Let me make a couple of points:
- Convert your equation into a proper differential equation, i.e.
r''[t] == -GM/Norm[r[t]]^3 r[t]
Even better, write it in Cartesian coordinates. Remember that Norm[r[t]] equals Sqrt[ x[t]^2 + y[t]^2]. Also remember, that the orbit is always in a plane, so you can chose your coordinates accordingly and drop the equation for z[t]
deq = {
x''[t] == -GM x[t]/(x[t]^2 + y[t]^2)^(3/2) ,
y''[t] == -GM y[t]/(x[t]^2 + y[t]^2)^(3/2)
};
Use proper units. For the Earth orbiting the Sun, it is useful to choose 1 AU as the unit of length (this way the radius of the orbit is 1, ignoring eccentricity, of course) and 1 year as the unit of time
If you use those units, you can easily figure out that with an initial radius of 1 (e.g. given by x[0]==1, y[0]==0, the initial velocity must be 2[\Pi] (e.g. x'[0]==0, y'[0]==2[\Pi] - simply divide the length of the orbit by the time it tales to complete it.
deqIC = {x[0] == 1,
y[0] == 0,
x'[0] == 0 ,
y'[0] == 2 \[Pi]};
By pretty much the same argument, GM = (2[\Pi])^2
Now you can simply dump the differential equation into NDSolve and let Mathematica do the rest:
s = Reap@NDSolve[ Join[deq, deqIC], {x, y}, {t, 0, 1},
MaxSteps -> 100000,
InterpolationOrder -> Automatic,
Method -> "ExplicitRungeKutta",
StepMonitor :> Sow[ {x[t], y[t]}]
];
Show[ ListPlot[s[[2]], PlotStyle -> Directive[{PointSize[0.02], Red}]],
ParametricPlot[Evaluate[{x[t], y[t]} /. s[[1]]], {t, 0, 1},
Frame -> True, AspectRatio -> Automatic],
Frame -> True, AspectRatio -> Automatic]
The Sow/Reap stuff is only showing off - you can get the actual points at which Mathematica evaluates your differential equation.
As far as FORTRAN goes - if this isn't a homework where you have to use FORTRAN, forget about it. There is no advantage in using FORTRAN code and branch out to Mathematica just for the plotting.
NDSolveis already built-in, and has options for controlling the method used. That's not to say that you can't program the solution like you would in Fortran, but if you did, you would be disappointed at the performance. The reason Mathematica exists is to make it so that you don't have to waste time explicitly writing Fortran-like loops when doing a numerical solution. – DumpsterDoofus Sep 12 '14 at 15:14doisDo.. – george2079 Sep 12 '14 at 15:15