Промышленный лизинг Промышленный лизинг  Методички 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 [ 64 ] 65 66 67

This page intentionally left blank



Appendix F

A Sample Test Problem

The following example has two controls and one state, and gradients are calculated.

subs=cell(1,9);

subs={t3x,t3j,t3f,t3c,>t3k,t3l,t3g,t3a,t3p}; par=[1, 2, 20, 0, 1, 0.25]; % Parameters % nx, nu, nn, npa, grad, c

nnb=par(3); nx=par(1); nu=par(2); xinit=[0.5];

% Initial value for the state u0=zeros(nn,nu);

% Starting values for computing the control ul=zeros(nn,nu);

% Lower bound (vector or matrix) for the control uu=ones(nn,nu);

% Upper bound (vector or matrix) for the control figure

Control=constr(fqq,u0,[],ul,uu,gqq,par,subs,xinit) % Calls constr package

[Objective,Constraint,State,Integral,Costate,Gradient] = cqq(Control,par,subs,xinit) % Right hand side of differential equation

function yy=t3x(t,it,z,yin,hs,um,xm,lm,ps)



yy(1)=z(1)*um(flcor(it),1)+um(flcor(it),2); % Dependent variables on the right hand side

of a differential equation are coded as

z(1), z(2), etc.

function ff=t3j(t,it,z,yin,hs,um,xm,lm,ps) % Integrand of objective function

c=ps(6)

ff(1) = (um(flG r(it),1)-1)*li3(xm,hs,t); ff(1)=ff(1)+c*u(floor(it),2);

function ff=t3f(xf,um,xm,ps) % Endpoint term

ff(1)=0; % Control constraint

function gg=t3c(ii,hs,um,xm,lm,ps) gg=um(ii,1) + um(ii,1) - 1;

function dg=t3k(ii,hs,um,xm,lm,ps) % Gradient of constraint

dg=[eye(nn);eye(nn)];

function yy=t3g(t,hs,um,xm,lm,nn) % Gradient of objective

temp= 0.5*(lm(t,1)+lm(t+1,1)); t2=t/nn;

yy=[(1+temp)*li3(xm,hs,t2), 0.25+temp]; function yy=t3a(nn,xf,um,xm,ps)

%Boundary condition for adjoint equation (at t=1) yy=0;

function yy=t3l(t,it,z,yin,hs,um,xm,lm,ps) % Right hand side of adjoint equation

yy=-(1+z(1))*um(floor(it),1)+1;



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 [ 64 ] 65 66 67