maximization problem , fmincon optimization
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Az.Sa
am 13 Jun. 2022
Kommentiert: Az.Sa
am 13 Jun. 2022
Hello,
I'm trying to solve this maximization problem with matlab.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1030985/image.png)
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 Kommentare
Akzeptierte Antwort
John D'Errico
am 13 Jun. 2022
Bearbeitet: John D'Errico
am 13 Jun. 2022
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!