Lorenz system#
\[\begin{split}\begin{cases}
\dot{x} = \sigma(y-x) \\
\dot{y} = \rho x - y - xz \\
\dot{z} = xy - \beta z \\
\end{cases}\end{split}\]
with initial condition \((x,y,z)=(1,1,1)\) and parameter \(\sigma=10\), \(\rho=28\) and \(\beta=\frac{8}{3}\).
Runge-Kutta solver#
First we need to write a problem:
using state_t = std::valarray<double>;
state_t lorenz(double t, const state_t& u)
{
double sigma=10. , rho=28., beta=8./3.;
return {
signa*( u[1] - u[0] ),
rho*u[0] - u[1] - u[0]*u[2],
u[0]*u[1] - beta*u[2]
};
}
//...
auto pb_rk = ode::make_problem(lorenz);
Note
We can also use a lambda to define a problem, or a collection of function as we present in the following part about splitting methods
Next we define the initial condition and call ode::solve()
:
state_t u0{1.,1.,1.};
using namespace observer; // to use _fobs litteral
ode::solve( pb_rk , ode::runge_kutta::rk33() , u0 , {0.,20.} , 0.01 , "lorenz_rk33.dat"_fobs );