Non-linear optimization routine for discrete Lagrange problems without state contraints and possibly bound contraints on the command. dynoptim solves the problem:
min J(u) = sum L(u(t),X(t),t) + phi(X(T),T) ub<u<uh t=0..T-1
where the state X(t) of the system evolves according to the discrete dynamics:
X(0)=X0, X(t+1)=f(u(t),X(t),t)
BEWARE L is a string matrix of siwe 3 in which are stored in this order: the name of the cost function, the name of the partial derivative of the cost with respect to u and the name of the partial derivative of the cost with respect to X. The declarations of f and phi follow the same behaviour.
DEFAULT PARAMETERS
nap = 200; iter= 200; epsf= 0.000E+00; epsg= 0.4441E-15; epsx= 0*u0+0.0000E+00
where u0 is the initial state;
/////////// several parameters /////////////////// E=[5.9623,6.998,8.4363,9.9111,11.018,12.126,13.233,14.541,15.848,17.156,18.463,19.771]; alpha=1000; nu=3; theta=0.0000526; M0=360; Minf=274; rho=0.05; sigma=0.01; delta=10; beta=0.38; neta=38.05; Ms=550; e=0.0001 Gamma=0.001; deff('y=Kappa(t)','y=18000*exp(0.02*delta*t)'); deff('y=Lambda(t)','y=0.25+0.75*exp(-0.01*delta*t)'); deff('y=xsi(m)','y=exp(-((m-Ms)/38.05)^2)'); deff('y=xsi_m(m)','y=-2*(m-Ms)/(38.05^2)*exp(-((m-Ms)/38.05)^2)'); deff('y=gama(v)','y=1/(2*Gamma*delta)*(v+sqrt(v*v+e))+1'); deff('y=gama_v(v)','y=1/(2*Gamma*delta)*(1+v/sqrt(v*v+e))'); deff('y=psi(u1,u2)','y=u2-u1-delta*Gamma'); deff('y=psi_u1(u1,u2)','y=-1') deff('y=psi_u2(u1,u2)','y=1') //////////The cost and its derivatives/////////////// deff('y=L(a,x,t)','y=(alpha*E(t+1)*a^nu*Lambda(t)*gama(psi(x(1),a))+Kappa(t)*xsi(x(2)))/(1+rho)^(delta*t)'); deff('y=L_cmd(a,x,t)','y=alpha*E(t+1)*(nu*a^(nu-1)*Lambda(t)*gama(psi(x(1),a))+a^nu*Lambda(t)*gama_v(psi(x(1),a)))/(1+rho)^(delta*t)'); deff('y=L_etat(a,x,t)','y(1)=-alpha*E(t+1)*a^nu*Lambda(t)*gama_v(psi(x(1),a))/(1+rho)^(delta*t),y(2)=Kappa(t)*xsi_m(x(2))/(1+rho)^(delta*t)'); //////////The dynamic and its derivatives /////////////// deff('y=f(a,x,t)','y(1)=a,y(2)=x(2)+10*(beta*E(t+1)*(1-a)-sigma*(x(2)-Minf))'); deff('y=f_etat(a,x,t)','y=zeros(2,2),y(1,1)=0,y(2,1)=0,y(1,2)=0,y(2,2)=1-sigma*delta'); deff('y=f_cmd(a,x,t)','y(1)=1,y(2)=-beta*E(t+1)*delta'); ///////// The final cost and its derivatives /////////// deff('y=phi(x,t)','y=Kappa(t)*xsi(x(2))/(1+rho)^(delta*t)'); deff('y=phi_etat(x,t)','y(1)=0,y(2)=Kappa(t)*xsi_m(x(2))/(1+rho)^(delta*t)'); //////////Paramaters for the optimization///////////// T=12 x0=[0;360]; ub=zeros(1,T); //the comand lower bound uh=zeros(1,T)+1; //the comand upper bound u0=rand(1,T); //////////The call of the primitive dynoptim ///////// L_noms=["L","L_cmd","L_etat"]; f_noms=["f","f_cmd","f_etat"]; phi_noms=["phi","phi_etat"]; [Uopt,Eopt]=dynoptim(L_noms,f_noms,phi_noms,ub,u0,uh,x0) ////////// Results ///////////////// xbasc() years=1990+10*(0:T-1); plot2d2(years,Uopt,2) xstring(2010,0.5,"time evolution of control") halt() xbasc() plot2d2(years,Eopt(2,1:T),5) xstring(2010,480,"time evolution of second component of state" ) |