Function y = myinvest (x);
y =-[0 0 0 1. 15 1.25 1.40 0 0 0 0 1.06]* x;
Then run the command line (preferably in another m file):
Clear all;
My idea is this: set A and D at the beginning of each year, so that there are four A's and five D's, and D, B, C and C are fixed.
% X =[a 1 a2 a3 a4 b c d 1 D2 D3 D4 D5]
% actually needs the largest positive value1.15a4+1.25b+1.40c+1.06d5, which is equivalent to finding the smallest negative value, so the fmincon function is used.
% max([0 0 0 1. 15 1.25 1.40 0 0 0 0 1.06]* X ')
% inequality constraint, only C.
a =[0 0 0 0 1 0 0 0 0 0];
b = 3;
% equals one * * * Five: Cash on hand at the beginning of next year equals the balance at the end of last year.
% a 1 a2 a3 a4 b c d 1 D2 D3 D4 D5
aeq =[ 1 0 0 0 0 1 0 0 0 0 0
0 1 0 0 0 1 - 1.06 1 0 0 0
- 1. 15 0 1 0 1 0 0 - 1.06 1 0 0
0 - 1. 15 0 1 0 0 0 0 - 1.06 1 0
0 0 1. 15 0 0 0 0 0 0 1.06 - 1];
beq =[ 10 0 0 0]';
options = optimset('LargeScale ',' off ',' MaxFunEvals ', 1e4,' MaxIter ', 1 E4);
x = fmincon(@myinvest,zeros( 1 1, 1),A,B,Aeq,Beq, 1e-6+zeros( 1 1, 1),[],[],options
The solved x is the corresponding [a1a2a3a4bc12d3d4d5].
7. 1698% smashed a in the first year, so don't vote again.
0.0000
0.0000
0.0000
In the third year, 8.2453% hit B.
3.0000% got a C in the second year.
2.8302% got a D in the first year, so don't vote again.
0.0000
0.0000
0.0000
0.0000
============================================================