ECM6Lecture11bVietnam 2014
ECM6Lecture11bVietnam 2014
ECM6Lecture11bVietnam 2014
Slide 1 of 5
Lecture 11b
Polynomial Regression
Brian G. Higgins
Department of Chemical Engineering & Materials Science
University of California, Davis
April 2014, Hanoi, Vietnam
ECM6Lecture11bVietnam_2014.nb
Background
We will now extend the ideas from Lecture 11a to find the best fit in a least squares sense for an
arbitrary polynomial:
P HxL = a0 + a1 x + a2 x2 + a3 x3 + + an xn
As before we will be given a set of M data points in the form
k=1
We know from calculus that to minimize the least square error, the desired values of ai must satisfy
E2 HLL
ai
= 0 , i = 0, 1, , n
Note that since the xk ' s and yk ' s are constant. Thus we have n+1 linear equations for the n+1 parameters ak
ECM6Lecture11bVietnam_2014.nb
Example 1
Suppose we have the following data points
881, 5.12<, 83, 3<, 86, 2.48<, 89, 2.34<, 815, 2.18<<
and we want to find the parameters ak that give the least square error for a guess function
PHxL = a0 + a1 x + a2 x 2 + a3 x 3
Thus it is a simple matter to generate the various equations required to determine the parameters ai :
ECM6Lecture11bVietnam_2014.nb
eqns =
8D@E2 @P, MD, a0 D 0, D@E2 @P, MD, a1 D 0, D@E2 @P, MD, a2 D 0, D@E2 @P, MD, a3 D 0<
82 H- 5.12 + a0 + a1 + a2 + a3 L +
2 H- 3 + a0 + 3 a1 + 9 a2 + 27 a3 L + 2 H- 2.48 + a0 + 6 a1 + 36 a2 + 216 a3 L +
2 H- 2.34 + a0 + 9 a1 + 81 a2 + 729 a3 L + 2 H- 2.18 + a0 + 15 a1 + 225 a2 + 3375 a3 L 0,
2 H- 5.12 + a0 + a1 + a2 + a3 L + 6 H- 3 + a0 + 3 a1 + 9 a2 + 27 a3 L +
12 H- 2.48 + a0 + 6 a1 + 36 a2 + 216 a3 L + 18 H- 2.34 + a0 + 9 a1 + 81 a2 + 729 a3 L +
30 H- 2.18 + a0 + 15 a1 + 225 a2 + 3375 a3 L 0,
2 H- 5.12 + a0 + a1 + a2 + a3 L + 18 H- 3 + a0 + 3 a1 + 9 a2 + 27 a3 L +
72 H- 2.48 + a0 + 6 a1 + 36 a2 + 216 a3 L + 162 H- 2.34 + a0 + 9 a1 + 81 a2 + 729 a3 L +
450 H- 2.18 + a0 + 15 a1 + 225 a2 + 3375 a3 L 0,
2 H- 5.12 + a0 + a1 + a2 + a3 L + 54 H- 3 + a0 + 3 a1 + 9 a2 + 27 a3 L +
432 H- 2.48 + a0 + 6 a1 + 36 a2 + 216 a3 L + 1458 H- 2.34 + a0 + 9 a1 + 81 a2 + 729 a3 L +
6750 H- 2.18 + a0 + 15 a1 + 225 a2 + 3375 a3 L 0<
PHxL
ECM6Lecture11bVietnam_2014.nb
10
12
14
x
It is apparent from the plots that a cubic polynomial is not an exceptionally good fit visually. How can we
evaluate the goodness of the fit quantitatively. We leave this question for later.
Note as the order of the polynomial increases, so does its ability to oscillate.
ECM6Lecture11bVietnam_2014.nb
Example 2
Problem Statement
Consider the following set of {x,y} data
882, 0.75<, 84, 0.1875<, 85, 0.1200<, 86, 0.0833<, 88, 0.0469<<
Determine the parameter values c and n in the model
y = c xn
that gives the best fit of the data in a least squares sense.
Y=m+nX
where the following definitions are used
ECM6Lecture11bVietnam_2014.nb
y = 2.2
Note instead of using the loge to transform our power function into a linear model, we could have used
log10 or for that matter log to any base.
Y=PHXL
-1
-2
-3
-4
0.5
1.0
1.5
2.0
X
Here is the plot in terms of the original variables (x, y)
2.5
ECM6Lecture11bVietnam_2014.nb
plt1 = PlotA3 x-2 , 8x, 2, 10<, PlotStyle 8Blue, Thick<, Frame True,
FrameLabel 8Style@"x", 16D, Style@"PHxL", 16D<, PlotRange AllE;
plt2 = ListPlot@data5, PlotStyle 8PointSize@LargeD, Red<D;
Show@plt1, plt2, PlotRange AllD
0.7
0.6
0.5
PHxL
0.4
0.3
0.2
0.1
0.0
2
10
References
These notes and the examples were adapted from the follow texts:
M. J. Maron, Numerical Analysis. A Practical Approach, 2nd Edition, Macmillan Publishing Company,
1987
A. J. Pettoprezzo, Introductory Numerical Analysis, Dover Publications, 1984