Change target as the model runs: target =
tmax=20; InitGraph(); ScaleWindow(0,-20,tmax,20); DrawAxes(); Label('Control with nested lops - fifth order ',1,18); Colour(Black); t=0; x=10;v=0;a=0;j=0;k=0; klim=1; jlim=1; alim=1; vlim=1; LineStart(t,x); StepModel();
//function StepModel() vdem=(xtarget-x)*.2; if(vdem>vlim){vdem=vlim;} if(vdem<-vlim){vdem=-vlim;} adem=(vdem-v)*1; if(adem>alim){adem=alim;} if(adem<-alim){adem=-alim;} jdem=(adem-a)*.5; if(jdem>jlim){jdem=jlim;} if(jdem<-jlim){jdem=-jlim;} kdem=(jdem-j)*4; if(kdem>klim){kdem=klim;} if(kdem<-klim){kdem=-klim;} u=(kdem-k)*10; if(u>1){u=1;} if(u<-1){u=-1;} Colour(Black); LineStart(t, x); k = k + u * dt; j = j + k * dt; a = a + j * dt; v = v + a * dt; x = x + v * dt; t = t + dt; LineTo(t, x); Colour("yellow"); Spot(t, 5*u); Colour(Green); Spot(t, 10*k); Colour(Blue); Spot(t, 10*j); Colour("cyan"); Spot(t, 10*a); Colour(Red); Spot(t, 10*v); if (t