Equana

Back to Polynomials

polyfit

Least-squares polynomial fit of the given degree.

Syntax

polyfit(x, y, deg) → r

Backends

TypeScriptnumwa

Description

Least-squares polynomial fit of the given degree.

Parameters

NameDescription
xx-coordinates of sample points
yy-coordinates of sample points
degDegree of the fitting polynomial

Returns

Polynomial coefficients of the best fit (descending order)

Examples

Try It
>> polyfit([0, 1, 2], [1, 3, 5], 1)
[2, 1]  (linear fit y = 2x + 1)