![]()
![]()
Lab for Least Squares Lines and Polynomials
![]()
First load Mathematica's graphics package "Colors".
Report to be handed in.
Computer Exercises
Exercise 1. Find the two
"Least Squares Lines" y = ax + b and x = cy + d for the data
points
(-4.5, 0.7), (-3.2, 2.3), (-1.4, 3.8), (0.8, 5.0), (2.5, 5.5), (4.1,
6.6).
(a) Use the computer to find the
least squares lines y = ax + b and x = cy + d.
(b) What point is common to both
lines.
(c) Are the two lines the same ?
Why?
First, enter the data points.
Use Mathematica to find the "Least Square Lines" y = ax + b.
Plot the "Least Square Lines" y = ax + b.
![]()
![[Graphics:lp.txtgr7.gif]](lp.txtgr7.gif)
Reverse the order of the coordinates of the points.
Use Mathematica to find the "Least Square Lines" x = cy + d.
Plot the "Least Square Lines" x = cy + d.
![]()
![[Graphics:lp.txtgr14.gif]](lp.txtgr14.gif)
Compare the two "Least Squares Lines" y = ax + b and x = cy + d.
![]()
![[Graphics:lp.txtgr17.gif]](lp.txtgr17.gif)
Find the point of intersection.
Be careful, to prevent a fatal error you must use == .
Compare this with the following average.
What do you conjecture ! Can you prove it ?
Exercise 2. Derive the "normal equations" for "Least Squares Lines" y = ax + b and x = cy + d .
First, derive the "normal equations" for "Least Squares Line" y = ax + b.
The "normal equations" for "Least Squares Line" y = ax + b are
The coefficients a and b are computed wit the formulas:
Second, derive the "normal equations" for "Least Squares Line" x = cy + d.
The "normal equations" for "Least Squares Line" x = cy + d are:
The coefficients c and d are computed wit the formulas:
Exercise 3. Explain
geometrically what is minimized to find each of the "Least Squares
Lines."
![]()
Polynomial curve fitting.
Exercise 4. Find the
polynomial fits of degree n = 2 for the following points.
Use Mathematica to find the "Least Square Quadratic".
Plot the "Least Square Quadratic".
![]()
![[Graphics:lp.txtgr35.gif]](lp.txtgr35.gif)
Exercise 5. Find the
polynomial fits of degree n = 3 for the data points in the previous
example.
Use Mathematica to find the "Least Square Cubic".
Plot the "Least Square Cubic".
![]()
![[Graphics:lp.txtgr40.gif]](lp.txtgr40.gif)
Caution for polynomial curve
fitting.
Something goes wrong if the data is radically "NOT polynomial."
This phenomenon is called "polynomial wiggle."
Exercise 6. Find the least
squares polynomial fits of degree n = 2, 3, 4, 5 for the points
(0.25, 23.1), (1.0 , 1.68), (1.5 , 1.0), (2.0 , 0.84), (2.4 , 0.826),
(5.0 , 1.2576)
REMARK. The points were obtained from
.
![]()
![[Graphics:lp.txtgr46.gif]](lp.txtgr46.gif)
Use Mathematica to find the least squares polynomial of degree n = 2.
![]()
![[Graphics:lp.txtgr48.gif]](lp.txtgr48.gif)
Use Mathematica to find the least squares polynomial of degree n = 3.
![]()
![[Graphics:lp.txtgr51.gif]](lp.txtgr51.gif)
Use Mathematica to find the least squares polynomial of degree n = 4.
![]()
![[Graphics:lp.txtgr54.gif]](lp.txtgr54.gif)
Use Mathematica to find the least squares polynomial of degree n = 5.
![]()
![[Graphics:lp.txtgr57.gif]](lp.txtgr57.gif)
What do you see happening with the polynomials of degree n = 2, 3, 4, 5 ?
![]()
![]()
(c) John H. Mathews, 1998