[−][src]Function bacon_sci::roots::secant
pub fn secant<N: ComplexField>(
initial: (&[N], &[N]),
f: fn(_: &[N]) -> DVector<N>,
tol: <N as ComplexField>::RealField,
n_max: usize
) -> Result<DVector<N>, String>
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::DVector; use bacon_sci::roots::secant; fn cubic(x: &[f64]) -> DVector<f64> { DVector::from_iterator(x.len(), x.iter().map(|x| x.powi(3))) } //... fn example() { let solution = secant((&[0.1], &[-0.1]), cubic, 0.001, 1000).unwrap(); }