fsolve with three anonymous functions
古いコメントを表示
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.
採用された回答
その他の回答 (4 件)
Simon
2011 年 3 月 27 日
1 件のコメント
Walter Roberson
2011 年 3 月 27 日
Ummm, like
EqSys = (x) [ f(x), g(x), h(x) ];
Andrew Newell
2011 年 3 月 23 日
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
2011 年 3 月 29 日
1 件のコメント
Walter Roberson
2011 年 3 月 29 日
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.
カテゴリ
ヘルプ センター および File Exchange で Function Creation についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!