[][src]Struct mathru::analysis::differential_equation::ordinary::DormandPrince54

pub struct DormandPrince54<T> { /* fields omitted */ }

Solves an ODE using the 5th order Runge-Kutta-Dormand-Prince algorithm.

https://en.wikipedia.org/wiki/Dormand-Prince_method

Example

For this example, we want to solve the following ordinary differiential equation:

\frac{dy}{dt} = ay = f(t, y)

The inial condition is $y(0) = 0.5$ and we solve it in the interval $\lbrack 0, 2\rbrack$ The following equation is the closed solution for this ODE:

y(t) = C a e^{at}

$C$ is a parameter and depends on the initial condition $y(t_{0})$

C = \frac{y(t_{0})}{ae^{at_{0}}}

In this example, we set $a=2$

use mathru::{
    algebra::linear::Vector,
    analysis::differential_equation::ordinary::{DormandPrince54, ExplicitODE},
};

pub struct ExplicitODE1
{
    time_span: (f64, f64),
    init_cond: Vector<f64>,
}

impl Default for ExplicitODE1
{
    fn default() -> ExplicitODE1
    {
        ExplicitODE1 { time_span: (0.0, 2.0),
                       init_cond: vector![0.5] }
    }
}

impl ExplicitODE<f64> for ExplicitODE1
{
    fn func(self: &Self, _t: &f64, x: &Vector<f64>) -> Vector<f64>
    {
        return x * &2.0f64;
    }

    fn time_span(self: &Self) -> (f64, f64)
    {
        return self.time_span;
    }

    fn init_cond(self: &Self) -> Vector<f64>
    {
        return self.init_cond.clone();
    }
}

let h_0: f64 = 0.001;
let n_max: u32 = 500;
let abs_tol: f64 = 0.00000001;

let solver: DormandPrince54<f64> = DormandPrince54::new(abs_tol, h_0, n_max);

let problem: ExplicitODE1 = ExplicitODE1::default();

// Solve the ODE
let (t, y): (Vec<f64>, Vec<Vector<f64>>) = solver.solve(&problem).unwrap();

Implementations

impl<T> DormandPrince54<T> where
    T: Real
[src]

pub fn new(abs_tol: T, begin_step_size: T, n_max: u32) -> DormandPrince54<T>[src]

Creates a DormandPrince54 instance, also known as explicit Runge-Kutta method of order 5(4) with step-size control

pub fn get_begin_step_size(&self) -> &T[src]

pub fn set_begin_step_size(&mut self, step_size: T)[src]

pub fn solve<F>(
    &self,
    prob: &F
) -> Result<(Vec<T>, Vec<Vector<T>>), &'static str> where
    F: ExplicitODE<T>, 
[src]

Solve ordinary differential equation

Arguments

  • 'self'
  • 'prob': explicit ordinary differntial equation with initial condition, which is solved

pub fn calc_error(&self, y: &Vector<T>, y_hat: &Vector<T>) -> T[src]

\lvert \lvert y - \hat{y} \rvert \rvert_{\infty}

Auto Trait Implementations

impl<T> RefUnwindSafe for DormandPrince54<T> where
    T: RefUnwindSafe

impl<T> Send for DormandPrince54<T> where
    T: Send

impl<T> Sync for DormandPrince54<T> where
    T: Sync

impl<T> Unpin for DormandPrince54<T> where
    T: Unpin

impl<T> UnwindSafe for DormandPrince54<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,