[−][src]Function bacon_sci::roots::newton_polynomial
pub fn newton_polynomial<N: ComplexField>(
initial: N,
poly: &Polynomial<N>,
tol: <N as ComplexField>::RealField,
n_max: usize
) -> Result<N, String>
Use Newton's method on a polynomial.
Given an initial guess of a polynomial root, use Newton's method to approximate within tol.
Returns
Ok(root)
when a root has been found, Err
on failure
Params
initial
initial estimate of the root
poly
the polynomial to solve the root for
tol
The tolerance of relative error between iterations
n_max
the maximum number of iterations
Examples
use bacon_sci::polynomial::Polynomial; use bacon_sci::roots::newton_polynomial; fn example() { let mut polynomial = Polynomial::new(); polynomial.set_coefficient(2, 1.0); polynomial.set_coefficient(0, -1.0); let solution = newton_polynomial(0.5, &polynomial, 0.0001, 1000).unwrap(); }