Need help! I keep getting the error "not enough input arguments" how do I fix this?

function drv = untitiled18(t,rv);
% small r is position
% big r is distance
mu = 3.986004*(10^5); %%unit is in km^3/s^2, and is Earth's Gravitational parameter
drv = zeros(6,1);
rx = rv(1);
vx = rv(2);
ry = rv(3);
vy = rv(4);
rz = rv(5);
vz = rv(6);
R = sqrt((rx^2)+(ry^2)+(rz^2));
% X component/ i direction
drv(1) = rv(2);
drv(2) = (-mu.*rx)/(R^3); % (vx) velocity in the x direction
% Y component/ j direction
drv(3) = rv(4);
drv(4) = (-mu.*ry)/(R^3); % (vy) velocity in the y direction
% Z component/ k direction
drv(5) = rv(6);
drv(6) = (-mu.*rz)/(R^3); % (vz) velocity in the z direction
end

7 Comments

Please show the ode45 call that uses this function.
Do not invoke this with
ode45(untitled18, ....)
Instead you would need
ode45(@untitled18, ....)
So I've made some changes to the callouts. Here is my ode function:
function drv = propagate2BP(t,rv)
% small r is position
% big r is distance
mu = 3.986004*(10^5); %%unit is in km^3/s^2, and is Earth's Gravitational parameter
drv = zeros(6,1);
rx = rv(1);
vx = rv(2);
ry = rv(3);
vy = rv(4);
rz = rv(5);
vz = rv(6);
R = sqrt((rx^2)+(ry^2)+(rz^2));
% X component/ i direction
drv(1) = rv(2);
drv(2) = (-mu.*rx)/(R^3); % (vx) velocity in the x direction
% Y component/ j direction
drv(3) = rv(4);
drv(4) = (-mu.*ry)/(R^3); % (vy) velocity in the y direction
% Z component/ k direction
drv(5) = rv(6);
drv(6) = (-mu.*rz)/(R^3); % (vz) velocity in the z direction
end
Here is my script:
mu = 3.986004*(10^5); % unit is in km^3/s^2, and is Earth's Gravitational parameter
ai = (15000+6378); % unit is in km
ei = .3;
ii = 10;
bigomegai = 0;
smallomegai = 10;
trueai = 0;
pi = ai.*(1-ei.^2);
velcompP = sqrt(mu/pi)*(-sind(trueai));
velcompQ = sqrt(mu/pi)*(ei+cosd(trueai));
velcompW = 0;
velpqw = [velcompP ; velcompQ ; velcompW];
rcompP = (pi*cosd(trueai)/(1+ei*cosd(trueai)));
rcompQ = (pi*sind(trueai)/(1+ei*cosd(trueai)));
rcompW = 0;
rpqw = [rcompP ; rcompQ ; rcompW];
IJKPQWrowtop = [(cosd(bigomegai)*cosd(smallomegai)-sind(bigomegai)*sind(smallomegai)*cosd(ii)) (-cosd(bigomegai)*sind(smallomegai)-sind(bigomegai)*cosd(smallomegai)*cosd(ii)) (sind(bigomegai)*sind(ii))];
IJKPQWrowmiddle = [(sind(bigomegai)*cosd(smallomegai)+cosd(bigomegai)*sind(smallomegai)*cosd(ii)) (-sind(bigomegai)*sind(smallomegai)+cosd(bigomegai)*cosd(smallomegai)*cosd(ii)) (-cosd(bigomegai)*sind(ii))];
IJKPQWrowbottom = [(sind(smallomegai)*sind(ii)) (cosd(smallomegai)*sind(ii)) cosd(ii)];
IJKPQW = [IJKPQWrowtop;IJKPQWrowmiddle ;IJKPQWrowbottom ];
Rvectori = IJKPQW*rpqw;
Vvectori = IJKPQW*velpqw;
vinputx = Vvectori(1);
rinputx = Rvectori(1);
vinputy = Vvectori(2);
rinputy = Rvectori(2);
vinputz = Vvectori(3);
rinputz = Rvectori(3);
rimag = norm(Rvectori);
vimag = norm(Vvectori);
orbitalenergyi = ((vimag.^2)/2)-(mu/rimag);
tolerance = 1e-13;
t = [0 172800]; % unit is in seconds, 2 orbital periods is 2 days
options = odeset('RelTol',tolerance,'AbsTol',tolerance);
[t,rv] = ode45(@propagate2BP, t, [rinputx, vinputx, rinputy, vinputy, rinputz, vinputz], options);
rxre = rv(:,1);
vxre = rv(:,2);
ryre = rv(:,3);
vyre = rv(:,4);
rzre = rv(:,5);
vzre = rv(:,6);
rrvector = [rxre ryre rzre];
rrtrans = (rrvector.');
vrvector = [vxre vyre vzre];
vrtrans = (vrvector.');
I am still getting the input issue. I would like to plot this orbit.
Your code (as you posted it in your most recent Comment) runs without error for me (in R2018a).
Plotting it with:
figure(1)
plot(t, rv)
grid
produces what appear to be reasonable results.
I am using R2017a. I don't think that would be the issue but I am upgrading the version now.
I agree. I doubt there are any significant differences between those versions with respect to ode45.
What line is throwing the error?
Not enough input arguments.
Error in propagate_2BP22 (line 11) rx = rv(1);
Error in untitled5 (line 41) [t,rv] = ode45(propagate_2BP22, t, [rinputx, vinputx, rinputy, vinputy, rinputz, vinputz], options);
Note: I did change the name again but the callouts match so that shouldn't be an issue.

Sign in to comment.

Answers (2)

Your latest code (as you posted it in your earlier Comment), runs for me without error.
The only thing I can think of is that you have a function called ‘rv’ somewhere. To find it, run this:
q = which('rv','-all')

2 Comments

I got the code to run. How can I subplot for velocity, position, and acceleration?
You could run your ‘propagate2BP’ function with the solved values to get some of those (I do not understand what variables those would be).
It would be easier to begin with the solved position values and use numerical differentiation one time to then get the velocity values, and two times to get acceleration.
Use the gradient (link) function to do the numerical differentiation. This will be more accurate if you define ‘t’ as:
t = linspace(0, 172800, 21681);
or something similar, to get equally-spaced solved position values.
In differentiating a matrix, gradient differentiates across both the rows and columns, and the first output is the derivative down the columns. I would do the differentiation as:
drv = gradient(rv, mean(diff(t)), 1);
Note that this differentiates all the columns, so choose the original position columns from the ‘drv’ output.

Sign in to comment.

The error line you post is
[t,rv] = ode45(propagate_2BP22, t, [rinputx, vinputx, rinputy, vinputy, rinputz, vinputz], options);
which is not the same as what you posted before that, which was
[t,rv] = ode45(@propagate2BP, t, [rinputx, vinputx, rinputy, vinputy, rinputz, vinputz], options);
Notice the difference between propagate2BP and @propagate2BP . You need the @ version so your propagate_2BP22 would have to be @propagate_2BP22

Categories

Find more on Simulink in Help Center and File Exchange

Tags

Asked:

on 10 Sep 2018

Commented:

on 10 Sep 2018

Community Treasure Hunt

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

Start Hunting!