polyfit
R2026bPolynomial curve fitting
Syntax
Description
[
provides the option to apply normalization when fitting. If you set
coeffs,fitStats,centerScale]
= polyfit(x,y,n,Normalize=tf)Normalize to true,
polyfit centers x at
0 and scales it to have a standard deviation of
1 according to the transformation In this case, polyfit also returns the
centerScale output as a two-element vector that contains the
center and scaling values, which are mean(x) and
std(x). If you set Normalize to
false, polyfit does not transform
x, and centerScale is a two-element vector
that contains 0 and 1. (since R2026b)
Before R2026b: Normalization is controlled implicitly by the number of output arguments. Returning a third output argument enables normalization automatically. See Version History for more information.
Examples
Input Arguments
Output Arguments
Limitations
In problems with many points, increasing the degree of the polynomial fit using
polyfitdoes not always result in a better fit. High-order polynomials can be oscillatory between the data points, leading to a poorer fit 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 (consistently increasing or consistently decreasing) data.
Algorithms
polyfit uses x to form
a Vandermonde matrix V with n+1 columns
and m = length(x) rows, resulting in the linear
system
which polyfit solves with coeffs = V\y. Since the
columns in the Vandermonde matrix are powers of the vector x, the
condition number of V is often large for high-order fits, resulting
in a singular coefficient matrix. In those cases, specifying
Normalize=true can improve the numerical properties of the system
to produce a more reliable fit.





