Skip to main content

polyvander

Function polyvander 

Source
pub fn polyvander<T>(x: &Array<T>, deg: usize) -> Result<Array<T>>
where T: Clone + Zero + One + Mul<Output = T>,
Expand description

Generate a Vandermonde matrix

Returns the Vandermonde matrix for the given polynomial degree. The Vandermonde matrix has columns [1, x, x^2, …, x^deg] where x is the input array.

§Parameters

  • x - Array of points
  • deg - Maximum degree of the polynomial (inclusive)

§Returns

Vandermonde matrix of shape (len(x), deg+1)

§Examples

use numrs2::prelude::*;
use numrs2::new_modules::polynomial::polyvander;

let x = Array::from_vec(vec![1.0, 2.0, 3.0]);
let v = polyvander(&x, 2).expect("valid 1D input array");
// Returns [[1, 1, 1], [1, 2, 4], [1, 3, 9]]