polyFit

Syntax

polyFit(X, Y, n)

Arguments

X is a numeric vector specifying the query points. The points in X correspond to the fitted function values contained in Y.

Y is a numeric vector of the same length as X, which specifies the fitted values at query points. It must not contain NULL values.

n is a non-negative scalar indicating the degree of polynomial fit.

Details

Return a vector indicating the least-squares fit polynomial coefficients in ascending powers for a polynomial p(X) of degree n that is a best fit (in a least-squares sense) for the data in Y.

Examples

x = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]
y = [0.0, 0.8, 0.9, 0.1, -0.8, -1.0]
z = polyFit(x, y, 3)
z
// output
[-0.0397,1.6931,-0.8135,0.087]

Related Function: poly1d