How to put fsolve in a loop, using 2 unknowns?
Show older comments
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.
Answers (1)
Sargondjani
on 23 Jun 2021
Edited: Sargondjani
on 23 Jun 2021
0 votes
Replace the first line with:
H = @(X)fsolve_root_finding(X(1),X(2));
Categories
Find more on Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!