- #1
Rhabdovirus
- 6
- 0
Hey guys, I've been fighting this problem all weekend with little avail. I only know a little Java, but we have this final project in MatLab, a program I don't really know.
I need to compute the orbit of a comet using the Runge-Kutte, Euler and midpoint methods. The program should terminate after 1 orbit. I then need to compute eccentricity, a, period and [tex]r_{min}[/tex].
I'm using the differential equation [tex]\mu \ddot{r}[/tex] = F(r) + l2/[tex]\mu[/tex]2*r2
F(r) is the central force, -GMm/r2 in this case
Here's my code so far, I'm having trouble figuring out how to plot it
Homework Statement
I need to compute the orbit of a comet using the Runge-Kutte, Euler and midpoint methods. The program should terminate after 1 orbit. I then need to compute eccentricity, a, period and [tex]r_{min}[/tex].
Homework Equations
I'm using the differential equation [tex]\mu \ddot{r}[/tex] = F(r) + l2/[tex]\mu[/tex]2*r2
F(r) is the central force, -GMm/r2 in this case
The Attempt at a Solution
Here's my code so far, I'm having trouble figuring out how to plot it
Code:
%Differential equation: r'' = F(r)/mu + ((l^2)/((mu^2)*(r^2)))
clear all; help orbit;
%Variables
%Fr = G*Msun*Mcomet/r^2;
%l = Mcomet*v*r;
%Constants
Msun = 2e30;
Mcomet = 2e6;
G = 6.67e-11;
mu = (Msun*Mcomet)/(Msun+Mcomet);
time = 0;
%initial conditions
r0 = 250000; %initial radius from Sun to comet in m
v0 = 8000; %initial tangential velocity of comet in m/s
r = r0; v = v0;
tau = 1000; %timestep in seconds
maxstep = 1000;
for iStep = 1:maxstep
%Euler Method v_n+1 = (v_n + tau*acc_n)
% r_n+1 = (r_n + tau*v_n)
acc = -G*Msun*r./norm(r)^3;
r = r + tau*v;
v = v + tau*acc;
time = time + tau;%Midpoint v_n+1 = v_n + tau*a_n
% r_n+1 = r_n + tau*v_n + .5*a_n*tau^2
acc = -G*Msun*r./norm(r)^3;
v = v + tau*acc;
r = r + tau*v + .5*acc*(tau^2);end