Trait peroxide::numerical::ode::ODEProblem

source ·
pub trait ODEProblem {
    // Required methods
    fn initial_conditions(&self) -> Vec<f64>;
    fn rhs(&self, t: f64, y: &[f64], dy: &mut [f64]) -> Result<()>;
}
Expand description

Trait for defining an ODE problem.

Implement this trait to define your own ODE problem.

§Example

use peroxide::fuga::*;

struct MyODEProblem;

impl ODEProblem for MyODEProblem {
    fn initial_conditions(&self) -> Vec<f64> {
        vec![1.0, 2.0]
    }

    fn rhs(&self, t: f64, y: &[f64], dy: &mut [f64]) -> anyhow::Result<()> {
        dy[0] = -0.5 * y[0];
        dy[1] = y[0] - y[1];
        Ok(())
    }
}

Required Methods§

source

fn initial_conditions(&self) -> Vec<f64>

source

fn rhs(&self, t: f64, y: &[f64], dy: &mut [f64]) -> Result<()>

Implementors§