# poly

Variants: poly, polyc, polycf, polyf

## Public Functions

 double poly_val(double * _p, unsigned int _k, double _x) int poly_fit(double * _x, double * _y, unsigned int _n, double * _p, unsigned int _k) int poly_fit_lagrange(double * _x, double * _y, unsigned int _n, double * _p) double poly_interp_lagrange(double * _x, double * _y, unsigned int _n, double _x0) int poly_fit_lagrange_barycentric(double * _x, unsigned int _n, double * _w) double poly_val_lagrange_barycentric(double * _x, double * _y, double * _w, double _x0, unsigned int _n) int poly_expandbinomial(unsigned int _n, double * _p) int poly_expandbinomial_pm(unsigned int _m, unsigned int _k, double * _p) int poly_expandroots(double * _r, unsigned int _n, double * _p) int poly_expandroots2(double * _a, double * _b, unsigned int _n, double * _p) int poly_findroots(double * _poly, unsigned int _n, double complex * _roots) int poly_findroots_durandkerner(double * _p, unsigned int _k, double complex * _roots) int poly_findroots_bairstow(double * _p, unsigned int _k, double complex * _roots) int poly_mul(double * _a, unsigned int _order_a, double * _b, unsigned int _order_b, double * _c)

## Interfaces

double poly_val(double * _p, unsigned int _k, double _x)

Evaluate polynomial _p at value _x

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

int poly_fit(double * _x, double * _y, unsigned int _n, double * _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 poly_fit_lagrange(double * _x, double * _y, unsigned int _n, double * _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)

double poly_interp_lagrange(double * _x, double * _y, unsigned int _n, double _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 poly_fit_lagrange_barycentric(double * _x, unsigned int _n, double * _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 =1, size [_n x 1]

double poly_val_lagrange_barycentric(double * _x, double * _y, double * _w, double _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 poly_expandbinomial(unsigned int _n, double * _p)

Perform binomial expansion on the polynomial $$P_n(x) = (1+x)^n$$ as $$P_n(x) = p + px + px^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 poly_expandbinomial_pm(unsigned int _m, unsigned int _k, double * _p)

Perform positive/negative binomial expansion on the polynomial $$P_n(x) = (1+x)^m (1-x)^k$$ as $$P_n(x) = p + px + px^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 poly_expandroots(double * _r, unsigned int _n, double * _p)

Perform root expansion on the polynomial $$P_n(x) = (x-r) (x-r) ... (x-r[n-1])$$ as $$P_n(x) = p + px + ... + p[n]x^n$$ where $$r,r,...,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 poly_expandroots2(double * _a, double * _b, unsigned int _n, double * _p)

Perform root expansion on the polynomial $$P_n(x) = (xb-a) (xb-a)...(xb[n-1]-a[n-1])$$ as $$P_n(x) = p + px + ... + 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 poly_findroots(double * _poly, unsigned int _n, double complex * _roots)

Find the complex roots of a polynomial.

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

int poly_findroots_durandkerner(double * _p, unsigned int _k, double 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 poly_findroots_bairstow(double * _p, unsigned int _k, double 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 poly_mul(double * _a, unsigned int _order_a, double * _b, unsigned int _order_b, double * _c)

Expand the multiplication of two polynomials $$( a + ax + ax^2 + ...) (b + bx + b[]x^2 + ...)$$ as $$c + cx + cx^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)