How to correct the code?
1 view (last 30 days)
Show older comments
I have to maximize the objective function
b*Eby-s*Esl+gb*(Esl-Eby)
subjected to constraints
gb<=s;b<=gs; % where gb=3;gs=8;
By solving this equation using KKT condition,
L(b,s,lambda1,lambda2)=b*Eby-s*Esl+gb*(Esl-Eby)+lambda1(gb-s)+lambda2(b-gs)
solution obtained is,
case1 : lambda1=0;lambda2=0
s*=3.302;b*=6.928
case1 : lambda1=0;lambda2>0
s*=3.302;b*=8
case1 : lambda1>0;lambda2=0
s*=3;b*=6.928
case1 : lambda1>0;lambda2>0
s*=3;b*=8
I solving this function using fmincon ,but didn't got the correct solution.
gb=3;gs=8;
ES=4.5;is=20;EB=1.5;ib=40;
b=8;s=3;Ns=1;Nb=1;
Esl=(ES)-(is/s)+Ns;
Eby=(ib/b)-(EB)-Nb;
f = @(s,b)(b*Eby-s*Esl+gb*(Esl-Eby));
[sb,fv] = fmincon(@(sb) -f(sb(1),sb(2)), rand(2,1), [],[],[],[],[3 -Inf],[inf 8])
b=sb(2)
s=sb(1)
Is this code is correct? Is it possible to get a solution between 3 and 8.That is case 1 have to be excecute.How to solve this problem?Is there any other method? Please help me to correct this code.
NB:values of ES,EB,is,ib are changable variables.
0 Comments
Answers (1)
Torsten
on 30 May 2022
gb=3;gs=8;
ES=4.5;is=20;EB=1.5;ib=40;
b=8;s=3;Ns=1;Nb=1;
Esl=@(s)(ES)-(is/s)+Ns
Eby=@(b)(ib/b)-(EB)-Nb
f = @(s,b)(b*Eby(b)-s*Esl(s)+gb*(Esl(s)-Eby(b)));
[sb,fv] = fmincon(@(sb) -f(sb(1),sb(2)), [5 5], [],[],[],[],[3 -Inf],[inf 8])
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!