numint

Struct Solution

Source
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>

Source

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 the Vector trait.
§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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.