Theoretica
A C++ numerical and automatic mathematical library
theoretica::ode Namespace Reference

Numerical methods for ordinary differential equations. More...

Classes

class  ode_solution_t
 The base type for the solution of an ODE, holding a vector \(t\) of the values of the time (independent variable) and a vector \(\vec x\) of the computed variables of the solution at each instant. More...
 

Typedefs

using ode_solution = ode_solution_t< vec< real > >
 The solution of an ODE with any number of variables.
 
using ode_solution1d = ode_solution_t< real >
 The solution of an ODE in 1 variable.
 
using ode_solution2d = ode_solution_t< vec2 >
 The solution of an ODE in 2 variables.
 
using ode_solution3d = ode_solution_t< vec3 >
 The solution of an ODE in 3 variables.
 
using ode_solution4d = ode_solution_t< vec4 >
 The solution of an ODE in 4 variables.
 
template<typename Vector >
using ode_function = std::function< Vector(real, const Vector &)>
 A function representing a system of differential equations, taking as input the time (independent variable) and the current value of the variables (dependent variables), returning the time derivatives of each variable, such as \(f\) in \(\dot \vec x = f(t, \vec x)\).
 

Functions

template<typename Vector , typename OdeFunction = ode_function<Vector>>
Vector step_euler (OdeFunction f, const Vector &x, real t, real h=0.0001)
 Compute one step of Euler's method for ordinary differential equations. More...
 
template<typename Vector , typename OdeFunction = ode_function<Vector>>
Vector step_midpoint (OdeFunction f, const Vector &x, real t, real h=0.0001)
 Compute one step of the midpoint method for ordinary differential equations. More...
 
template<typename Vector , typename OdeFunction = ode_function<Vector>>
Vector step_heun (OdeFunction f, const Vector &x, real t, real h=0.001)
 Compute one step of Heun's method for ordinary differential equations. More...
 
template<typename Vector , typename OdeFunction = ode_function<Vector>>
Vector step_rk2 (OdeFunction f, const Vector &x, real t, real h=0.001)
 Compute one step of the Runge-Kutta method of 2nd order for ordinary differential equations. More...
 
template<typename Vector , typename OdeFunction = ode_function<Vector>>
Vector step_rk4 (OdeFunction f, const Vector &x, real t, real h=0.01)
 Compute one step of the Runge-Kutta method of 4th order for ordinary differential equations. More...
 
template<typename Vector , typename OdeFunction = ode_function<Vector>>
Vector step_k38 (OdeFunction f, const Vector &x, real t, real h=0.001)
 Compute one step of Kutta's 3/8 rule method for ordinary differential equations. More...
 
template<typename Vector , typename OdeFunction = ode_function<Vector>>
Vector step_adams2 (OdeFunction f, const Vector &x0, real t0, const Vector &x1, real t1, real h=0.001)
 Compute one step of the Adams-Bashforth linear multistep method of 2nd order for ordinary differential equations. More...
 
template<typename Vector , typename OdeFunction = ode_function<Vector>>
Vector step_adams3 (OdeFunction f, const Vector &x0, real t0, const Vector &x1, real t1, const Vector &x2, real t2, real h=0.001)
 Compute one step of the Adams-Bashforth linear multistep method of 3rd order for ordinary differential equations. More...
 
template<typename Vector , typename OdeFunction = ode_function<Vector>, typename StepFunction = std::function<Vector(OdeFunction, real, const Vector&)>>
ode_solution_t< Vector > solve_fixstep (OdeFunction f, const Vector &x0, real t0, real tf, StepFunction step, real stepsize=0.001)
 Integrate an ordinary differential equation using any numerical algorithm with a constant step size, such as Runge-Kutta methods. More...
 
template<typename Vector , typename OdeFunction = ode_function<Vector>>
ode_solution_t< Vector > solve_euler (OdeFunction f, const Vector &x0, real t0, real tf, real stepsize=0.0001)
 Integrate an ordinary differential equation over a certain domain with the given initial conditions using Euler's method. More...
 
template<typename Vector , typename OdeFunction = ode_function<Vector>>
ode_solution_t< Vector > solve_midpoint (OdeFunction f, const Vector &x0, real t0, real tf, real stepsize=0.0001)
 Integrate an ordinary differential equation over a certain domain with the given initial conditions using the midpoint method. More...
 
template<typename Vector , typename OdeFunction = ode_function<Vector>>
ode_solution_t< Vector > solve_heun (OdeFunction f, const Vector &x0, real t0, real tf, real stepsize=0.0001)
 Integrate an ordinary differential equation over a certain domain with the given initial conditions using Heun's method. More...
 
template<typename Vector , typename OdeFunction = ode_function<Vector>>
ode_solution_t< Vector > solve_rk2 (OdeFunction f, const Vector &x0, real t0, real tf, real stepsize=0.0001)
 Integrate an ordinary differential equation over a certain domain with the given initial conditions using Runge-Kutta's method of 2nd order. More...
 
template<typename Vector , typename OdeFunction = ode_function<Vector>>
ode_solution_t< Vector > solve_rk4 (OdeFunction f, const Vector &x0, real t0, real tf, real stepsize=0.01)
 Integrate an ordinary differential equation over a certain domain with the given initial conditions using Runge-Kutta's method of 4th order. More...
 
template<typename Vector , typename OdeFunction = ode_function<Vector>>
ode_solution_t< Vector > solve_k38 (OdeFunction f, const Vector &x0, real t0, real tf, real stepsize=0.0001)
 Integrate an ordinary differential equation over a certain domain with the given initial conditions using Kutta's 3/8 rule method. More...
 

Detailed Description

Numerical methods for ordinary differential equations.

Function Documentation

◆ solve_euler()

template<typename Vector , typename OdeFunction = ode_function<Vector>>
ode_solution_t<Vector> theoretica::ode::solve_euler ( OdeFunction  f,
const Vector &  x0,
real  t0,
real  tf,
real  stepsize = 0.0001 
)
inline

Integrate an ordinary differential equation over a certain domain with the given initial conditions using Euler's method.

Parameters
fA function representing the system of differential equations, following the signature of ode_function.
x0The initial value of the variables
t0The starting value of the time variable
tfThe final value of the time variable
stepsizeThe constant step size
Returns
The numerical solution of the equation, as an ode_solution_t structure, holding a vector t of time values and a vector x of the variables.

◆ solve_fixstep()

template<typename Vector , typename OdeFunction = ode_function<Vector>, typename StepFunction = std::function<Vector(OdeFunction, real, const Vector&)>>
ode_solution_t<Vector> theoretica::ode::solve_fixstep ( OdeFunction  f,
const Vector &  x0,
real  t0,
real  tf,
StepFunction  step,
real  stepsize = 0.001 
)
inline

Integrate an ordinary differential equation using any numerical algorithm with a constant step size, such as Runge-Kutta methods.

This function does not use a specific method but uses the step argument function to iterate each step of an arbitrary fixed step algorithm. If the step size does not exactly cover the interval of integration, the last step is shortened.

Parameters
fA function representing the system of differential equations, following the signature of ode_function.
x0The initial value of the variables
t0The starting value of the time variable
tfThe final value of the time variable
stepA function which integrates numerically the differential equation between \(t\) and \(t + h\), such as the functions named ode::step_*
stepsizeThe constant step size
Returns
The numerical solution of the equation, as an ode_solution_t structure, holding a vector t of time values and a vector x of the variables.

◆ solve_heun()

template<typename Vector , typename OdeFunction = ode_function<Vector>>
ode_solution_t<Vector> theoretica::ode::solve_heun ( OdeFunction  f,
const Vector &  x0,
real  t0,
real  tf,
real  stepsize = 0.0001 
)
inline

Integrate an ordinary differential equation over a certain domain with the given initial conditions using Heun's method.

Parameters
fA function representing the system of differential equations, following the signature of ode_function.
x0The initial value of the variables
t0The starting value of the time variable
tfThe final value of the time variable
stepsizeThe constant step size
Returns
The numerical solution of the equation, as an ode_solution_t structure, holding a vector t of time values and a vector x of the variables.

◆ solve_k38()

template<typename Vector , typename OdeFunction = ode_function<Vector>>
ode_solution_t<Vector> theoretica::ode::solve_k38 ( OdeFunction  f,
const Vector &  x0,
real  t0,
real  tf,
real  stepsize = 0.0001 
)
inline

Integrate an ordinary differential equation over a certain domain with the given initial conditions using Kutta's 3/8 rule method.

Parameters
fA function representing the system of differential equations, following the signature of ode_function.
x0The initial value of the variables
t0The starting value of the time variable
tfThe final value of the time variable
stepsizeThe constant step size
Returns
The numerical solution of the equation, as an ode_solution_t structure, holding a vector t of time values and a vector x of the variables.

◆ solve_midpoint()

template<typename Vector , typename OdeFunction = ode_function<Vector>>
ode_solution_t<Vector> theoretica::ode::solve_midpoint ( OdeFunction  f,
const Vector &  x0,
real  t0,
real  tf,
real  stepsize = 0.0001 
)
inline

Integrate an ordinary differential equation over a certain domain with the given initial conditions using the midpoint method.

Parameters
fA function representing the system of differential equations, following the signature of ode_function.
x0The initial value of the variables
t0The starting value of the time variable
tfThe final value of the time variable
stepsizeThe constant step size
Returns
The numerical solution of the equation, as an ode_solution_t structure, holding a vector t of time values and a vector x of the variables.

◆ solve_rk2()

template<typename Vector , typename OdeFunction = ode_function<Vector>>
ode_solution_t<Vector> theoretica::ode::solve_rk2 ( OdeFunction  f,
const Vector &  x0,
real  t0,
real  tf,
real  stepsize = 0.0001 
)
inline

Integrate an ordinary differential equation over a certain domain with the given initial conditions using Runge-Kutta's method of 2nd order.

Parameters
fA function representing the system of differential equations, following the signature of ode_function.
x0The initial value of the variables
t0The starting value of the time variable
tfThe final value of the time variable
stepsizeThe constant step size
Returns
The numerical solution of the equation, as an ode_solution_t structure, holding a vector t of time values and a vector x of the variables.

◆ solve_rk4()

template<typename Vector , typename OdeFunction = ode_function<Vector>>
ode_solution_t<Vector> theoretica::ode::solve_rk4 ( OdeFunction  f,
const Vector &  x0,
real  t0,
real  tf,
real  stepsize = 0.01 
)
inline

Integrate an ordinary differential equation over a certain domain with the given initial conditions using Runge-Kutta's method of 4th order.

Parameters
fA function representing the system of differential equations, following the signature of ode_function.
x0The initial value of the variables
t0The starting value of the time variable
tfThe final value of the time variable
stepsizeThe constant step size
Returns
The numerical solution of the equation, as an ode_solution_t structure, holding a vector t of time values and a vector x of the variables.

◆ step_adams2()

template<typename Vector , typename OdeFunction = ode_function<Vector>>
Vector theoretica::ode::step_adams2 ( OdeFunction  f,
const Vector &  x0,
real  t0,
const Vector &  x1,
real  t1,
real  h = 0.001 
)
inline

Compute one step of the Adams-Bashforth linear multistep method of 2nd order for ordinary differential equations.

This function is used in solvers to solve an ODE over a certain domain.

Parameters
fA function representing the system of differential equations, following the signature of ode_function.
xThe starting vector of variables
tThe starting value of the time (independent variable)
hThe step size
Returns
The resulting vector of variables

◆ step_adams3()

template<typename Vector , typename OdeFunction = ode_function<Vector>>
Vector theoretica::ode::step_adams3 ( OdeFunction  f,
const Vector &  x0,
real  t0,
const Vector &  x1,
real  t1,
const Vector &  x2,
real  t2,
real  h = 0.001 
)
inline

Compute one step of the Adams-Bashforth linear multistep method of 3rd order for ordinary differential equations.

This function is used in solvers to solve an ODE over a certain domain.

Parameters
fA function representing the system of differential equations, following the signature of ode_function.
xThe starting vector of variables
tThe starting value of the time (independent variable)
hThe step size
Returns
The resulting vector of variables

◆ step_euler()

template<typename Vector , typename OdeFunction = ode_function<Vector>>
Vector theoretica::ode::step_euler ( OdeFunction  f,
const Vector &  x,
real  t,
real  h = 0.0001 
)
inline

Compute one step of Euler's method for ordinary differential equations.

This function is used in solvers to solve an ODE over a certain domain.

Parameters
fA function representing the system of differential equations, following the signature of ode_function.
xThe starting vector of variables
tThe starting value of the time (independent variable)
hThe step size
Returns
The resulting vector of variables

◆ step_heun()

template<typename Vector , typename OdeFunction = ode_function<Vector>>
Vector theoretica::ode::step_heun ( OdeFunction  f,
const Vector &  x,
real  t,
real  h = 0.001 
)
inline

Compute one step of Heun's method for ordinary differential equations.

This function is used in solvers to solve an ODE over a certain domain.

Parameters
fA function representing the system of differential equations, following the signature of ode_function.
xThe starting vector of variables
tThe starting value of the time (independent variable)
hThe step size
Returns
The resulting vector of variables

◆ step_k38()

template<typename Vector , typename OdeFunction = ode_function<Vector>>
Vector theoretica::ode::step_k38 ( OdeFunction  f,
const Vector &  x,
real  t,
real  h = 0.001 
)
inline

Compute one step of Kutta's 3/8 rule method for ordinary differential equations.

This function is used in solvers to solve an ODE over a certain domain.

Parameters
fA function representing the system of differential equations, following the signature of ode_function.
xThe starting vector of variables
tThe starting value of the time (independent variable)
hThe step size
Returns
The resulting vector of variables

◆ step_midpoint()

template<typename Vector , typename OdeFunction = ode_function<Vector>>
Vector theoretica::ode::step_midpoint ( OdeFunction  f,
const Vector &  x,
real  t,
real  h = 0.0001 
)
inline

Compute one step of the midpoint method for ordinary differential equations.

This function is used in solvers to solve an ODE over a certain domain.

Parameters
fA function representing the system of differential equations, following the signature of ode_function.
xThe starting vector of variables
tThe starting value of the time (independent variable)
hThe step size
Returns
The resulting vector of variables

◆ step_rk2()

template<typename Vector , typename OdeFunction = ode_function<Vector>>
Vector theoretica::ode::step_rk2 ( OdeFunction  f,
const Vector &  x,
real  t,
real  h = 0.001 
)
inline

Compute one step of the Runge-Kutta method of 2nd order for ordinary differential equations.

This function is used in solvers to solve an ODE over a certain domain.

Parameters
fA function representing the system of differential equations, following the signature of ode_function.
xThe starting vector of variables
tThe starting value of the time (independent variable)
hThe step size
Returns
The resulting vector of variables

◆ step_rk4()

template<typename Vector , typename OdeFunction = ode_function<Vector>>
Vector theoretica::ode::step_rk4 ( OdeFunction  f,
const Vector &  x,
real  t,
real  h = 0.01 
)
inline

Compute one step of the Runge-Kutta method of 4th order for ordinary differential equations.

This function is used in solvers to solve an ODE over a certain domain.

Parameters
fA function representing the system of differential equations, following the signature of ode_function.
xThe starting vector of variables
tThe starting value of the time (independent variable)
hThe step size
Returns
The resulting vector of variables