0
$\begingroup$

I've been asked to plot the orbit of the Earth around the sun over a period of three years. I've copied my exact code below. When I try to run it I get a series of errors, the first being:

NDSolve::ndsz: At t == 9.641612453331499*^-11`, step size is effectively zero; singularity or stiff system suspected.

I'm fairly new to Mathematica and I'm not sure why this error is appearing, or, when an error does appear, how to correct my code given what the error tells me.

G = 6.6723*10^(-11);
mSun = 1.989*10^30;
solEarth1 = NDSolve[{r''[t] == -G*mSun*r[t]/Norm[r[t]]^3, r[0] == {1, 0}, r'[0] == {0, 29785.1}}, r, {t, 0, 94608000}][[1]];
ParametricPlot[r[t] /. solEarth1, {t, 0, 94608000}, AxesLabel -> {"x (m)", "y (m)"}, PlotLabel -> "Orbit of Earth around the Sun"]
$\endgroup$
  • 6
    $\begingroup$ You have constants that differ by dozens of orders of magnitude; numerical results will be catastrophically bad. Please, work in natural units, where all parameters are of order one. $\endgroup$ – AccidentalFourierTransform Oct 2 '18 at 14:43
3
$\begingroup$

Error in the initial data. Earth's distance from the Sun 1 astronomical unit. But in meters it will be 149597870700.After fixing the code works

G = 6.6723*10^(-11);
mSun = 1.989*10^30;
solEarth1 = 
 NDSolve[{r''[t] == -G*mSun*r[t]/Norm[r[t]]^3, 
    r[0] == {149597870700, 0}, r'[0] == {0, 29785.1}}, 
   r, {t, 0, 94608000}][[1]]
ParametricPlot[r[t] /. solEarth1, {t, 0, 94608000}, 
 AxesLabel -> {"x (m)", "y (m)"}, 
 PlotLabel -> "Orbit of Earth around the Sun"]

fig1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.