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

1 次查看(过去 30 天)
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 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by