Function: From multiple variables as input to vector input

2 vues (au cours des 30 derniers jours)
Nicolas Ochmann
Nicolas Ochmann le 8 Août 2017
Commenté : Nicolas Ochmann le 8 Août 2017
Hi everybody,
I have the following problem: I have a function such as: fun = @(x1,x2)100*(x2-x1^2)^2+(1-x1)^2
However, I need to convert this to the form: fun = @(x)100*(x(2)-x(1)^2)^2+(1-x(1))^2 so that I can use it as the objective function for fmincon.
Does anybody have a clue how this can be done?
Thanks in advance,
Nicolas

Réponse acceptée

Stephen23
Stephen23 le 8 Août 2017
Modifié(e) : Stephen23 le 8 Août 2017
Either rewrite the function exactly as you have shown, or put it inside a wrapper:
foo = @(x)fun(x(1),x(2));
Note the different function name.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by