I wrote trajectory calculator, for a small mass in a gravitational field, that uses forward Euler numerical integration. It works as expected until I try to subject my small mass to drag, or lessen its velocity at each time-slice in any way. The reason I want to do this is to make the small mass spiral inwards and eventually hit the 'planet' which is causing the gravitational field. I've tried several methods:defining a new vector valued function Fdrag which returns a force opposite to velocity, then summing with with my Fgrav to get a resultant force Fresultant, which gives acceleration, which gives velocity...shrinking the magnitude of the velocity vector by an arbitrary amount each step, say 10%.What this leads to is strange behaviour where the small mass follows a distorted, but recognizable, trajectory for a while, then shoots off in a straight line (see fig 2. 'after'). Prior to adding this attempted 'drag' to the simulation, the small mass orbits in a spiral exactly as I expect it to, given the errors in the Euler method (see fig 1. 'before').I didn't want to make the post too cluttered but I can attach code on request if people think it would help to diagnose the problem.Please see before/after graphs enclosed below:N.B. the program takes 'current' position and velocity and returns 'next' position and velocity. The method used to create the 'after' graph below was to calculate the 'next' velocity value and shrink it by 10% (multiply each component by 0.9).
python trajectory calculator works well UNTIL i try to introduce drag - what am I doing wrong?
computational physics