# Numerical Methods of solving a non-linear ODE?

I want to solve the nonlinear equation $$\frac{d^2x}{dt^2} + k\sin x = 0$$, numerically. I found that solving this elliptic integral would be cumbersome, so is there a numerical method i could use to solve it?

I have tried to apply Newton's method, but it requires a rough value of where the solution lies, which i do not have. in all my searches for numerical methods to solve this equation, i couldn't find any function $$f(x)$$ which contained both a derivative of $$x$$ and a function of $$x$$, of the form $$f(x) = x''+ k\, g(x)$$ Any input would be appreciated

• That's a large amplitude pendulum equation, and an exact solution exist there, expressed in terms of special functions. For numerical solution treat it as a system of two 1st order ODEs. Oct 29 '20 at 21:56
• Any book on numerical methods will have a section on the numerical integration of ODEs. Yours is a typical ODE to which these methods are applicable. Oct 29 '20 at 22:41
• What exactly do you mean with applying the Newton method to solve an ODE? Oct 30 '20 at 12:17
• Is this an initial value problem or a boundary value problem? Oct 30 '20 at 22:00
• @LutzLehmann Probably the OP is referring to the numerical solution with some implicit method
– VoB
Nov 17 '20 at 0:27

## 2 Answers

Just introduce the velocity as an additional variable and solve: $$\frac{d}{dt}(x,\dot{x})^t = (\dot{x}, k\sin(x))^t$$

You can then solve that with any ODE integrator, e.g. ode45 in Matlab, RK45 with Scipy...

Note: I am quite confused as to why you would use a Newton's method to solve this problem... You can apply it to solve each time step of an implicit scheme, or to solve your solution, all time steps at once, on a discretised time grid. But I don't see how you would solve the original equation with that...

Just too long for a comment.

As others mentioned, there's a huge amount of codes/literature available on the web so that you'll have no problem to find any suitable reference. Also, your specific example is one of the most standard example taken from physics. Btw, if we use backward euler, after defining $$X(t)=[x(t),\dot{x}(t)]$$ and writing your ODE as a first order system you obtain, after calling $$X_n=[x(t_n),\dot{x}(t_n)]$$ the solution at time $$t_n = y_0 + hn$$, with $$h$$ the time step:

$$X_{n+1}= X_n + h [\dot{x}(t_n), k \sin(x(t_n))]$$

which is a non-linear equation in $$X_n$$ that is usually solved with Newton's method (at each time step $$n$$)