[][src]Function bacon_sci::roots::steffensen

pub fn steffensen<N: RealField + From<f64> + Copy>(
    initial: N,
    f: fn(_: N) -> N,
    tol: N,
    n_max: usize
) -> Result<N, String>

Use steffenson's method to find a fixed point

Use steffenson's method to find a value x so that f(x) = x, given a starting point.

Returns

Ok(x) so that f(x) - x < tol on success, Err on failure

Params

initial inital guess for the fixed point

f Function to find the fixed point of

tol Tolerance from 0 to try and achieve

n_max maximum number of iterations

Examples

use bacon_sci::roots::steffensen;
fn cosine(x: f64) -> f64 {
  x.cos()
}
//...
fn example() -> Result<(), String> {
  let solution = steffensen(0.5f64, cosine, 0.0001, 1000)?;
  Ok(())
}