How to correct the code?

4 Ansichten (letzte 30 Tage)
ancy s george
ancy s george am 30 Mai 2022
Beantwortet: Torsten am 30 Mai 2022
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])
Problem appears unbounded. fmincon stopped because the objective function value is less than the value of the objective function limit and constraints are satisfied to within the value of the constraint tolerance.
sb = 2×1
1.0e+20 * 3.2933 -0.0000
fv = -3.8422e+20
b=sb(2)
b = -1.4635e+13
s=sb(1)
s = 3.2933e+20
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.

Antworten (1)

Torsten
Torsten am 30 Mai 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
Esl = function_handle with value:
@(s)(ES)-(is/s)+Ns
Eby=@(b)(ib/b)-(EB)-Nb
Eby = function_handle with value:
@(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])
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
sb = 1×2
3.3029 6.9282
fv = -13.0272

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by