Virtual Testbed
Ship dynamics simulator for extreme conditions
|
Runge—Khutta—Fehlberg initial value problem solver. More...
#include <rkf45.hh>
Public Types | |
typedef T | value_type |
Public Member Functions | |
RKF45 (const RKF45 &)=default | |
RKF45 & | operator= (const RKF45 &)=default |
RKF45 (RKF45 &&)=default | |
RKF45 & | operator= (RKF45 &&)=default |
template<class Function , int N> | |
blitz::TinyVector< T, N > | solve (Function f, T t0, T t1, const blitz::TinyVector< T, N > &x0) |
Solve system of ordinary differential equations with right hand sides f . More... | |
template<class Function , int N> | |
blitz::TinyVector< T, N > | operator() (Function f, T t0, T t1, const blitz::TinyVector< T, N > &x0) |
Solve system of ordinary differential equations with right hand sides f . More... | |
T | min_step () const noexcept |
void | min_step (T rhs) |
T | max_step () const noexcept |
void | max_step (T rhs) |
T | tolerance () const noexcept |
void | tolerance (T rhs) |
void | verbose (bool rhs) noexcept |
bool | verbose () const noexcept |
Runge—Khutta—Fehlberg initial value problem solver.
|
inline |
Solve system of ordinary differential equations with right hand sides f
.
[in] | f | right hand sides of the equations |
[in] | t0 | initial time instant |
[in] | t1 | final time instant |
[in] | x0 | initial value at \(t=t_0\) |
|
inline |
Solve system of ordinary differential equations with right hand sides f
.
[in] | f | right hand sides of the equations |
[in] | t0 | initial time instant |
[in] | t1 | final time instant |
[in] | x0 | initial value at \(t=t_0\) |
Calculate coefficients:
\begin{eqnarray*} k_1 &=& h f\left(t_i, x_i\right) \\ k_2 &=& h f\left( t_i + \frac{1}{4}h, x_i + \frac{1}{4}k_1 \right) \\ k_3 &=& h f\left( t_i + \frac{3}{8}h, x_i + \frac{3}{32}k_1 + \frac{9}{32}k_2 \right) \\ k_4 &=& h f\left( t_i + \frac{12}{13}h, x_i + \frac{1932}{2197}k_1 - \frac{7200}{2197}k_2 + \frac{7296}{2197}k_3 \right) \\ k_5 &=& h f\left( t_i + h, x_i + \frac{439}{216}k_1 - 8 k_2 + \frac{3680}{513}k_3 - \frac{845}{4104}k_4 \right) \\ k_6 &=& h f\left( t_i + \frac{1}{2}h, x_i - \frac{8}{27}k_1 + 2 k_2 - \frac{3544}{2565}k_3 + \frac{1859}{4104}k_4 - \frac{11}{40}k_5 \right) \end{eqnarray*}
Calculate \(x_{i+1}\) using a Runge—Kutta method of order 4. N.B. \(k_2\) is not used here.
\[ x_{i+1} = x_i + \frac{25}{216}k_1 + \frac{1408}{2565}k_3 + \frac{2197}{4101}k_4 - \frac{1}{5}k_5 \]
Calculate \(x_{i+1}\) (denoted here as \(z_{i+1}\)) using a Runge—Kutta method of order 5. N.B. \(k_2\) is not used here.
\[ z_{i+1} = z_i + \frac{16}{135}k_1 + \frac{6656}{12825}k_3 + \frac{28561}{56430}k_4 - \frac{9}{50}k_5 + \frac{2}{55}k_6 \]
Calculate optimal step size \(sh\).
\[ s = \left( \frac{\textrm{tol} \, h} {2\,\textrm{max}\left|x_{i+1} - z_{i+1}\right|} \right)^{1/4} \]
Clamp step size \(h\) to \([h_{\textrm{min}},h_{\textrm{max}}]\). Clamp time instant to \([t_{\textrm{min}},t_{\textrm{max}}]\).