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

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

Solves an ODE using Euler’s method.

https://en.wikipedia.org/wiki/Euler_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::{ExplicitEuler, FixedStepper, 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();
    }
}

// We instantiate Euler's algorithm with a step size of 0.001
let solver: FixedStepper<f64> = FixedStepper::new(0.001);

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

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

Trait Implementations

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

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

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

fn default() -> ExplicitEuler<T>[src]

Creates a Euler instance

Auto Trait Implementations

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

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

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

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

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