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.

  • $\begingroup$ 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? $\endgroup$ – nicoguaro Apr 24 '20 at 18:34
  • $\begingroup$ Yes, i can build a system of linear equations for each $f_i$ and build a matrix, which can be solved via Gaussian method. $\endgroup$ – Constantor Apr 24 '20 at 18:40
  • $\begingroup$ It's better to be consistent in using x or t for the independent variable. $\endgroup$ – Maxim Umansky Apr 25 '20 at 4:53
  • $\begingroup$ Since this is an initial-value problem, you can solve it numerically using the Euler method, for example. $\endgroup$ – Christoph Apr 25 '20 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$.

  • 1
    $\begingroup$ Euler is of course just one simple possibility. For the conservation of energy it might be advantageous to use a symplectic method such as Verlet integration. $\endgroup$ – Christoph Apr 25 '20 at 8:14
  • $\begingroup$ Thank you very much! But I know that Euler's method is not accuarate enough. Is there a way with better accuracy? $\endgroup$ – Constantor Apr 25 '20 at 12:38
  • $\begingroup$ You could use a higher-order Runge-Kutta method instead of Euler, and/or reduce the step size $h$. $\endgroup$ – Christoph Apr 25 '20 at 13:34
  • $\begingroup$ Higher order (explicit) RK does not imply a smaller step size. A-Stability has to be taken into account $\endgroup$ – VoB Apr 25 '20 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.