Effacer les filtres
Effacer les filtres

maximization problem , fmincon optimization

3 vues (au cours des 30 derniers jours)
Az.Sa
Az.Sa le 13 Juin 2022
Commenté : Az.Sa le 13 Juin 2022
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

Réponse acceptée

John D'Errico
John D'Errico le 13 Juin 2022
Modifié(e) : John D'Errico le 13 Juin 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)
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 commentaire
Az.Sa
Az.Sa le 13 Juin 2022
Thank you very much

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with Optimization Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by