User`s guide

Least Squares Polynomial Fit
5-261
5Least Squares Polynomial Fit
Purpose Compute the coefficients of the polynomial that best fits the input data in a
least-squares sense.
Library Math Functions / Polynomial Functions
Description The Least Squares Polynomial Fit block computes the coefficients of the nth
order polynomial that best fits the input data in the least-squares sense, where
n is specified by the
Polynomial order parameter. A distinct set of n+1
coefficients is computed for each column of the M-by-N input, u.
For a given input column, the block computes the set of coefficients,
c
1
, c
2
,…,c
n+1
, that minimizes the quantity
where u
i
is the ith element in the input column, and
The values of the independent variable, x
1
, x
2
,…,x
M
, are specified as a
length-M vector by the
Control points parameter. The same M control points
are used for all N polynomial fits, and can be equally or unequally spaced. The
equivalent MATLAB code is shown below.
c = polyfit(x,u,n) % Equivalent MATLAB code
Inputs can be frame-based or sample-based. For convenience, a length-M 1-D
vector input is treated as an M-by-1 matrix.
Each column of the (n+1)-by-N output matrix, c, represents a set of n+1
coefficients describing the best-fit polynomial for the corresponding column of
the input. The coefficients in each column are arranged in order of descending
exponents, c
1
, c
2
,…,c
n+1
. The output is always sample-based.
Example In the model below, the Polynomial Evaluation block uses the second-order
polynomial
u
i
u
ˆ
i
()
2
i 1=
M
u
ˆ
i
fx
i
() c
1
x
i
n
c
2
x
i
n 1
L c
n 1+
+++==
y 2 u
2
3+=