polyf

Variants: poly, polyc, polycf, polyf

Public Functions

float polyf_val(float * _p, unsigned int _k, float _x)
int polyf_fit(float * _x, float * _y, unsigned int _n, float * _p, unsigned int _k)
int polyf_fit_lagrange(float * _x, float * _y, unsigned int _n, float * _p)
float polyf_interp_lagrange(float * _x, float * _y, unsigned int _n, float _x0)
int polyf_fit_lagrange_barycentric(float * _x, unsigned int _n, float * _w)
float polyf_val_lagrange_barycentric(float * _x, float * _y, float * _w, float _x0, unsigned int _n)
int polyf_expandbinomial(unsigned int _n, float * _p)
int polyf_expandbinomial_pm(unsigned int _m, unsigned int _k, float * _p)
int polyf_expandroots(float * _r, unsigned int _n, float * _p)
int polyf_expandroots2(float * _a, float * _b, unsigned int _n, float * _p)
int polyf_findroots(float * _poly, unsigned int _n, float complex * _roots)
int polyf_findroots_durandkerner(float * _p, unsigned int _k, float complex * _roots)
int polyf_findroots_bairstow(float * _p, unsigned int _k, float complex * _roots)
int polyf_mul(float * _a, unsigned int _order_a, float * _b, unsigned int _order_b, float * _c)

Interfaces

float polyf_val(float * _p, unsigned int _k, float _x)

Evaluate polynomial _p at value _x

  • _p : polynomial coefficients, shape: (_k, 1)
  • _k : polynomial coefficients length
  • _x : input to evaluate polynomial

int polyf_fit(float * _x, float * _y, unsigned int _n, float * _p, unsigned int _k)

Perform least-squares polynomial fit on data set

  • _x : x-value sample set, shape: (_n, 1)
  • _y : y-value sample set, shape: (_n, 1)
  • _n : number of samples in _x and _y
  • _p : polynomial coefficients output, shape: (_k, 1)
  • _k : polynomial coefficients length

int polyf_fit_lagrange(float * _x, float * _y, unsigned int _n, float * _p)

Perform Lagrange polynomial exact fit on data set

  • _x : x-value sample set, size [_n x 1]
  • _y : y-value sample set, size [_n x 1]
  • _n : number of samples in _x and _y
  • _p : polynomial coefficients output, shape: (_n, 1)

float polyf_interp_lagrange(float * _x, float * _y, unsigned int _n, float _x0)

Perform Lagrange polynomial interpolation on data set without computing coefficients as an intermediate step.

  • _x : x-value sample set, shape: (_n, 1)
  • _y : y-value sample set, shape: (_n, 1)
  • _n : number of samples in _x and _y
  • _x0 : x-value to evaluate and compute interpolant

int polyf_fit_lagrange_barycentric(float * _x, unsigned int _n, float * _w)

Compute Lagrange polynomial fit in the barycentric form.

  • _x : x-value sample set, size [_n x 1]
  • _n : number of samples in _x
  • _w : barycentric weights normalized so _w [0]=1, size [_n x 1]

float polyf_val_lagrange_barycentric(float * _x, float * _y, float * _w, float _x0, unsigned int _n)

Perform Lagrange polynomial interpolation using the barycentric form of the weights.

  • _x : x-value sample set, shape: (_n, 1)
  • _y : y-value sample set, shape: (_n, 1)
  • _w : barycentric weights, shape: (_n, 1)
  • _x0 : x-value to evaluate and compute interpolant
  • _n : number of samples in _x, _y, and _w

int polyf_expandbinomial(unsigned int _n, float * _p)

Perform binomial expansion on the polynomial \( P_n(x) = (1+x)^n \) as \( P_n(x) = p[0] + p[1]x + p[2]x^2 + ... + p[n]x^n \) NOTE: _p has order n (coefficients has length n+1)

  • _n : polynomial order
  • _p : polynomial coefficients, shape: (_n+1, 1)

int polyf_expandbinomial_pm(unsigned int _m, unsigned int _k, float * _p)

Perform positive/negative binomial expansion on the polynomial \( P_n(x) = (1+x)^m (1-x)^k \) as \( P_n(x) = p[0] + p[1]x + p[2]x^2 + ... + p[n]x^n \) NOTE: _p has order n=m+k (array is length n+1)

  • _m : number of '1+x' terms
  • _k : number of '1-x' terms
  • _p : polynomial coefficients, shape: (_m+_k+1, 1)

int polyf_expandroots(float * _r, unsigned int _n, float * _p)

Perform root expansion on the polynomial \( P_n(x) = (x-r[0]) (x-r[1]) ... (x-r[n-1]) \) as \( P_n(x) = p[0] + p[1]x + ... + p[n]x^n \) where \( r[0],r[1],...,r[n-1]\) are the roots of \( P_n(x) \). NOTE: _p has order _n (array is length _n+1)

  • _r : roots of polynomial, shape: (_n, 1)
  • _n : number of roots in polynomial
  • _p : polynomial coefficients, shape: (_n+1, 1)

int polyf_expandroots2(float * _a, float * _b, unsigned int _n, float * _p)

Perform root expansion on the polynomial \( P_n(x) = (xb[0]-a[0]) (xb[1]-a[1])...(xb[n-1]-a[n-1]) \) as \( P_n(x) = p[0] + p[1]x + ... + p[n]x^n \) NOTE: _p has order _n (array is length _n+1)

  • _a : subtractant of polynomial rotos, shape: (_n, 1)
  • _b : multiplicant of polynomial roots, shape: (_n, 1)
  • _n : number of roots in polynomial
  • _p : polynomial coefficients, shape: (_n+1, 1)

int polyf_findroots(float * _poly, unsigned int _n, float complex * _roots)

Find the complex roots of a polynomial.

  • _poly :
  • _n :
  • _roots : resulting complex roots, shape: (_k-1, 1)

int polyf_findroots_durandkerner(float * _p, unsigned int _k, float complex * _roots)

Find the complex roots of the polynomial using the Durand-Kerner method

  • _p : polynomial coefficients, shape: (_n, 1)
  • _k : polynomial length
  • _roots : resulting complex roots, shape: (_k-1, 1)

int polyf_findroots_bairstow(float * _p, unsigned int _k, float complex * _roots)

Find the complex roots of the polynomial using Bairstow's method.

  • _p : polynomial coefficients, shape: (_n, 1)
  • _k : polynomial length
  • _roots : resulting complex roots, shape: (_k-1, 1)

int polyf_mul(float * _a, unsigned int _order_a, float * _b, unsigned int _order_b, float * _c)

Expand the multiplication of two polynomials \( ( a[0] + a[1]x + a[2]x^2 + ...) (b[0] + b[1]x + b[]x^2 + ...) \) as \( c[0] + c[1]x + c[2]x^2 + ... + c[n]x^n \) where order(c) = order(a) + order(b) + 1 and therefore length(c) = length(a) + length(b) - 1

  • _a : 1st polynomial coefficients (length is _order_a+1)
  • _order_a : 1st polynomial order
  • _b : 2nd polynomial coefficients (length is _order_b+1)
  • _order_b : 2nd polynomial order
  • _c : output polynomial, shape: (_order_a+_order_b+1, 1)