muller_polynomial

Function muller_polynomial 

Source
pub fn muller_polynomial<N: ComplexField + FromPrimitive + Copy>(
    initial: (N, N, N),
    poly: &Polynomial<N>,
    tol: <N as ComplexField>::RealField,
    n_max: usize,
) -> Result<Complex<<N as ComplexField>::RealField>, String>
Expand description

Use Mueller’s method on a polynomial. Note this usually requires complex numbers.

Givin three initial guesses of a polynomial root, use Muller’s method to approximate within tol.

§Returns

Ok(root) when a root has been found, Err on failure

§Params

initial Triplet of initial guesses

poly the polynomial to solve the root for

tol the tolerance of relative error between iterations

n_max Maximum number of iterations

§Examples

use bacon_sci::polynomial::Polynomial;
use bacon_sci::roots::muller_polynomial;
fn example() {
  let mut polynomial = Polynomial::new();
  polynomial.set_coefficient(2, 1.0);
  polynomial.set_coefficient(0, -1.0);
  let solution = muller_polynomial((0.0, 1.5, 2.0), &polynomial, 0.0001, 1000).unwrap();
}