fmincon--How to use multivariable optimization

22 vues (au cours des 30 derniers jours)
Young
Young le 2 Mar 2022
Commenté : Matt J le 3 Mar 2022
Hi, I am using 3 or 4 variables to get the min or max of one function
But I cannot get the right answer, I don't know why,could anyone help me solve this problem?
fun=@(x)(x(1)+x(2)+x(3)).*x(2)./(x(1).*(x(2)-x(3)));
lb = [10,10,10];
ub = [100,100,100] ;
x0 = [10,50,100]; % Starting guess at the solution
[x1,fval] = fmincon(fun,x0,[],[],[],[],lb,ub);
Local minimum possible. Constraints satisfied. fmincon stopped because the size of the current step is less than the value of the step size tolerance and constraints are satisfied to within the value of the constraint tolerance.
xmax2 = x1(1)
xmax2 = 10.0036
ymax2 = x1(2)
ymax2 = 84.8926
zmax2 = x1(3)
zmax2 = 84.8926
max = fval
max = -2.7102e+11
First of all ,how to add the constraint of X(2) =/(unequal) X(3)?
Second, the right answer is
x = 10 99 100
f =-2.0691e+03
How to get it ? Thank you!!!
  3 commentaires
Young
Young le 2 Mar 2022
I think they are the different algorithm do you mind explain why?
Torsten
Torsten le 2 Mar 2022
Modifié(e) : Torsten le 2 Mar 2022
"fmincon" does not support solution variables that are integers. It will treat each variable as real-valued.
Is it this what you wanted to know ( since I can't understand exactly what you are asking) ?

Connectez-vous pour commenter.

Réponses (2)

Walter Roberson
Walter Roberson le 2 Mar 2022
You would need to use a non-linear constraint to force that x2 ~= x3
However... by examination we can see that if x(2)-x(3) is negative then you are dividing by a negative and the result would be negative. The other terms are all positive or sums of positive, so getting a negative expression due to x(2)-x(3) being negative is going to give you a result that is less positive than any possible answer when x(2)>x(3) .
That tells us that you would be better off constraining x(2)<x(3) . Which is something you can implement as a linear constraint:
A = [0 1 -1]
b = -eps(realmin)
Here, b is the first representable number that is less than 0. You do not use 0 itself because the test is A*x.' <= b and in the case of the two being equal, 1*x(2)+-1*x(3) would be exactly 0 and you do not want 0 as an allowed outcome.
  2 commentaires
Young
Young le 3 Mar 2022
Hi Walter, thank you
I tried ga to solve this problem, here is another question, Could I get multi objectives with multi variables using fmincon?
I search the solution, fminmax is utlized instead of fmincon.
Are there any examples?
Walter Roberson
Walter Roberson le 3 Mar 2022
Single objective only for fmincon.

Connectez-vous pour commenter.


Matt J
Matt J le 2 Mar 2022
Modifié(e) : Matt J le 2 Mar 2022
For such a small number of variables, this is very easy to do with a discrete exhaustive search. Here, I use ndgridVecs (download here) instead of ndgrid to save memory.
lb = [10,10,10];
ub = [100,100,100] ;
ranges=arrayfun(@(a,b)a:b, lb,ub,'uni',0);
[x1,x2,x3]=ndgridVecs(ranges{:});
F=(x1+x2+x3).*x2./(x1.*(x2-x3));
[fval,imin]=min(F(:));
[i,j,k]=ind2sub(size(F),imin);
x1=x1(i),
x1 = 10
x2=x2(j),
x2 = 99
x3=x3(k)
x3 = 100
fval,
fval = -2.0691e+03
  3 commentaires
Walter Roberson
Walter Roberson le 3 Mar 2022
No, fmincon can use a vector of unknown values, but it cannot do multiple objectives.
Matt J
Matt J le 3 Mar 2022
@Young, what is the status of your original question? Has it been addressed by either my answer or Walter's. If so, please Accept-click the appropriate answer and post your new question in a new thread.
However, for multi-objective problems you could look at either fgoalattain , paretosearch, or gamultiobj.

Connectez-vous pour commenter.

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by