Using fmincon for optimization, when having too many variables

1 vue (au cours des 30 derniers jours)
Itachi
Itachi le 10 Août 2012
Hi guys, I wanted to use the "fmincon" in the optimization toolbox to minimize my objective function. The only problem is that I have many variables. should I manually type the objective function :f(X)=x(1)+x(2)+...+x(n) ? Is there no other way?
Thanks in advance.

Réponse acceptée

Alan Weiss
Alan Weiss le 10 Août 2012
You have to write a function that takes one input, typically a vector called x, and returns the objective function evaluated at x. If your objective function is the sum of the elements in the vector x, as you seem to have, then you could write, for example,
objective = @(x)sum(x);
For more details, consult the documentation.
Alan Weiss
MATLAB mathematical toolbox documentation
  2 commentaires
Itachi
Itachi le 11 Août 2012
Dear Alan,
Hi,this objective function was just an example, the variables may have different coefficients like 5*x(1)-6*x(2)+...-12*x(n) , please can you help me out here?
Thanks in advance.
Alan Weiss
Alan Weiss le 14 Août 2012
Well, if it is really a linear function with a vector of coefficients, you could use
@(x)dot(x,a)
where a is the vector of coefficients.
Alan Weiss
MATLAB mathematical toolbox documentation

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by