Namespace Polynomial

namespace khivapolynomial

Functions

af::array khiva::polynomialpolyfit(af::array x, af::array y, int deg)

Least squares polynomial fit. Fit a polynomial \(p(x) = p[0] * x^{deg} + ... + p[deg]\) of degree \(deg\) to points \((x, y)\). Returns a vector of coefficients \(p\) that minimizes the squared error.

Return
af::array Polynomial coefficients, highest power first.
Parameters
  • x: x-coordinates of the M sample points \((x[i], y[i])\).
  • y: y-coordinates of the sample points.
  • deg: Degree of the fitting polynomial.

af::array khiva::polynomialroots(af::array pp)

Calculates the roots of a polynomial with coefficients given in \(p\). The values in the rank-1 array \(p\) are coefficients of a polynomial. If the length of \(p\) is \(n+1\) then the polynomial is described by:

\[ p[0] * x^n + p[1] * x^{n-1} + ... + p[n-1] * x + p[n] \]
.

Return
af::array Containing the roots of the polynomial.
Parameters
  • pp: Array of polynomial coefficients.