[−][src]Function bacon_sci::roots::secant
pub fn secant<N: ComplexField, S: DimName, F: FnMut(&[N]) -> VectorN<N, S>>(
initial: (&[N], &[N]),
mut f: F,
tol: <N as ComplexField>::RealField,
n_max: usize
) -> Result<VectorN<N, S>, String> where
DefaultAllocator: Allocator<N, S>,
Use secant method to find a root of a vector function.
Using a vector function and its derivative, find a root based on two initial guesses using secant method.
Returns
Ok(vec)
on success, where vec
is a vector input for which the function is
zero. Err
on failure.
Params
initial
Initial guesses of the root. Should be near actual root. Slice since this
function finds roots of vector functions.
f
Vector function for which to find the root
tol
tolerance for error between iterations of Newton's method
n_max
Maximum number of iterations
Examples
use nalgebra::{VectorN, U1}; use bacon_sci::roots::secant; fn cubic(x: &[f64]) -> VectorN<f64, U1> { VectorN::<f64, U1>::from_iterator(x.iter().map(|x| x.powi(3))) } //... fn example() { let solution = secant((&[0.1], &[-0.1]), cubic, 0.001, 1000).unwrap(); }