Not enough input arguments

7 ビュー (過去 30 日間)
john_arle
john_arle 2019 年 3 月 11 日
コメント済み: Adam Danz 2019 年 3 月 11 日
Hello there!
I am writing a simple function but I can not understand why it will not work.
The error says "Not enough input arguments", right when the compiler is compiling the function I called ecc_anomaly.
Could you help me? I know the code is banal, though I can not fix it!
Thank you in advance!
The infamous function
function E = ecc_anomaly(tow, toe, GM, sqrta, M0, ecc)
i = 0;
M = M0+(tow-toe)*sqrt(GM/sqrta^6);
a = M0;
while i >= 10^-13
E = M0+ecc*sin(a);
i = abs(E-a);
a = E;
end
end
And finally my main
clc
clear all
format long
GM = 3.986005e14; % m^3/s^2
rotation = 7.2921151467e-5; % rad/s
tow = 223221; % s (self-check value)
%tow = 225445; % s
M0 = 1.94850072201; % rad
sqrta = 0.544062105942e+04; % m^0.5
ecc = 0.404827296734e-04; % unitless
toe = 0.225600000000e+06; % s
E = ecc_anomaly(tow, toe, GM, sqrta, M0, ecc);
f = t_a(ecc, E);
r = sqrta^2*(1-ecc*cos(E));
x_1 = r*cos(f);
x_2 = r*sin(f);
  3 件のコメント
john_arle
john_arle 2019 年 3 月 11 日
I can confirm this, but the function got somehow wrong. "i" should be set to one at the beginning. Here the correct version. Apologies.
function E = ecc_anomaly(tow, toe, GM, sqrta, M0, ecc)
i = 1;
M = M0+(tow-toe)*sqrt(GM/sqrta^6);
a = M0;
while i >= 10^-13
E = M0+ecc*sin(a);
i = abs(E-a);
a = E;
end
end
Here the error message
>> ecc_anomaly
Not enough input arguments.
Error in ecc_anomaly (line 3)
M = M0+(tow-toe)*sqrt(GM/sqrta^6);
Adam Danz
Adam Danz 2019 年 3 月 11 日
This version does not produce an error within the ecc_anomaly() funciton. It returns
E = 1.948538350699015

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

採用された回答

Steven Lord
Steven Lord 2019 年 3 月 11 日
Your function is declared to accept six input arguments:
function E = ecc_anomaly(tow, toe, GM, sqrta, M0, ecc)
When you call it, you need to pass six inputs into it. When you try to call it with zero inputs like:
>> ecc_anomaly
MATLAB doesn't know what value to use as M0 on that line of code. It also doesn't know what values to use for tow, toe, GM, and sqrta, but M0 is the first variable it "sees" on that line.
There are ways to specify default values for when you call the function with fewer inputs than it's declared to accept (using functions like nargin) but easier is to call it with six inputs as you do in the "main" in the original message. I couldn't run your full "main" code since I don't have the t_a function, but I was able to run up through the ecc_anomaly call it contains.
  1 件のコメント
Adam Danz
Adam Danz 2019 年 3 月 11 日
Note that there are no errors when the function is called properly from within the script provided.
clc
clear all
format long
GM = 3.986005e14; % m^3/s^2
rotation = 7.2921151467e-5; % rad/s
tow = 223221; % s (self-check value)
%tow = 225445; % s
M0 = 1.94850072201; % rad
sqrta = 0.544062105942e+04; % m^0.5
ecc = 0.404827296734e-04; % unitless
toe = 0.225600000000e+06; % s
E = ecc_anomaly(tow, toe, GM, sqrta, M0, ecc);
f = t_a(ecc, E);
r = sqrta^2*(1-ecc*cos(E));
x_1 = r*cos(f);
x_2 = r*sin(f);
function E = ecc_anomaly(tow, toe, GM, sqrta, M0, ecc)
i = 1;
M = M0+(tow-toe)*sqrt(GM/sqrta^6);
a = M0;
while i >= 10^-13
E = M0+ecc*sin(a);
i = abs(E-a);
a = E;
end
end

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

その他の回答 (1 件)

Guillaume
Guillaume 2019 年 3 月 11 日
>> ecc_anomaly
Calls ecc_anomaly with no inputs argument. So, yes, you will get a "Not enough input arguments." error.
I'm not sure what else you expected to happen when you wrote that. Considering that you wrote: "right when the compiler is compiling the function I called ecc_anomaly", maybe you expected it to somehow compile the function. Base matlab does not include a compiler and if you do have matlab compiler, that's certainly not the way to go. The above simply call the function.

カテゴリ

Help Center および File ExchangeSource Control Integration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by