fsolve with three anonymous functions
Afficher commentaires plus anciens
Hello everybody,
I can't see why giving a cell array of three separate anonymous as input to fsolve() doesn't work:
a = 6;
f = @(x)[sin(x);x;x*x];
g = @(x) sin(x);
h = @(x) x;
y1 = fsolve(f,a)
y2 = fsolve({g,f},a)
y3 = fsolve({f,g,h},a)
y1 and y2 will be calculated, y3 results in an error:
??? Error using ==> lsqfcnchk at 117
FUN must be a function or an inline object;
What do I miss over here? or, FUN may be a cell array that contains these type of objects.
Réponse acceptée
Plus de réponses (4)
Simon
le 27 Mar 2011
1 commentaire
Walter Roberson
le 27 Mar 2011
Ummm, like
EqSys = (x) [ f(x), g(x), h(x) ];
Andrew Newell
le 23 Mar 2011
The full message is
??? Error using ==> lsqfcnchk at 117
FUN must be a function or an inline object;
or, FUN may be a cell array that contains these type of objects.
The third statement is not the whole truth. I looked at the code, and lsqfcnchk only allows cell arrays of length 1 or 2. However, the documentation for fsolve does not claim that you can input cell arrays at all. So the documentation is not quite right.
Of course, you can still solve each equation separately.
Simon
le 29 Mar 2011
1 commentaire
Walter Roberson
le 29 Mar 2011
Your loop does work
>> EqSys{2}(5)
ans =
25
>> EqSys{4}(5)
ans =
625
The text representation of the function handles _does_ appear to have ^i in it, suggestive of it not having worked, but each of those "i" had its value "captured" at the time of function creation.
Simon
le 29 Mar 2011
Catégories
En savoir plus sur Function Creation dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!