\(\newcommand{\B}[1]{ {\bf #1} }\) \(\newcommand{\R}[1]{ {\rm #1} }\)
runge_kutta¶
View page sourceA C++ Fourth Order Runge Kutta Solver¶
Syntax¶
# include <cmpad/algo/runge_kutta.hpp>cmpad::runge_kutta ( fun , yi , tf, ns )Prototype¶
template <class Vector, class Fun>
Vector runge_kutta(
const Fun& fun ,
const Vector& yi ,
const typename Vector::value_type tf ,
size_t ns )
Purpose¶
This routine returns an approximate solution for \(y( t^f )\) where \(y(0) = y^i\) and \(y' (t) = f(y)\) .
Vector¶
The vectors yi and yf have this fun_obj vector_type .
fun¶
The syntax dy = fun ( yt ) , were yt is \(y(t)\) , sets dy equal to the derivative \(y'(t)\) . Both yt and dy are represented as Vector objects.
yi¶
is the value of \(y(t)\) at \(t = 0\) .
tf¶
is the value of t at which we wish to evaluate \(y(t)\) .
ns¶
is the number of Runge-Kutta steps to use. The more steps the smaller the step size and the more accurate the solution.
yf¶
The return value yf has the same size as yi and is the approximation for \(y(t)\) at t = tf .
Name |
Title |
|---|---|
runge_kutta.hpp |
|
xam_runge_kutta.cpp |
Example¶
xam_runge_kutta.cpp
contains an example and test of runge_kutta .