# How can we ensure the result of Mathematica is exactly correct?

This is an example, I plot a function and find it has a defect when x approximates 400.

Plot[Cos[.3 x] Exp[-0.01 x], {x, 0, 1000}, PlotRange -> All] Another example, we calculate the orbit of planet motion. As we know, the orbit of planet is ellipse when the total energy is negative. However, if we calculate it in a long time, the result will deviate from ellipse markedly - while Mathematica has no any warning or message here!

The code and result showed below:

M = 4; a = 700; (*a is the total time of this simulation*)
s =
NDSolve[{x''[t] == -((GM (x[t] + 1))/((x[t] + 1)^2 + y[t]^2)^1.5),
y''[t] == -((GM y[t])/((x[t] + 1)^2 + y[t]^2)^1.5), y == 2,
x == .3, x' == .2, y' == -.1}, {x, y}, {t, 0, a},
MaxSteps -> 10^8];
ParametricPlot[Evaluate[{x[t], y[t]} /. s], {t, 0, a}] What I wonder is how to make sure Mathematica's result is exactly correct? When we find something special with Mathematica, how can we know it is a new thing, or just a wrong result of Mathematica?

• – Mr.Wizard Jun 24 '14 at 5:45
• A good start is understanding proper use of Mathematica, how built-ins (and their options) work, etc. (e.g. PlotPoints, MaxRecursion and Method in your plot visualization example). The documentation is pretty good pointing out gotchas and their effects and ways to avoid them. – ciao Jun 24 '14 at 6:02
• For me, a good approach would be also to use another, redundant, tool- for those extremely important results. – VividD Jun 24 '14 at 10:37

Simply increase PlotPoints:

Plot[Cos[.3 x] Exp[-0.01 x], {x, 0, 1000},
PlotRange -> {{300, 500}, {-0.05, 0.05}}, ImageSize -> 600, PlotPoints -> 2000] Increasing PlotPoints would also draw a smooth ellipse in your orbit example

• I am sorry, but this does not attempt to answer the question. – Sektor Jun 24 '14 at 12:49
• @Sektor - I am sorry too, but my tip attempts to answer the question. Using Plot and ParametricPlot YOU have to decide how many PlotPoints you want or need. When you use Table and then ListLinePlot with the above example you get the same smooth image, i.e. the numerics are correct. – eldo Jun 24 '14 at 13:02
• @Sektor - I now answer the question: "How to make sure Mathematica's result is exactly correct?" Answer: With pencil and paper like in the good all days :) – eldo Jun 24 '14 at 13:15
• I think this answers the issue that caused the question (+1). The title of the question is too broad to allow a better answer. – Jens Jun 24 '14 at 17:40
• @VividD I think your opinion is appropriate. – S.Lai Jun 25 '14 at 9:52