Nonlinear fval, fsolve

3 ビュー (過去 30 日間)
Karol T
Karol T 2021 年 4 月 11 日
回答済み: Star Strider 2021 年 4 月 11 日
Hello, I'm trying to solve three nonlinear equations with fsolve. When I used two is worked, but when I add another one then I've an error.
function F = mufun(x)
F = [(1./A)*(x(1)-x(2))-x(3);
(-1./A)*(x(1)-x(2)) + B*(exp((x(2)-0)./C)-1);
x(1)-D ];
Variables A,B,C,D I defined in Command Window.
The warning tales:
Warning: Trust-region-dogleg algorithm of FSOLVE cannot
handle non-square systems; using Levenberg-Marquardt
algorithm instead.
> In fsolve (line 336)
In calc (line 3)
In calc file I've:
x0=[-5;5;10];
[x,fval] = fsolve(@mufunc,x0);
Everything looks fine, but output is x = x0 and I suppose the computation is wrong.

回答 (1 件)

Star Strider
Star Strider 2021 年 4 月 11 日
Pass ‘A’-‘D’ to ‘mufun’ as extra arguments:
function F = mufun(x,A,B,C,D)
F = [(1./A)*(x(1)-x(2))-x(3);
(-1./A)*(x(1)-x(2)) + B*(exp((x(2)-0)./C)-1);
x(1)-D ];
end
then call it as:
x0=[-5;5;10];
[x,fval] = fsolve(@(x)mufun(x,A,B,C,D),x0);
Also, note that the function is called ‘mufun’ however it is passed to fsolve as ‘mufunc’.
I am surprised that these did not throw errors, so perhaps everything exists inside another function that is over-the-horizon to us, or that the code that was run was not the code that was posted.

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by