Generating a 4th order Runge-Kutta Integrator solver for the motion equation.

8 visualizaciones (últimos 30 días)
The Problem statement is as followed.
Using the constant for km/s. and the inital conditions
km
and
km/s
The orbital motion equation is:
integrate using runge kutta RK4 (not ODE45) for an h =10 seconds and an end time of 86000 seconds
So i tried the ODE45 approach to this problem and my results generated a 3d plot that isnt consistent with my expectations. The orbit's size should not be changing, in my case, the orbit seems to either shift or the size diminishes as the time increases. The expected result is an ellipse that doesnt change in size aka major axis stays constant as time increases (tested it out with higher values of time). Im looking for an alternative integrator solver that can capture these expectations. What twould be the best approach to solving this?
function xdot = exfunc(t,x)
mu = 398600.64;
r = x(1:3);
rdot = x(4:6);
rmag = norm(r);
rdotdot = -(mu/rmag^3)*r;
xdot = [rdot;rdotdot];
end
r0 = [8598; 5076; 45]; % km
v0 = [2.0; 4.9; 6.0]; % km/s
t0 = 0; % s
tend = 86000 %86400; % s
[t,x] = ode45(@exfunc,t0:10:tend,[r0,v0]);
plot3(x(:,1),x(:,2),x(:,3))
xlabel('X [km]')
ylabel('Y [km]')
zlabel('Z [km]')

Respuestas (1)

James Tursa
James Tursa el 30 de Mzo. de 2021
ode45( ) is not well suited to the orbit problem since the integration errors can systematically build up over time. You can try specifying tighter error tolerances. E.g.
opts = odeset('RelTol',whatever,'AbsTol',whatever);
And feed this opts variable to ode45( ).
That being said, it seems the instructions are to write your own RK4 solver using a fixed step size. Have you done that part? The ode45( ) solver will use a variable step size.
Nit: [r0,v0] should be [r0;v0]

Community Treasure Hunt

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

Start Hunting!

Translated by