pub struct Euler<N, const S: usize>where
N: ComplexField,{ /* private fields */ }Expand description
Euler solver for an IVP.
Solves an initial value problem using Euler’s method.
Examples
use nalgebra::SVector;
use bacon_sci::ivp::{Euler, IVPSolver};
fn derivative(_t: f64, state: &[f64], _p: &mut ()) -> Result<SVector<f64, 1>, String> {
Ok(SVector::<f64, 1>::from_column_slice(state))
}
fn example() -> Result<(), String> {
let solver = Euler::new()
.with_dt_max(0.001)?
.with_initial_conditions(&[1.0])?
.with_start(0.0)?
.with_end(1.0)?
.build();
let path = solver.solve_ivp(derivative, &mut ())?;
for (time, state) in &path {
assert!((time.exp() - state.column(0)[0]).abs() <= 0.001);
}
Ok(())
}Implementations§
Trait Implementations§
source§impl<N, const S: usize> Clone for Euler<N, S>where
N: ComplexField + Clone,
N::RealField: Clone,
impl<N, const S: usize> Clone for Euler<N, S>where N: ComplexField + Clone, N::RealField: Clone,
source§impl<N, const S: usize> Debug for Euler<N, S>where
N: ComplexField + Debug,
N::RealField: Debug,
impl<N, const S: usize> Debug for Euler<N, S>where N: ComplexField + Debug, N::RealField: Debug,
source§impl<N, const S: usize> Default for Euler<N, S>where
N: ComplexField + Default,
N::RealField: Default,
impl<N, const S: usize> Default for Euler<N, S>where N: ComplexField + Default, N::RealField: Default,
source§impl<N, const S: usize> IVPSolver<N, S> for Euler<N, S>where
N: ComplexField + Copy,
<N as ComplexField>::RealField: Copy,
impl<N, const S: usize> IVPSolver<N, S> for Euler<N, S>where N: ComplexField + Copy, <N as ComplexField>::RealField: Copy,
source§fn step<T, F>(
&mut self,
f: F,
params: &mut T
) -> Result<IVPStatus<N, S>, String>where
T: Clone,
F: FnMut(N::RealField, &[N], &mut T) -> Result<SVector<N, S>, String>,
fn step<T, F>( &mut self, f: F, params: &mut T ) -> Result<IVPStatus<N, S>, String>where T: Clone, F: FnMut(N::RealField, &[N], &mut T) -> Result<SVector<N, S>, String>,
Step forward in the solver. Returns if the solver is finished, produced
an acceptable state, or needs to be redone.
source§fn with_tolerance(self, _tol: N::RealField) -> Result<Self, String>
fn with_tolerance(self, _tol: N::RealField) -> Result<Self, String>
Set the error tolerance for this solver.
source§fn with_dt_max(self, max: N::RealField) -> Result<Self, String>
fn with_dt_max(self, max: N::RealField) -> Result<Self, String>
Set the maximum time step for this solver.
source§fn with_dt_min(self, _min: N::RealField) -> Result<Self, String>
fn with_dt_min(self, _min: N::RealField) -> Result<Self, String>
Set the minimum time step for this solver.
source§fn with_start(self, t_initial: N::RealField) -> Result<Self, String>
fn with_start(self, t_initial: N::RealField) -> Result<Self, String>
Set the initial time for this solver.
source§fn with_end(self, t_final: N::RealField) -> Result<Self, String>
fn with_end(self, t_final: N::RealField) -> Result<Self, String>
Set the end time for this solver.
source§fn with_initial_conditions(self, start: &[N]) -> Result<Self, String>
fn with_initial_conditions(self, start: &[N]) -> Result<Self, String>
Set the initial conditions for this solver.
source§fn get_initial_conditions(&self) -> Option<SVector<N, S>>
fn get_initial_conditions(&self) -> Option<SVector<N, S>>
Return the initial conditions. Called once at the very start
of solving.
Auto Trait Implementations§
impl<N, const S: usize> RefUnwindSafe for Euler<N, S>where N: RefUnwindSafe, <N as ComplexField>::RealField: RefUnwindSafe,
impl<N, const S: usize> Send for Euler<N, S>
impl<N, const S: usize> Sync for Euler<N, S>
impl<N, const S: usize> Unpin for Euler<N, S>where N: Unpin, <N as ComplexField>::RealField: Unpin,
impl<N, const S: usize> UnwindSafe for Euler<N, S>where N: UnwindSafe, <N as ComplexField>::RealField: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.