Solving a second order ODE with ode45???

I'm very much a beginner with Matlab, but I did manage to solve this before in a simpler problem, however applying the same technique here doesn't seem to be working! Am I overlooking something?
For context, I'm trying to find the position of an orbiting body over time given initial position and velocity vectors. The vector R points from the centre of the larger mass (which does not lie at the origin) to the centre of the orbiting mass.
Any help at all would be greatly appreciated!
function A2Q2()
close all
clc
x0 = 3207;
y0 = 5459;
z0 = 2714;
dx0 = -6.532;
dy0 = 0.7835;
dz0 = 6.142;
f0 = [x0 y0 z0 dx0 dy0 dz0];
[t,f] = ode45(@Eq, [0 3.4*60*60], f0);
plot3(f(:,1),f(:,2),f(:,3))
end
function dRdt = Eq(t,f)
mS = 100; % Placeholder value!!
mE = 5.972e24;
G = (6.67384e-11)/1000;
mu = G*(mS + mE);
x = f(1);
y = f(2);
z = f(3);
dx = f(4);
dy = f(5);
dz = f(6);
r = sqrt((x^2)+(y^2)+(z^2));
d2x = -(mu/(r^3))*x;
d2y = -(mu/(r^3))*y;
d2z = -(mu/(r^3))*z;
dRdt = [dx dy dz d2x d2y d2z]';
end

답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

질문:

2015년 4월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by