Change target as the model runs: target =
tmax=20; InitGraph(); ScaleWindow(0,-20,tmax,20); DrawAxes(); Label('Predictive control - third order - position offside, slugging',1,18); Colour(Black); t=0; x=10;v=0;a=0; Spot(t,x); StepModel();
//function StepModel() var uf = 1; af=a*1.5; vf=v*1.5; xf=x; tf=t; toff=0; Colour(Green); while((af<0)||(vf<0)||(xf
0)||(vf>0)||(xf>xtarget)){ if (xf>xtarget){toff=tf;} af = af + uf * dtf; vf = vf + af * dtf; xf = xf + vf * dtf; tf = tf + dtf; Spot(tf, xf); } if(toff>tpos){u=-1;}else{u=1;} Colour(Black); LineStart(t, x); a = a + u * dt; v = v + a * dt; x = x + v * dt; t = t + dt; LineTo(t, x); Colour(Blue); Spot(t,10*a); if (t