polyfit
Polynomial curve fitting
Description
[
also returnsp
,S
,mu
] = polyfit(x
,y
,n
)mu
, which is a two-element vector with centering and scaling values.mu(1)
ismean(x)
, andmu(2)
isstd(x)
. Using these values,polyfit
centersx
at zero and scales it to have unit standard deviation,
This centering and scaling transformation improves the numerical properties of both the polynomial and the fitting algorithm.
Examples
Input Arguments
Output Arguments
Limitations
In problems with many points, increasing the degree of the polynomial fit using
polyfit
does not always result in a better fit. High-order polynomials can be oscillatory between the data points, leading to apoorerfit to the data. In those cases, you might use a low-order polynomial fit (which tends to be smoother between points) or a different technique, depending on the problem.Polynomials are unbounded, oscillatory functions by nature. Therefore, they are not well-suited to extrapolating bounded data or monotonic (increasing or decreasing) data.
Algorithms
polyfit
usesx
to form Vandermonde matrixV
withn+1
columns andm = length(x)
rows, resulting in the linear system
whichpolyfit
solves withp = V\y
. Since the columns in the Vandermonde matrix are powers of the vectorx
, the condition number ofV
is often large for high-order fits, resulting in a singular coefficient matrix. In those cases centering and scaling can improve the numerical properties of the system to produce a more reliable fit.