Continuous and discrete Zhang dynamics for real-time varying nonlinear optimization