maximization problem , fmincon optimization
5 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I'm trying to solve this maximization problem with matlab.
I use the following code
objective = @(x) - ( -.858*x(1)-.04182*x(2)-1.645*sqrt((.5882*x(1) -.055*x(2)).^2 + (-.0558*x(1) +.352*x(2)).^2 ));
Aeq = [1,1];
beq = 1;
lb = zeros*(2);
ub = ones*(2);
x0 = [0,0];
x = fmincon(objective,x0,[],[],Aeq,beq,lb,ub)
once I run the code I received the following :
Warning: Length of lower bounds is < length(x); filling in missing lower bounds
with -Inf.
> In checkbounds (line 33)
In fmincon (line 324)
Warning: Length of upper bounds is < length(x); filling in missing upper bounds
with +Inf.
> In checkbounds (line 47)
In fmincon (line 324)
Any advice to improve my code.
Thank you
0 件のコメント
採用された回答
John D'Errico
2022 年 6 月 13 日
編集済み: John D'Errico
2022 年 6 月 13 日
syms x y
objxy = ( -.858*x-.04182*y-1.645*sqrt((.5882*x -.055*y).^2 + (-.0558*x +.352*y).^2 ));
If x+y == 1 then we can replace y with 1-x.
objx = subs(objxy,y,1-x)
Clearly, the solution must be between 0 and 1 for both x and y given the constraint.
fplot(objx,[0,1])
At a glance, that tends to suggest the function is monotone decreasing, with the maximum at x ==0. But in fact, if we expand the axis down near zero, we do find a non-trivial maximum.
fplot(objx,[0,0.02])
It looks like a max exists around x= 0.06.
Now, how will fmincon do it. First, this is meaningless:
lb = zeros*(2);
ub = ones*(2);
That is NOT how you create vectors of length 2 in MATLAB. READ THE HELP!!!!
Now, fmincon is a MINIMIZER. You state you want to MAXIMIZE. So negate the objective. You actually got that part right.
objective = @(x) - ( -.858*x(1)-.04182*x(2)-1.645*sqrt((.5882*x(1) -.055*x(2)).^2 + (-.0558*x(1) +.352*x(2)).^2 ));
Aeq = [1,1];
beq = 1;
lb = zeros(1,2);
ub = ones(1,2);
x0 = [.5 .5];
fmincon(@(x) objective(x),x0,[],[],Aeq,beq,lb,ub)
That is the solution we found graphically.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!