# Numerical solution of pendulum equation

Given a system of equations:

\begin{align} &f''(x) = -a \cdot \sin(f(x))\\ &f(0) = b\\ &f'(0) = c \end{align}

$$a, b, c, dt, N$$ are arbitrary parameters.

How to get a values of $$f(0), f(dt), f(2dt) ... f(N)$$. I am stuck with the non-linearity of the right part of the first equation.

I will be very glad, if someone will show me an implementation of an algorithm calculating this.

• I am stuck with the non-linearity of the right part of the first equation. Does that comment mean that you are able to numerically solve the system for the linear case? – nicoguaro Apr 24 at 18:34
• Yes, i can build a system of linear equations for each $f_i$ and build a matrix, which can be solved via Gaussian method. – Constantor Apr 24 at 18:40
• It's better to be consistent in using x or t for the independent variable. – Maxim Umansky Apr 25 at 4:53
• Since this is an initial-value problem, you can solve it numerically using the Euler method, for example. – Christoph Apr 25 at 5:17

With the functions $$y_1 := f$$, $$y_2 := f'$$, $$\pmb{y} := (y_1,y_2)^{\top}$$, we obtain an initial-value problem with an autonomous first-order system: $$\pmb{y}' = \left( \begin{array}{c} y_2\\ -a \sin(y_1) \end{array} \right) =: \pmb{f}(\pmb{y}), \quad \pmb{y}(0) = \left( \begin{array}{c} b\\ c \end{array} \right) =: \pmb{y}_0.$$ We now choose the Euler method for the numerical solution: $$\pmb{y}_i = \pmb{y}_{i-1} + h \pmb{f}(\pmb{y}_{i-1}),$$ $$i = 1, 2, \dots$$. This yields approximations $$\pmb{y}_i \simeq \pmb{y}(x_i)$$ at the positions $$x_i = ih$$.
• You could use a higher-order Runge-Kutta method instead of Euler, and/or reduce the step size $h$. – Christoph Apr 25 at 13:34