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

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

Backward differentitation formula

Example

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

0 = -4(y(t) -2) - y(t)^{'} = f(t, y, y^{'})

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

y(t) = 2 - e^{-t}
use mathru::{
    algebra::linear::{Matrix, Vector},
    analysis::differential_equation::ordinary::{BDF, ImplicitODE},
};

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

impl Default for ODEProblem
{
    fn default() -> ODEProblem
    {
        return ODEProblem { time_span: (0.0, 2.0), init_cond: vector![1.0] };
    }
}

impl ImplicitODE<f64> for ODEProblem
{
    fn func(self: &Self, _t: f64, x: &Vector<f64>) -> Vector<f64>
    {
        let result = (x * &-4.0) + 8.0;
        return result;
    }

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

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

    fn jacobian(self: &Self, _t: f64, _input: &Vector<f64>) -> Matrix<f64>
    {
        let jacobian = matrix![-4.0];
        return jacobian;
    }
}

let step_size: f64 = 0.0001;
let solver: BDF<f64> = BDF::new(2, step_size);

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

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

Implementations

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

pub fn new(k: u8, step_size: T) -> BDF<T>[src]

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

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

Solves func using BDF method.

Arguments

  • 'func' is an explict oridnary diffential equation
  • 'init' is the initial value at the time 't_start'
  • 't_span' Time span

Return

The solver returns a vector and a matrix, containing the times used in each step of the algorithm and the respectful values for that time.

Panic

if t_span.0 > t_span.1

Trait Implementations

impl<T: Clone> Clone for BDF<T>[src]

impl<T: Copy> Copy for BDF<T>[src]

impl<T: Debug> Debug for BDF<T>[src]

impl<'de, T> Deserialize<'de> for BDF<T> where
    T: Deserialize<'de>, 
[src]

impl<T> Serialize for BDF<T> where
    T: Serialize
[src]

Auto Trait Implementations

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

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

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

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

impl<T> UnwindSafe for BDF<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> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

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

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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>,