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

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

Solves an ODE using the 4th order Runge-Kutta-Fehlberg algorithm.

order \mathcal{O}(h^4) with an error estimator of order \mathcal{O}(h^5)

https://en.wikipedia .org/wiki/Runge-Kutta-Fehlberg_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::{ExplicitODE, RungeKuttaFehlberg54},
};

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();
    }
}

// We instanciate CashKarp algorithm
let h_0: f64 = 0.0001;
let fac: f64 = 0.9;
let fac_min: f64 = 0.01;
let fac_max: f64 = 2.0;
let n_max: u32 = 100;
let abs_tol: f64 = 10e-6;
let rel_tol: f64 = 10e-3;

let solver: RungeKuttaFehlberg54<f64> =
    RungeKuttaFehlberg54::new(n_max, h_0, fac, fac_min, fac_max, abs_tol, rel_tol);

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

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

Implementations

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

pub fn new(
    n_max: u32,
    h_0: T,
    fac: T,
    fac_min: T,
    fac_max: T,
    abs_tol: T,
    rel_tol: T
) -> RungeKuttaFehlberg54<T>
[src]

Creates a Runge Kuttea Fehlberg 54 instance, also known as Runge-Kutta-Fehlberg

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

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

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

pub fn set_abs_tol(&mut self, abs_tol: T)[src]

pub fn set_rel_tol(&mut self, rel_tol: T)[src]

Trait Implementations

impl<T> Default for RungeKuttaFehlberg54<T> where
    T: Real
[src]

Auto Trait Implementations

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

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

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

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

impl<T> UnwindSafe for RungeKuttaFehlberg54<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>,