Not enough input arguments
Mostrar comentarios más antiguos
Hi so Im writing a code for plotting a satilite path in 3D. (I use here the 4th order Runge Kutta method) my main file is:
y0=[-6035,-3480,2500,-3.437,6.618,2.523];
tspan=[1 9000];
[t3out,y3out]=RK(ode_function,tspan,y0,100,4);
The RK function is as follows:
function [tout,yout]=RK(ode_function,tspan,y0,h,rk)
i=1;
.
.
elseif rk==4
for t=tspan(1):h:tspan(2)
[k11,k12]=ode_function(y0(i,:));
ytemp(1:3)=y0(i,1:3)+k11*h/2;
ytemp(4:6)=y0(i,4:6)+k12*h/2;
[k21,k22]=ode_function(ytemp);
ytemp(1:3)=y0(i,1:3)+k21*h/2;
ytemp(4:6)=y0(i,4:6)+k22*h/2;
[k31,k32]=ode_function(ytemp);
ytemp(1:3)=y0(i,1:3)+k31*h;
ytemp(4:6)=y0(i,4:6)+k32*h;
[k41,k42]=ode_function(ytemp);
y0(i+1,1:3)=y0(i,1:3)+1/6*(k11+k21*2+k31*2+k41)*h;
y0(i+1,4:6)=y0(i,4:6)+1/6*(k12+k22*2+k32*2+k42)*h;
i=i+1;
end
tout=[tspan(1):h:tspan(2)];
yout=y0;
end
which outputs a time vector and the y vector which contains position (1:3) and velocity (4:6) components
and calls to the ode function which calculates the needed derivatives as follows:
function [f1,f2]=ode_function(y)
%y is a 1x6 row vector containing position (1:3) and velocity (4:6) components
u=3.98716708*10^5;
R=6378.137;
J=0.0010826267;
r=sqrt(y(1)^2+y(2)^2+y(3)^2);
a=[-3*J*u*R^2*y(1)/2/r^5*(1-5*y(3)^2/r^2),-3*J*u*R^2*y(2)/2/r^5*(1-5*y(3)^2/r^2),-3*J*u*R^2*y(3)/2/r^5*(1-5*y(3)^2/r^2)];
f1=y(4:6);
f2=-u*y/r+a;
end
anyways when i run this there is always an error in the RK function stating:
Not enough input arguments. (on the line beginning with r=)
any solutions to this please?
Respuestas (1)
Walter Roberson
el 27 de Abr. de 2017
[t3out,y3out]=RK(@ode_function,tspan,y0,100,4);
5 comentarios
Andrew Shepherd
el 27 de Abr. de 2017
Walter Roberson
el 27 de Abr. de 2017
Nothing else is obvious in the code you posted, but the @ was definitely missing in the line you had.
Could you post the full code?
Andrew Shepherd
el 27 de Abr. de 2017
Andrew Shepherd
el 27 de Abr. de 2017
Walter Roberson
el 27 de Abr. de 2017
Once you change all three references to ode_function in RungeKutta.m then you will run into a different problem.
Your y0 is a vector of length 6, so in your ode_function y will be a vector of length 6. In ode_function you calculate a as a vector of length 3. Then you have
f2=-u*y/r+a;
so you are attempting to add a vector of length 6 and a vector of length 3.
Categorías
Más información sobre Runge Kutta Methods en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!