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

1 Ansicht (letzte 30 Tage)
Noob
Noob am 21 Jun. 2021
Bearbeitet: Sargondjani am 23 Jun. 2021
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.

Antworten (1)

Sargondjani
Sargondjani am 23 Jun. 2021
Bearbeitet: Sargondjani am 23 Jun. 2021
Replace the first line with:
H = @(X)fsolve_root_finding(X(1),X(2));

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by