Change target as the model runs: target =
tmax=20; InitGraph(); ScaleWindow(0,-20,tmax,20); DrawAxes(); Label('Predictive control - fifth order - all offside, slugging',1,18); Colour(Black); t=0; x=10;v=0;a=0; Spot(t,x); StepModel();
//function StepModel() var uf = 1; kf=k*1.45; jf=j*1.9; af=a*1.9; vf=v*1.45; xf=x; tf=t; toff=0; Colour(Green); while((kf<0)||(jf<0)||(af<0)||(vf<0)||(xf
0)||(jf>0)||(af>0)||(vf>0)||(xf>xtarget)){ kf = kf + uf * dtf; jf = jf + kf * dtf; af = af + jf * dtf; vf = vf + af * dtf; xf = xf + vf * dtf; tf = tf + dtf; Spot(tf, xf); } if(tf>tpos){u=-1;}else{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