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

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

function project3 1=project3 1(nb,ns) % nb is big

interval of time t and ns is small interval

par = [2,1,rb,ns];

xinit= [3,5];

nb=par(3);£ big intervals

ns=par(4);% small intervals

nn=nb*ns; %total intervals

options(13)=1;

options(14)=10000;

um0=ones(nb,1)/nb;

ul=zeros(nb,1);

uu=ones(nb,1);

um=constr(project3 2,um0,options,ul,uu,[],xinit,par);

[f,g,xm] = project3 2(um,xinit,par)

sm=zeros(nn,1);

v=zeros(nn,1);

for ii =1: nb

for jj= 1:ns

sm((ii-1)*ns+jj)=um(ii)/ns;

v(1)=sm(1); for ii=2:nn

v(ii)=sm(ii)+v(ii-1);

v (nn)=0.9999999999999;

s=zeros(nn+1,1); s(1)=0;

for ii = 2: nn+1

s(ii)=v(ii-1);

end s

figure;

plot(s,xm(:,1),ob-)

hold on;

t= [0:1/10:1];

plot(t,4*sin(5*t+1), +r:) xlabeKTime T )

ylabelCState function xm and given fit function

4*sin(5*t+1) )

figure;

plot(xm(:,1),xm(:,2),*b-) xlabel(state function xm1)



ylabel(state function xm2) %Project3 2.m integral

function [f,g,xm] = project3 2(um, xinit, par)

nx=par(1);

nu=par(2);

nb=par(3);

ns=par(4); % ns is small interval nn=par(3)*par(4) ; % nn is total interval sm=zeros(nn,1);

for ii =1: nb

for jj= 1:ns

sm((ii-1)*ns+jj)=um(ii)/ns;

xm=zeros(nn+1,nx); xm(1,:)=xinit; lm=zeros(nn+1,nx); ma=nx; t=0; it=1; hs=1/nn;

px=project3 3;

xm=nqq(px,nx,nu,nn,xm,ma,t,it,hs,sm,xm,lm,ns);

zz=zeros(nn+1,nx); zz(1,:) = 0; ma=1; t=0;

it=1;

hs=1/nn;

px=project3 4; x=xm(:,1);

jm=nqq(px,nx,nu,nn,zz,ma,t,it,hs,sm,x,lm,ns);

f=jm(nn+1);

g(1)=sum(sm)-1;

%Project3 3.m compute differential equation

function ff = project3 3(t,it,z,yin,hs,sm,xm,lm,ns)

nn=1/hs;

T=5;

B=0.0;

B=0.1;



B=0.2;

nb=nn/ns;

rr=nn/(3*ns);

%for i=1:rr,

% ut(3*i-1)=-1;

% ut(3*i)=0;

% ut(3*1+1)=1;

%end

for i=1:rr,

ut(3*i-2)=-2;

ut(3*i-1)=0;

ut(3*i)=2;

ts=zeros(nn,1);

if ns > 1 for ii= 1:nb

for jj=1:ns

ts(ii)=ts(ii)+sm((ii-1)*ns+jj);

end else

for ii= 1: nb

ts(ii)=sm(ii);

pt=nb*ts((floor((it-1)/ns)+1),1); ff(1)= T * z(2)*pt;

ff(2)= (-T * z(1) + T *ut(1,(floor((it-1)/ns) +1)) -Тл2 * B *z(2))*pt;

%Project3 4.m

function ff = project3 4(t,it,z,yin,hs,sm,x,lm,ns)

nn=1/hs;

fr=nn*mod(t,hs);

xmt=(1-fr)*x(it)+fr*x(it+1);

nb=nn/ns;

umx=zeros(nn,1);

umx(2)=s(1);

for ii = 3: nn

umx(ii)=sm(ii-1)+umx(ii-1);

qt=nn*sm(floor(it),1)*(t-hs*(it-1))+umx(floor(it),1); ll=abs(xmt-4*sin(5*qt+1);% x1(t)-cos(0.4*t+2.85) ff=ll*nn*sm(floor(it),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