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 CenterFile Exchange에서 Solver 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