Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am new to mathematica and was experimenting with NDSolve and doing a simple demonstration of orbital motion and Newtons laws. I put together the following code which all seems to work except the Graphics object at the origin seems to flicker/move ? I tried moving the graphics object that displays this object to the initialisation section but that doesn't seem to help. I've also tried trackedsymbols but that doesn't work either. Any ideas/suggestions much appreciated.

Module[{t,tfinal=20,x0=1.5,y0=1.0,xv0=0.2,yv0=0.5,range = {{-3,3},{-3,3}},eqs,sol,fx,fy},
eqs = {y''[t]+y[t]/(x[t]^2+y[t]^2)^(3/2)==0,x''[t]+x[t]/(x[t]^2+y[t]^2)^(3/2)==0,x'[0]==xv0,y'[0]==yv0,x[0]==x0,y[0]==y0};
sol = Flatten @ NDSolve[eqs,{x,y},{t,tfinal}];
fx[t_]:=x[t] /. sol;
fy[t_]:= y[t] /. sol;
Manipulate[
g =Graphics[{Red,PointSize[0.02],Point@ {fx[t],fy[t]}},PlotRange->range];
Show[p,g,p1],
{t,0,tfinal},
Initialization :> {p=ParametricPlot[{{fx[k],fy[k]}},{k,0,tfinal},PlotRange->range,PlotLabel->"Planetary motion"],p1=Graphics[{Blue,PointSize[0.03],Point[{0,0}]},PlotRange->range]}
]
]

enter image description here

Here's an ImageDifference of two adjacent frames of a screen recording of the animation:

image difference of two frames

The central dot has moved sideways...

share|improve this question
2  
In your example, time is undefined. Nevertheless, when I set it to any numerical value, the example works as expected. If you refer to the fact that the red dot moves so fast around {0,0} that it seems to cut through some distance, you could try holding down the Alt key while moving the slider which slows down updating. For me it shows a smooth movement around the focus. –  István Zachar Apr 7 '13 at 17:29
    
Same as @IstvánZachar here Mma v 8.0 –  belisarius Apr 7 '13 at 17:46
    
And don't include t into the module vars, as it's localized by Manipulate[] –  belisarius Apr 7 '13 at 17:48
    
@belisarius I was wondering about that myself. Does it really matter? No value of t gets out of the Manipulate to the Module, thus updating t does not cause interference with the symbolic nature of t in the equations. Generally of course I agree with you, but does it really have any risk here (apart from giving t any value in the Module)? –  István Zachar Apr 7 '13 at 17:59
    
@IstvánZachar I think it's simply not necessary to scope it –  belisarius Apr 7 '13 at 18:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.