How to put fsolve in a loop, using 2 unknowns?

조회 수: 1 (최근 30일)
Noob
Noob 2021년 6월 21일
편집: Sargondjani 2021년 6월 23일
Hi,
I want to write a code that asks fsolve to go through some combinations of guesses and then find all the roots (xdot, ydot) to the equation, but I'm having some trouble debugging the code. I defined the function locally, without saving it in a separate file.
Thanks in advance,
H = @(xdot, ydot) fsolve_root_finding(xdot, ydot);
for xdot = linspace(1,5,5)
for ydot = linspace(-5,-1,5)
[ my_root, fval, exit_flag ] = fsolve( H, [ xdot, ydot ] )
plot( my_root, 'bx','MarkerSize',10 );
end
hold on
end
function G = fsolve_root_finding(xdot, ydot)
G(1) = xdot + ydot;
end
Here's the current error message:
Not enough input arguments.
Error in fsolve_practice>@(xdot,ydot)fsolve_root_finding(xdot,ydot)
Error in fsolve (line 242)
fuser = feval(funfcn{3},x,varargin{:});
Error in fsolve_practice (line 9)
[ my_root, fval, exit_flag ] = fsolve( H, [ xdot, ydot ] )
Caused by:
Failure in initial objective function evaluation. FSOLVE cannot continue.

답변 (1개)

Sargondjani
Sargondjani 2021년 6월 23일
편집: Sargondjani 2021년 6월 23일
Replace the first line with:
H = @(X)fsolve_root_finding(X(1),X(2));

카테고리

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