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

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

Appendix A CSTVA Program List

1. Program A: Investment Model in Chapter 2

Projectl.m

function J=project1(C,nn) J=project1 1(nn)+C*nn

Project1 1.m

% Program for the project 1 in chapter2

function project1 1=project1 1(nn) figure;

par=[1,1,nn];

% parameters: 1 state, 1 control, nn subintervals. options(14)=2000;

% maximum number of function evaluations.

options(13)=1;

% one equality constraint

xinit=0.0;

% initialize the state function xt um0=ones(nn,1)/nn;

% take a initial guess of starting time intervals

s=[0:0.05:1];

plot(s,1/2*s,1:)

ul=zeros(nn,1);

% lower bound of um, t(nn)-t(nn-1) >= 0

uu=ones(nn,1);



% upper bound of um, t(nn)-t(nn-1) <= 1

um=constr(1project1 2,um0,options,ul.uu,[],xinit,par)

% use the MATLAB constr to get the optimal time intervals

[f,g,xm]=project1 2(um,xinit,par) v(1)=um(1); for ii=2:nn

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

% obtain the real switching time t

v (nn)=0.9999999999999; v=[0 v] ; hold on

plot(v,xm,1rx-)

% plot the state function to switch time t xlabelOTime T)

ylabel(1State function xm and given fit function 1/2*t) Project1 2.m

%. Function of calculating differential equations and intervals

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

nx=par(1);

nu=par(2);

nn=par(3);

ps=1;

xm=zeros(nn+1,nx);

xm(1,:)=xinit;

lm=zeros(nn+1,nx);

% co-state function, polygonal function. In this case no co-state function

ma=nx;

% Component of the state functions. t=0;

% scale time t it=1;

% counter it hs=1/nn;

px=1project1 3;

% form of the right side of the transformation of the differential equation

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



% use SCOM package nqq to do the integral calculation zz=zeros(nn+1,nx);

% here is the first xm in the calling function

zz(1,:)=0; ma=1;

% set the number of the integral

t=0;

it = 1;

hs=1/nn;

px=1project1 4 1;

% form of the right side of the linear transformation of the integral

jm=nqq(px,nx,nu,nn,zz,ma,t,it,hs,um,xm,lm,ps) f=jm(nn+1);

% the result of the integral

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

% calculate the constraint

Project1 3.m

% Form of the right side of linear transformation of the differential equation

function ff = project1 3(t,it,z,yin,hs,um,xm,lm,ps)

nn=1/hs;

rr=nn/2;

for i=1:rr,

u(2*i-1)=1;

u(2*i)=0;

% map the control pattern ut=0,1,. . . in successive time intervals

pt=nn*u(floor(it),1); ff=(u(1,floor(it)))*pt;

% Piecewise-linear transformation d/d(xt) = (1/h)*(t(j+1)-t(j))*u(j) Project1 4 1.m

% Form of the right side of the integral

function ff = project1 4 1 (t,it,z,yin,hs,um,xm,lm,ps)

nn=1/hs;

fr=nn*mod(t,hs);

% Linear interpolation



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