Change target as the model runs: target =
tmax=20; umax=4; //drive limit InitGraph(); ScaleWindow(-.5,-2.5,tmax,2.5); DrawAxes(); Label('Time plot - u*|u|',2,2); // Label('Position error',2,-.2); // Label('Velocity',.1,2); f=8; //Feedback coefficient d=.1; //damping coefficient t=0; LineStart(t,x-xtarget); StepModel();
//function StepModel() Colour(Black); u = f*(xtarget - x) -d * v; u=u*Math.abs(u); // if (u>umax) {u=umax; Colour(Red);} // if (u<-umax){u=-umax; Colour(Red);} v = v + u * dt; x = x + v * dt; t = t + dt; Spot(t,x-xtarget); if (t