Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Compute polynomial coefficients that best fit input data in least-squares sense

Math Functions / Polynomial Functions

`dsppolyfun`

The Least Squares Polynomial Fit block computes the coefficients
of the * n*th order polynomial that best fits the
input data in the least-squares sense, where you specify

For a given input column, the block computes the set of coefficients, * c_{1}*,

$$\sum _{i=1}^{M}{({u}_{i}-{\widehat{u}}_{i})}^{2}$$

where * u_{i}* is the

$${\widehat{u}}_{i}=f\left({x}_{i}\right)={c}_{1}{x}_{i}^{n}+{c}_{2}{x}_{i}^{n-1}+\text{}\mathrm{...}\text{}+{c}_{n+1}$$

The values of the independent variable, * x_{1}*,

c = polyfit(x,u,n) % Equivalent MATLAB code

For convenience, the block treats length-* M* unoriented
vector input as an

Each column of the (* n*+1)-by-

In the ex_leastsquarespolyfit_ref model below, the Polynomial Evaluation block uses the second-order polynomial

$$y=-2{u}^{2}+3$$

to generate four values of dependent variable * y* from
four values of independent variable

```
[-2
0 3]
```

at the bottom port. Note that the coefficient of the
first-order term is zero.

The **Control points** parameter of the Least
Squares Polynomial Fit block is configured with the same four values
of independent variable * u* that are used as input
to the Polynomial Evaluation block,

`[1 2 3 4]`

.
The Least Squares Polynomial Fit block uses these values together
with the input values of dependent variable **Control points**The values of the independent variable to which the data in each input column correspond. For an

-by-*M*input, this parameter must be a length-*N*vector. Tunable (Simulink).*M***Polynomial order**The order,

, of the polynomial to be used in constructing the best fit. The number of coefficients is*n*+1.*n*

Double-precision floating point

Single-precision floating point

Detrend | DSP System Toolbox |

Polynomial Evaluation | DSP System Toolbox |

Polynomial Stability Test | DSP System Toolbox |

`polyfit` | MATLAB |

Was this topic helpful?