1

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]

Mathematica graphics

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[0] == 2, 
             x[0] == .3, x'[0] == .2, y'[0] == -.1}, {x, y}, {t, 0, a}, 
             MaxSteps -> 10^8];
ParametricPlot[Evaluate[{x[t], y[t]} /. s], {t, 0, a}]

enter image description here

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?

Öskå
  • 8,587
  • 4
  • 30
  • 49
S.Lai
  • 13
  • 2

1 Answers1

3

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]

enter image description here

Increasing PlotPoints would also draw a smooth ellipse in your orbit example

eldo
  • 67,911
  • 5
  • 60
  • 168
  • I am sorry, but this does not attempt to answer the question. – Sektor Jun 24 '14 at 12:49
  • 1
    @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
  • So, you are telling me that this answers the question "How to make sure Mathematica's result is exactly correct?" ?! – Sektor Jun 24 '14 at 13:09
  • I am not saying it is not related, but to consider it an answer ... – Sektor Jun 24 '14 at 13:09
  • 1
    @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
  • Good for you :) We should all upvote your answer then :) – Sektor Jun 24 '14 at 13:17
  • Thank you all. In fact, I knew PlotPoints can improve it, but I don't know how much PlotPoints is enough, – S.Lai Jun 24 '14 at 14:37
  • @S.Lai - just start with a large number, f.e, I used 2000 for the ellipse. A smooth plot came immediately with a = 1000 and GM = 0.9. – eldo Jun 24 '14 at 14:41
  • 1
    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
  • I would interpret the answer this way: "As you see, in this particular case, you can do something to make Mathematica be more accurate. Try similar in any other situation." This makes this answer fine, and really a nice and useful answer to the question. – VividD Jun 25 '14 at 05:28
  • 1
    @VividD I think your opinion is appropriate. – S.Lai Jun 25 '14 at 09:52