horner

Function horner 

Source
pub fn horner(
    coeffs: &mut [f64],
    degree: usize,
    vr: &Vector2<f64>,
) -> Vector2<f64>
Expand description

The horner function implements Horner’s evaluation for Bairstow’s method in Rust.

Arguments:

  • coeffs: A mutable slice of f64 values representing the coefficients of the polynomial. The coefficients are in descending order of degree.
  • degree: The degree parameter represents the degree of the polynomial. It is used to determine the number of coefficients in the coeffs array.
  • vr: The parameter vr is a Vec2 struct that contains two values, x_ and y_. In the example, vr is initialized with the values -1.0 and -2.0.

Returns:

The function horner returns a Vec2 struct, which contains two f64 values representing the results of the Horner evaluation.

§Examples:

use ginger::rootfinding::horner;
use ginger::vector2::Vector2;
use approx_eq::assert_approx_eq;

let mut coeffs = vec![10.0, 34.0, 75.0, 94.0, 150.0, 94.0, 75.0, 34.0, 10.0];
let px = horner(&mut coeffs, 8, &Vector2::new(-1.0, -2.0));

assert_approx_eq!(px.x_, 114.0);
assert_approx_eq!(px.y_, 134.0);
assert_approx_eq!(coeffs[3], 15.0);