[−][src]Struct mathru::analysis::differential_equation::ordinary::BDF
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]
T: Real,
impl<T> BDF<T> where
T: Real,
[src]
T: Real,
pub fn solve<F>(&self, prob: &F) -> Result<(Vec<T>, Vec<Vector<T>>), ()> where
F: ImplicitODE<T>,
[src]
F: ImplicitODE<T>,
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]
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 BDF<T> where
T: Serialize,
[src]
T: Serialize,
Auto Trait Implementations
impl<T> RefUnwindSafe for BDF<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for BDF<T> where
T: Send,
T: Send,
impl<T> Sync for BDF<T> where
T: Sync,
T: Sync,
impl<T> Unpin for BDF<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for BDF<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>,