[−][src]Struct mathru::analysis::differential_equation::ordinary::ImplicitEuler
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]
T: Real,
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]
F: ImplicitODE<T>,
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]
pub fn clone(&self) -> ImplicitEuler<T>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[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]
T: Deserialize<'de>,
pub fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl<T> Serialize for ImplicitEuler<T> where
T: Serialize,
[src]
T: Serialize,
Auto Trait Implementations
impl<T> RefUnwindSafe for ImplicitEuler<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for ImplicitEuler<T> where
T: Send,
T: Send,
impl<T> Sync for ImplicitEuler<T> where
T: Sync,
T: Sync,
impl<T> Unpin for ImplicitEuler<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for ImplicitEuler<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,