pub struct Solution<T: OdeState> {
pub t: Vec<f64>,
pub y: Vec<T>,
}Expand description
Solution of an ordinary differential equation dy/dt = f(t,y).
Fields§
§t: Vec<f64>Time vector (length-N).
This vector stores each sample time.
y: Vec<T>State history vector (length-N).
This vector stores the ODE solution (i.e. the state vector) corresponding to each sample
time in t.
Implementations§
Source§impl<T: OdeState> Solution<T>
impl<T: OdeState> Solution<T>
Sourcepub fn get_state_variable<V: Vector<f64>>(&self, index: &StateIndex) -> V
pub fn get_state_variable<V: Vector<f64>>(&self, index: &StateIndex) -> V
Get the time history of the state variable at the specified index.
§Type Parameters
V- The type of vector to use to store the time history of the requested state variable. This type must implement theVectortrait.
§Arguments
index- Index of the state variable (using 0-based indexing).
§Returns
Time history of the state variable.
§Examples
§Vector-valued
use numint::{solve_ivp, Euler, StateIndex};
let f = |t: f64, y: &Vec<f64>| { vec![y[1], -2.5 * y[1] - 0.5 * y[0] + 0.5 * t.sin()] };
let y0 = vec![1.0, 0.0];
let t0 = 0.0;
let tf = 1.0;
let h = 0.1;
let sol = solve_ivp::<Vec<f64>, Euler>(&f, t0, &y0, tf, h);
// Get the time history of the y₁, where y = (y₀,y₁)ᵀ.
let idx = StateIndex::Vector(1);
let y1 = sol.get_state_variable::<Vec<f64>>(&idx);§Matrix-valued
use nalgebra::SMatrix;
use numint::{solve_ivp, Euler, StateIndex};
// Solve a simple initial value problem.
let f = |t: f64, y: &SMatrix<f64, 2, 2>| {
SMatrix::<f64, 2, 2>::from_row_slice(&[
y[(0, 1)],
-2.5 * y[(0, 1)] - 0.5 * y[(0, 0)] + 0.5 * t.sin(),
y[(1, 0)],
0.5 * y[(1, 1)],
])
};
let y0 = SMatrix::<f64, 2, 2>::from_row_slice(&[1.0, 0.0, 1.0, 1.0]);
let t0 = 0.0;
let tf = 1.0;
let h = 0.1;
let sol = solve_ivp::<SMatrix<f64, 2, 2>, Euler>(&f, t0, &y0, tf, h);
// Get the time history of y₁₀, where y = ((y₀₀,y₀₁), (y₁₀,y₁₁)).
let idx = StateIndex::Matrix(1, 0);
let y10 = sol.get_state_variable::<Vec<f64>>(&idx);§Scalar-valued
use numint::{solve_ivp, Euler, StateIndex};
// Solve a simple initial value problem.
let f = |_t: f64, y: &f64| *y;
let y0 = 1.0;
let t0 = 0.0;
let tf = 3.0;
let h = 1.0;
let sol = solve_ivp::<f64, Euler>(&f, t0, &y0, tf, h);
// Get the time history of the only state variable.
let idx = StateIndex::Scalar();
let y = sol.get_state_variable::<Vec<f64>>(&idx);Auto Trait Implementations§
impl<T> Freeze for Solution<T>
impl<T> RefUnwindSafe for Solution<T>where
T: RefUnwindSafe,
impl<T> Send for Solution<T>where
T: Send,
impl<T> Sync for Solution<T>where
T: Sync,
impl<T> Unpin for Solution<T>where
T: Unpin,
impl<T> UnwindSafe for Solution<T>where
T: 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
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§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 moreSource§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).Source§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.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.