pub struct Solver<T>where
T: Number,{ /* private fields */ }
Expand description
§Default values
When creating a new Solver
with Solver::new()
, this is the default
configuration:
-
method:
Method::RK4
-
weights for the intermediate points:
Method::RK2
:vec![1, 1],
Method::RK4
:vec![1, 2, 2, 1],
(Note that each internal value of the vector will be converted to T
via
T::from_str_radix().)
§Example
use ode::{Method, Solver};
let time_interval: [f32; 2] = [0., 100.];
let ini_cond: Vec<f32> = vec![0.];
// simple config
Solver::new(&time_interval, &ini_cond)
.method(Method::RK4)
.solve(|t: &f32, _: &Vec<f32>| vec![2.*t]);
// complex config
let mut s = Solver::new(&time_interval, &ini_cond);
s.method(Method::RK4);
// run the solver
let (times, pos) = s.solve(|t: &f32, _: &Vec<f32>| vec![2.*t]);
Implementations§
Source§impl<T> Solver<T>where
T: Number,
impl<T> Solver<T>where
T: Number,
Sourcepub fn new(time_interval: &[T; 2], initial_conditions: &Vec<T>) -> Solver<T>
pub fn new(time_interval: &[T; 2], initial_conditions: &Vec<T>) -> Solver<T>
Start building a new Solver.
Default values are:
- method:
Method::RK4
, - intermidiate point weights:
vec![1, 2, 2, 1]
- step size:
10e-3
(Note that these values will be converted to T
via T::from_str_radix()
.)
Sourcepub fn method(&mut self, new_method: Method) -> &mut Solver<T>
pub fn method(&mut self, new_method: Method) -> &mut Solver<T>
Select the desired algorithm to solve the givem problem, also updating the
weights based on default values. To manually alter these values, please
check Self::change_weight()
.
Sourcepub fn weights(&mut self, new_weights: Vec<T>) -> &mut Solver<T>
pub fn weights(&mut self, new_weights: Vec<T>) -> &mut Solver<T>
Modify the default weighting applyed to each intermidiate point.
Sourcepub fn validate(&self) -> bool
pub fn validate(&self) -> bool
Validates the data passed to the solver.
This is tipically called by run()
before attempting to solve the passed
function, but was made public so the data can be verified and corrected
without a panic.
Data checks are:
-
Self::weights.len()
should match the selected method:Method::RK2
requires 2 weights;Method::RK4
requires 4 weights;
Sourcepub fn solve<F>(&self, function: F) -> (Vec<T>, Vec<Vec<T>>)where
F: Function<T>,
pub fn solve<F>(&self, function: F) -> (Vec<T>, Vec<Vec<T>>)where
F: Function<T>,
Check and run the solver, returning the results of the calculation.
Notice that, before the solver actually runs, it validates its data by
calling Self::validate()
within an assert!
. See that function for more
details.