pub fn horner_eval(coeffs: &[f64], zval: f64) -> f64Expand description
The horner_eval function in Rust implements the Horner’s method for polynomial evaluation.
Arguments:
coeffs: A mutable slice of f64 values representing the coefficients of a polynomial. The coefficients are ordered from highest degree to lowest degree.degree: Thedegreeparameter represents the degree of the polynomial. In the given example, the polynomial has a degree of 8.zval: Thezvalparameter in thehorner_evalfunction represents the value at which the polynomial is evaluated. It is the value of the independent variable in the polynomial expression.
Returns:
The function horner_eval returns a f64 value, which is the result of evaluating the polynomial
with the given coefficients at the specified value zval.
§Examples:
use ginger::rootfinding::horner_eval;
use approx_eq::assert_approx_eq;
let coeffs = vec![10.0, 34.0, 75.0, 94.0, 150.0, 94.0, 75.0, 34.0, 10.0];
let px = horner_eval(&coeffs, 2.0);
assert_approx_eq!(px, 18250.0);
assert_approx_eq!(coeffs[3], 94.0);