fsolve with three anonymous functions
Show older comments
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.
Accepted Answer
More Answers (4)
Simon
on 27 Mar 2011
1 Comment
Walter Roberson
on 27 Mar 2011
Ummm, like
EqSys = (x) [ f(x), g(x), h(x) ];
Andrew Newell
on 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
on 29 Mar 2011
1 Comment
Walter Roberson
on 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
on 29 Mar 2011
Categories
Find more on Function Creation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!