Change target as the model runs: target =
tmax=20; InitGraph(); ScaleWindow(0,-2.5,tmax,2.5); DrawAxes(); Label('Second order example - closed loop',1,35); f=8; //Feedback coefficient d=2; //damping coefficient ulim=4; //drive limit Colour(Black); t=0; LineStart(t,x); StepModel();
//function StepModel() Colour(Black); u = f*(xtarget - x) -d * v; if (u>ulim) {u=ulim; Colour(Red);} if (u<-ulim){u=-ulim;Colour(Red);} v = v + u * dt; x = x + v * dt; t = t + dt; Spot(t, x); if (t