[−][src]Struct mathru::analysis::differential_equation::ordinary::Heun
Solves an ODE using Heun's method.
https://en.wikipedia.org/wiki/Heun's_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::{ExplicitODE, Heun}, }; 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 instanciate Heuns algorithm with a stepsize of 0.001 let step_size: f64 = 0.001; let solver: Heun<f64> = Heun::new(step_size); let problem: ExplicitODE1 = ExplicitODE1::default(); // Solve the ODE let (t, y): (Vec<f64>, Vec<Vector<f64>>) = solver.solve(&problem).unwrap();
Implementations
impl<T> Heun<T> where
T: Real,
[src]
T: Real,
pub fn new(step_size: T) -> Heun<T>
[src]
Creates a Heun instance with step size 'step_size'
pub fn solve<F>(&self, prob: &F) -> Result<(Vec<T>, Vec<Vector<T>>), ()> where
F: ExplicitODE<T>,
[src]
F: ExplicitODE<T>,
pub fn get_step_size(&self) -> &T
[src]
pub fn set_step_size(&mut self, step_size: T)
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Heun<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Heun<T> where
T: Send,
T: Send,
impl<T> Sync for Heun<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Heun<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Heun<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,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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.
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.
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>,