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

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

Solves an ODE using backward Euler

https://en.wikipedia.org/wiki/Backward_Euler_method

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::{ImplicitEuler, ImplicitODE},
};

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

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

impl ImplicitODE<f64> for ImplicitODEExample
{
    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;
    }
}

// We instanciate Euler's backward algorithm with a stepsize of 0.001
let step_size: f64 = 0.0001;
let solver: ImplicitEuler<f64> = ImplicitEuler::new(step_size);

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

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

Implementations

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

pub fn new(step_size: T) -> ImplicitEuler<T>[src]

Creates a backward Euler instance

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

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

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

Trait Implementations

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

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

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

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

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

Auto Trait Implementations

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

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

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

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

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