Class xlifepp::RK4TP#
-
template<class T, class P>
class RK4TP : public xlifepp::OdeSolverTP<T, P>#
-
Runge-Kutta 4th order method for solving ODEs which functions depending on parameters.
This class implements the Runge-Kutta 4th order method for solving ODEs of the form y’=f(t,y). The method computes the solution by iteratively updating the state y at each time step dt, using the formula: y(t+dt) = y(t) + dt/6 * (k1 + 2*k2 + 2*k3 + k4) where: k1 = f(t,y(t),params) k2 = f(t+dt/2, y(t) + dt/2 * k1,params) k3 = f(t+dt/2, y(t) + dt/2 * k2,params) k4 = f(t+dt, y(t) + dt * k3,params) The compute method fills the tys_ list with pairs of (time, state) at each time step. The class also provides methods to access the computed states and times, and to save the results to a file.
- Template Parameters:
-
T – type of the state (real_t, complex_t, Vector<real_t>, Vector<complex_t>, …)
P – type of the parameters (default is real_t)
- Param f:
-
function of the ODE y’=f(t,y) with prototype T& f(real_t t, const T& y, T& fty, P& params)
- Param t0:
-
initial time
- Param tf:
-
final time
- Param dt:
-
initial time step
- Param y0:
-
initial state
- Param pars:
-
optional parameters for the function f (default is nullptr)
- Param na:
-
name of the method (default is “RK4”)
Note
This class is not meant to be used directly, but as a base class for specific ODE solvers like RK4.