Graphics Programs Reference
In-Depth Information
Polynomial Fit
A commonlyused linear formis apolynomial. If the degree of the polynomial is m
1,
= j = 1 a j x j 1 . Here the basisfunctions are
wehave f ( x )
x j 1 ,
f j ( x )
=
j
=
1
,
2
,...,
m
(3.22)
so that Eqs. (3.21b) become
n
n
x j + k 2
i
x k 1
i
A kj =
b k =
y i
i
=
1
i
=
1
or
x i x i
x i
y i
x i y i
.
x m 1
i
n
...
x i
x i x i
x m + 1
i
...
A
=
b
=
(3.23)
.
.
.
.
. . .
x m 1
i
x i x m + 1
x 2 m 2
i
...
y i
i
where standsfor i = 1 . The normalequations become progressivelyill-conditioned
with increasing m .Fortunately,this isoflittle practicalconsequence, because only
low-orderpolynomials are useful in curve fitting. Polynomials of highorderare not
recommended, because they tend to reproduce the noise inherent in the data.
polynFit
The function polynFit computes the coefficients of apolynomialofdegree m
1 to
fit n datapoints in the least-squares sense. To facilitate computations, the terms n ,
x i , x i ,
, x 2 m i that make up the coefficient matrix A in Eq. (3.23) are first
storedinthe vector s and theninsertedinto A . The normalequations are solved for
the coefficient vector coeff by Gauss eliminationwith pivoting. Since the elements
of coeff emerging from the solutionare not arrangedinthe usualorder (the coeffi-
cient of the highest power of x first), the coeff array is “flipped” upside-down before
returning to the calling program.
...
function coeff = polynFit(xData,yData,m)
% Returns the coefficients of the polynomial
% a(1)*xˆ(m-1) + a(2)*xˆ(m-2) + ... + a(m)
% that fits the data points in the least squares sense.
% USAGE: coeff = polynFit(xData,yData,m)
% xData = x-coordinates of data points.
% yData = y-coordinates of data points.
Search WWH ::




Custom Search