system of non linear functions

44 ビュー (過去 30 日間)
Lucrezia Cester
Lucrezia Cester 2019 年 12 月 13 日
コメント済み: Lucrezia Cester 2019 年 12 月 13 日
Hello,
I get an error saying not enough input arguments.
I literally tried to go step by step from the matlab tutorial for non linear functions.
Do you know what might be wrong?
Thanks!
function F = root2d(x)
F(1) = 97-(1/sqrt(2))*(exp((1i)*(136)*x(1)))- exp((1i)*105*x(2))*(1/sqrt(2));
F(2) = 51-(1/sqrt(2))*(exp((1i)*(51)*x(1)))- exp((1i)*14*x(2))*(1/sqrt(2));
fun = @root2d;
x0 = [0,0];
x = fsolve(fun,x0)
  1 件のコメント
Star Strider
Star Strider 2019 年 12 月 13 日
Your code runs for me without error:
function F = root2d(x)
F(1) = 97-(1/sqrt(2))*(exp((1i)*(136)*x(1)))- exp((1i)*105*x(2))*(1/sqrt(2));
F(2) = 51-(1/sqrt(2))*(exp((1i)*(51)*x(1)))- exp((1i)*14*x(2))*(1/sqrt(2));
end
fun = @root2d;
x0 = [0,0];
x = fsolve(fun,x0)
(I added an end to the function because I am running it inside another function I use to test Answers functions.)
It produces a normal termination for fsolve, and these parameter estimates:
x =
0.000514467767515 - 0.082745912708573i -0.029252385734369 - 0.107158749735724i

サインインしてコメントする。

採用された回答

Steven Lord
Steven Lord 2019 年 12 月 13 日
It's unclear from what you've posted whether the last three lines of your code:
fun = @root2d;
x0 = [0,0];
x = fsolve(fun,x0)
are inside root2d.m or outside. They need to be outside of root2d.m, otherwise you will either receive an error about not enough input arguments (if you call root2d with no input arguments) or (eventually) an error about the recursion limit or simply a crash (if you call root2d with an input argument that has at least two elements.)
Why would you receive the recursion limit error if you call this with an input argument?
Your first call to root2d would call fsolve
which would call root2d which would call fsolve
which would call root2d which would call fsolve
which would call root2d which would call fsolve ...
Break this infinite loop by not calling fsolve inside root2d to solve the system computed by root2d.
  1 件のコメント
Lucrezia Cester
Lucrezia Cester 2019 年 12 月 13 日
yup, thank you very much! that was the problem! the lines had to be outisde

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by