フィルターのクリア

maximization problem , fmincon optimization

3 ビュー (過去 30 日間)
Az.Sa
Az.Sa 2022 年 6 月 13 日
コメント済み: Az.Sa 2022 年 6 月 13 日
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

採用された回答

John D'Errico
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)
objx = 
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)
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.
ans = 1×2
0.0066 0.9934
That is the solution we found graphically.
  1 件のコメント
Az.Sa
Az.Sa 2022 年 6 月 13 日
Thank you very much

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Optimization Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by