Effacer les filtres
Effacer les filtres

Solve equations by fsolve and with input anonymous function format

25 vues (au cours des 30 derniers jours)
zongxian
zongxian le 12 Sep 2020
By the help document of Matlab, the example of fsolve is:
function F = root2d(x)
F(1) = exp(-exp(-(x(1)+x(2)))) - x(2)*(1+x(1)^2);
F(2) = x(1)*cos(x(2)) + x(2)*sin(x(1)) - 0.5;
fun = @root2d;
x0 = [0,0];
x = fsolve(fun,x0)
But now outer function transfer a anonymous function of fun, like:
fun = @(x,y) [x+y^2-5, 6*x^2+13*y-5]
Start value x0 = [1, 1]
How do I fit fsolve input format?

Réponse acceptée

Steven Lord
Steven Lord le 12 Sep 2020
fun = @(x,y) [x+y^2-5, 6*x^2+13*y-5]
Since fsolve requires the function you pass into it to accept one input, a vector, you need an adapter.
g = @(xy) fun(xy(1), xy(2));
This has the interface fsolve requires and calls fun the way it expects to be called.
g([1 2]) % [0 27]
fun(1, 2) % [0 27]

Plus de réponses (0)

Catégories

En savoir plus sur Linear and Nonlinear Regression 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