Can I call a fsolve funciton with arguments? I was trying to do somethink like this:
root2d.m file:
function (F) = root2d(x)
F(1) = x(1)*E+x(2)- x(2)*(x(1)^2); F(2) = x(1)*cos(x(2)) + x(2)*sin(x(1)) - E;
and calling the function: fun = @root2d; E = 23; x0 = [0,0]; x = fsolve(fun,x0);
So how can i call fsolve function for diferents values of E ?

 Réponse acceptée

Sean de Wolski
Sean de Wolski le 20 Juin 2016
Modifié(e) : Sean de Wolski le 20 Juin 2016

0 votes

Easiest way to do this is with a nested function. The nested function can see its parent workspace.
function x = fsolveex(E)
x0 = [0,0];
x = fsolve(@root2d,x0);
function F = root2d(x)
F(1) = x(1)*E+x(2)- x(2)*(x(1)^2);
F(2) = x(1)*cos(x(2)) + x(2)*sin(x(1)) - E;
end
end
Now just pass E values into fsolveex
x = fsolveex(23)

1 commentaire

Tiago Casagrande
Tiago Casagrande le 21 Juin 2016
Modifié(e) : Tiago Casagrande le 21 Juin 2016
Thanks man, worked perfectly!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Entering Commands dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by