Nonlinear fval, fsolve
조회 수: 3 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!