The basic model is the 1d Harmonic Oscillator
- f(x) = -x, dv/dt = f(x), dx/dt = v for t > 0,
with solution x(t) = A*sin(t) + B*cos(t) with coefficients A and B determined by B = x(0) and A = v(0). Here f(x) = -x is a linear spring force. Write code for non-linear spring force e g f(x) = -x^3.
Newton’s gravitational force f(x) from a point mass at x = 0 in 3d is given as the gradient of the gravitational potential = 1/|x|, that is
- f(x) = -x/|x|^3.
Write 2d code for the motion of one body subject to f(x).
Test with different gravitational forces
- f(x) = -x/|x|^p
with different p (help: Variants of Newton’s Gravitational Model).