pub struct RK23<N, const S: usize>where
N: ComplexField + FromPrimitive + Copy,
<N as ComplexField>::RealField: FromPrimitive + Copy,{ /* private fields */ }Expand description
Bogacki-Shampine method for solving an IVP.
Defines the Butch Tableaux for a 5(4) order adaptive runge-kutta method. Uses RKInfo to do the actual solving. Provides an interface for setting the conditions on RKInfo.
Examples
use nalgebra::SVector;
use bacon_sci::ivp::{RK23, RungeKuttaSolver};
fn derivatives(_t: f64, state: &[f64], _p: &mut ()) -> Result<SVector<f64, 1>, String> {
Ok(SVector::<f64, 1>::from_column_slice(state))
}
fn example() -> Result<(), String> {
let rk45 = RK23::new()
.with_dt_max(0.1)?
.with_dt_min(0.001)?
.with_start(0.0)?
.with_end(10.0)?
.with_tolerance(0.0001)?
.with_initial_conditions(&[1.0])?
.build();
let path = rk45.solve_ivp(derivatives, &mut ())?;
for (time, state) in &path {
assert!((time.exp() - state.column(0)[0]).abs() < 0.001);
}
Ok(())
}Implementations§
source§impl<N, const S: usize> RK23<N, S>where
N: ComplexField + FromPrimitive + Copy,
<N as ComplexField>::RealField: FromPrimitive + Copy,
impl<N, const S: usize> RK23<N, S>where N: ComplexField + FromPrimitive + Copy, <N as ComplexField>::RealField: FromPrimitive + Copy,
Trait Implementations§
source§impl<N, const S: usize> Clone for RK23<N, S>where
N: ComplexField + FromPrimitive + Copy + Clone,
<N as ComplexField>::RealField: FromPrimitive + Copy,
impl<N, const S: usize> Clone for RK23<N, S>where N: ComplexField + FromPrimitive + Copy + Clone, <N as ComplexField>::RealField: FromPrimitive + Copy,
source§impl<N, const S: usize> Debug for RK23<N, S>where
N: ComplexField + FromPrimitive + Copy + Debug,
<N as ComplexField>::RealField: FromPrimitive + Copy,
impl<N, const S: usize> Debug for RK23<N, S>where N: ComplexField + FromPrimitive + Copy + Debug, <N as ComplexField>::RealField: FromPrimitive + Copy,
source§impl<N, const S: usize> Default for RK23<N, S>where
N: ComplexField + FromPrimitive + Copy,
<N as ComplexField>::RealField: FromPrimitive + Copy,
impl<N, const S: usize> Default for RK23<N, S>where N: ComplexField + FromPrimitive + Copy, <N as ComplexField>::RealField: FromPrimitive + Copy,
source§impl<N, const S: usize> From<RK23<N, S>> for RKInfo<N, S, 4>where
N: ComplexField + FromPrimitive + Copy,
<N as ComplexField>::RealField: FromPrimitive + Copy,
impl<N, const S: usize> From<RK23<N, S>> for RKInfo<N, S, 4>where N: ComplexField + FromPrimitive + Copy, <N as ComplexField>::RealField: FromPrimitive + Copy,
source§impl<N, const S: usize> RungeKuttaSolver<N, S, 4> for RK23<N, S>where
N: ComplexField + FromPrimitive + Copy,
<N as ComplexField>::RealField: FromPrimitive + Copy,
impl<N, const S: usize> RungeKuttaSolver<N, S, 4> for RK23<N, S>where N: ComplexField + FromPrimitive + Copy, <N as ComplexField>::RealField: FromPrimitive + Copy,
source§fn t_coefficients() -> SVector<N::RealField, 4>
fn t_coefficients() -> SVector<N::RealField, 4>
Returns a vec of coeffecients to multiply the time step by when getting
intermediate results. Upper-left portion of Butch Tableaux
source§fn k_coefficients() -> SMatrix<N::RealField, 4, 4>
fn k_coefficients() -> SMatrix<N::RealField, 4, 4>
Returns the coefficients to use on the k_i’s when finding another
k_i. Upper-right portion of the Butch Tableax. Should be
an NxN-1 matrix, where N is the order of the Runge-Kutta Method (Or order+1 for
adaptive methods)
source§fn avg_coefficients() -> SVector<N::RealField, 4>
fn avg_coefficients() -> SVector<N::RealField, 4>
Coefficients to use when calculating the final step to take.
These are the weights of the weighted average of k_i’s. Bottom
portion of the Butch Tableaux. For adaptive methods, this is the first
row of the bottom portion.
source§fn error_coefficients() -> SVector<N::RealField, 4>
fn error_coefficients() -> SVector<N::RealField, 4>
Coefficients to use on
the k_i’s to find the error between the two orders
of Runge-Kutta methods. In the Butch Tableaux, this is
the first row of the bottom portion minus the second row.
source§fn solve_ivp<T: Clone, F: FnMut(N::RealField, &[N], &mut T) -> Result<SVector<N, S>, String>>(
self,
f: F,
params: &mut T
) -> Result<Vec<(N::RealField, SVector<N, S>)>, String>
fn solve_ivp<T: Clone, F: FnMut(N::RealField, &[N], &mut T) -> Result<SVector<N, S>, String>>( self, f: F, params: &mut T ) -> Result<Vec<(N::RealField, SVector<N, S>)>, String>
Ideally, call RKInfo.solve_ivp
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.
Auto Trait Implementations§
impl<N, const S: usize> RefUnwindSafe for RK23<N, S>where N: RefUnwindSafe, <N as ComplexField>::RealField: RefUnwindSafe,
impl<N, const S: usize> Send for RK23<N, S>
impl<N, const S: usize> Sync for RK23<N, S>
impl<N, const S: usize> Unpin for RK23<N, S>where N: Unpin, <N as ComplexField>::RealField: Unpin,
impl<N, const S: usize> UnwindSafe for RK23<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.