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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by