I have been given the following question:
The differential equation describing the angular position $\theta$ of a mechanical arm: $$\ddot{\theta}=\frac{a(b-\theta)-\theta\dot{\theta}^2}{1-\theta^2}$$ where $a=100ms^{-2}$, b=15. If $\theta(0)=2\pi, \dot{\theta}=0$. Compute $\theta$ & $\dot{\theta}$ when t=0.5s with tolerance of $10^{-3}$.
I am required to create a python program to solve this. I have no problem with making the program. However, normally these problems require me to split the differential equation into a system of first order differential equations (by introducing a new variable).
The reason for posting is to see if anyone can help me to split this into a system of DE's, as I have no idea where to start.
(The task in the question is ambiguous and gives a not solvable problem in the apparent interpretations. However, the original task that can be found in the exercise 14 on page 271 of Numerical Methods in Engineering with MATLAB® By Jaan Kiusalaas, is well solvable.)
The usual method to transform a higher order ODE into a first order system via the derivatives array $\dot \theta = \omega$, $\dot\omega=rhs(\theta,\omega)$ can be implemented in a python function as
This then can be fed to an ODE solver and evaluate for instance as in the following lines where Richardson extrapolation is used to estimate the error of the second order method.
with the result
For demonstration purposes a second-order fixed-step Runge-Kutta method was used, the explicit midpoint or improved Euler method.