Numerical Analysis and Computing: Lecture Notes #12 - Approximation Theory - Chebyshev Polynomials & Least Squares, Redux
Numerical Analysis and Computing: Lecture Notes #12 - Approximation Theory - Chebyshev Polynomials & Least Squares, Redux
Joe Mahaffy,
[email protected]
Department of Mathematics
Dynamical Systems Group
Computational Sciences Research Center
San Diego State University
San Diego, CA 92182-7720
http://www-rohan.sdsu.edu/∼jmahaffy
Spring 2010
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (1/45)
Chebyshev Polynomials
Least Squares, redux
Outline
1 Chebyshev Polynomials
Orthogonal Polynomials
Chebyshev Polynomials, Intro & Definitions
Properties
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (2/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (3/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
d 2y dy
(1 − x 2 ) 2
− 2x + ℓ(ℓ + 1)y = 0, ℓ∈N
dx dx
or equivalently
· ¸
d dy
(1 − x 2 ) + ℓ(ℓ + 1)y = 0, ℓ∈N
dx dx
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (4/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
(http://mathworld.wolfram.com/OrthogonalPolynomials.html)
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (5/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
d2 dy
x 2
+ (1 − x) + λy = 0
dx dx
They are associated with the radial solution to the Schrödinger
equation for the Hydrogen atom’s electron (Spherical Harmonics).
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (6/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (7/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
1 − t 2 t −(n+1)
I ¡ ¢
1
Tn (z) = dt
2πi (1 − 2tz + t 2 )
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (9/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (9/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (10/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (10/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
or
Tn+1 (x) = 2xTn (x) − Tn−1 (x).
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (10/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
0.5
-0.5
-1
-1 -0.5 0 0.5 1
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (11/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
0.5
-0.5
-1
-1 -0.5 0 0.5 1
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (11/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
0.5
-0.5
-1
-1 -0.5 0 0.5 1
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (11/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
-0.5
-1
-1 -0.5 0 0.5 1
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (11/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
-0.5
-1
-1 -0.5 0 0.5 1
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (11/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
1 1
Tn (x)Tm (x) dx
Z Z
√ dx = cos(n arccos x) cos(m arccos x) √ .
−1 1 − x2 −1 1 − x2
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (12/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
1 1
Tn (x)Tm (x) dx
Z Z
√ dx = cos(n arccos x) cos(m arccos x) √ .
−1 1 − x2 −1 1 − x2
Reintroducing θ = arccos x gives,
dx
dθ = − √ ,
1 − x2
and the integral becomes
Z 0 Z π
− cos(nθ) cos(mθ) dθ = cos(nθ) cos(mθ) dθ.
π 0
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (12/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
1 1
Tn (x)Tm (x) dx
Z Z
√ dx = cos(n arccos x) cos(m arccos x) √ .
−1 1 − x2 −1 1 − x2
Reintroducing θ = arccos x gives,
dx
dθ = − √ ,
1 − x2
and the integral becomes
Z 0 Z π
− cos(nθ) cos(mθ) dθ = cos(nθ) cos(mθ) dθ.
π 0
Now, we use the fact that
cos(n + m)θ + cos(n − m)θ
cos(nθ) cos(mθ) = ...
2
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (12/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
We have: π
cos(n + m)θ + cos(n − m)θ
Z
dθ.
0 2
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (13/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
We have: π
cos(n + m)θ + cos(n − m)θ
Z
dθ.
0 2
If m 6= n, we get
· ¸π
1 1
sin((n + m)θ) + sin((n − m)θ) = 0,
2(n + m) 2(n − m) 0
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (13/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
We have: π
cos(n + m)θ + cos(n − m)θ
Z
dθ.
0 2
If m 6= n, we get
· ¸π
1 1
sin((n + m)θ) + sin((n − m)θ) = 0,
2(n + m) 2(n − m) 0
if m = n, we have
· ¸π
1 x π
sin((n + m)θ) + = .
2(n + m) 2 0 2
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (13/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Theorem
The Chebyshev polynomial of degree n ≥ 1 has n simple zeros in
[−1, 1] at µ ¶
2k − 1
xk = cos π , k = 1, . . . , n.
2n
Moreover, Tn (x) assumes its absolute extrema at
µ ¶
′ kπ
xk = cos , with Tn (xk′ ) = (−1)k , k = 1, . . . , n − 1.
n
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (14/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Theorem
The Chebyshev polynomial of degree n ≥ 1 has n simple zeros in
[−1, 1] at µ ¶
2k − 1
xk = cos π , k = 1, . . . , n.
2n
Moreover, Tn (x) assumes its absolute extrema at
µ ¶
′ kπ
xk = cos , with Tn (xk′ ) = (−1)k , k = 1, . . . , n − 1.
n
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (14/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Proof.
Let: „ « „ «
2k − 1 kπ
xk = cos π , xk′ = cos .
2n n
Then:
“ “ “ ”””
Tn (xk ) = cos(n arccos(xk )) = cos n arccos cos 2k−1
2n
π
“ ” √
= cos 2k−1
2
π = 0,
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (15/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Proof.
Let: „ « „ «
2k − 1 kπ
xk = cos π , xk′ = cos .
2n n
Then:
“ “ “ ”””
Tn (xk ) = cos(n arccos(xk )) = cos n arccos cos 2k−1
2n
π
“ ” √
= cos 2k−1
2
π = 0,
d n sin(n arccos(x))
Tn′ (x) = [cos(n arccos(x))] = √ ,
dx 1 − x2
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (15/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Proof.
Let: „ « „ «
2k − 1 kπ
xk = cos π , xk′ = cos .
2n n
Then:
“ “ “ ”””
Tn (xk ) = cos(n arccos(xk )) = cos n arccos cos 2k−1
2n
π
“ ” √
= cos 2k−1
2
π = 0,
d n sin(n arccos(x))
Tn′ (x) = [cos(n arccos(x))] = √ ,
dx 1 − x2
n sin(n arccos(cos( kπ
n ))) n sin(kπ) √
Tn′ (xk′ ) = = = 0,
sin( kπ
q
1−cos2 ( kπ
n ) n )
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (15/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Proof.
Let: „ « „ «
2k − 1 kπ
xk = cos π , xk′ = cos .
2n n
Then:
“ “ “ ”””
Tn (xk ) = cos(n arccos(xk )) = cos n arccos cos 2k−1
2n
π
“ ” √
= cos 2k−1
2
π = 0,
d n sin(n arccos(x))
Tn′ (x) = [cos(n arccos(x))] = √ ,
dx 1 − x2
n sin(n arccos(cos( kπ
n ))) n sin(kπ) √
Tn′ (xk′ ) = = = 0,
sin( kπ
q
1−cos2 ( kπ
n ) n )
“ “ “ ””” √
Tn (xk′ ) = cos n arccos cos kπ
n
= cos(kπ) = (−1)k .
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (15/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (16/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
The location of the zeros and extrema of T̃n (x) coincides with
those of Tn (x), however the extreme values are
(−1)k
T̃n (xk′ ) = , k = 1, . . . , n − 1.
2n−1
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (17/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
The location of the zeros and extrema of T̃n (x) coincides with
those of Tn (x), however the extreme values are
(−1)k
T̃n (xk′ ) = , k = 1, . . . , n − 1.
2n−1
Definition
Let P̃n denote the set of all monic polynomials of degree n.
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (17/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
The location of the zeros and extrema of T̃n (x) coincides with
those of Tn (x), however the extreme values are
(−1)k
T̃n (xk′ ) = , k = 1, . . . , n − 1.
2n−1
Definition
Let P̃n denote the set of all monic polynomials of degree n.
Theorem (Min-Max)
The monic Chebyshev polynomials T̃n (x), have the property that
1
= max |T̃n (x)| ≤ max |Pn (x)|, ∀Pn (x) ∈ P̃n .
2n−1 x∈[−1,1] x∈[−1,1]
0.5
-0.5
-1
-1 -0.5 0 0.5 1
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (18/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
0.5
-0.5
-1
-1 -0.5 0 0.5 1
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (18/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
0.5
-0.5
-1
-1 -0.5 0 0.5 1
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (18/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
-0.5
-1
-1 -0.5 0 0.5 1
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (18/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
-0.5
-1
-1 -0.5 0 0.5 1
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (18/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (19/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (19/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (19/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Theorem
If P(x) is the interpolating polynomial of degree at most n with
nodes at the roots of Tn+1 (x), then
1
max |f (x) − P(x)| ≤ max |f (n+1) (x)|,
x∈[−1,1] 2n (n + 1)! x∈[−1,1]
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (20/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Theorem
If P(x) is the interpolating polynomial of degree at most n with
nodes at the roots of Tn+1 (x), then
1
max |f (x) − P(x)| ≤ max |f (n+1) (x)|,
x∈[−1,1] 2n (n + 1)! x∈[−1,1]
f(x)
2.5
1.5
0.5
0
0 0.2 0.4 0.6 0.8 1
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (21/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
f(x)
2.5 Taylor2(x)
1.5
0.5
0
0 0.2 0.4 0.6 0.8 1
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (21/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
f(x)
2.5 Taylor2(x)
Lagrange2EquiSpaced(x)
1.5
0.5
0
0 0.2 0.4 0.6 0.8 1
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (21/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
f(x)
2.5 Taylor2(x)
Lagrange2EquiSpaced(x)
Lagrange2Optimal(x)
2
1.5
0.5
0
0 0.2 0.4 0.6 0.8 1
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (21/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
Deviation: EquiSpaced
Deviation: Optimal
0.1
-0.1
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (22/45)
Orthogonal Polynomials
Chebyshev Polynomials
Chebyshev Polynomials, Intro & Definitions
Least Squares, redux
Properties
0.05 0.01
0 0.005
−0.05 0
−0.1 −0.005
−0.15 −0.01
−0.2 −0.015
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
−5 Degree 5
−3 Degree 4 x 10
x 10 10
1.5 Error: EquiSpaced
Error: EquiSpaced
Error: Optimal
Error: Optimal
1
0.5 5
−0.5 0
−1
−1.5 −5
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (23/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (24/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
Example #1 — Warm-up 1 of 3
First we consider the problem of fitting 1st, 2nd, and 3rd degree
polynomials to the following data:
x = [1.0 1.1 1.3 1.5 1.9 2.1]’
y = [1.84 1.90 2.31 2.65 2.74 3.18]’
matlab¿¿ [First we define the matrices]
A1 = [ones(size(x)) x];
A2 = [A1 x.*x];
A3 = [A2 x.*x.*x ];
[Then we solve the Normal Equations]
pcoef1 = A1\y;
pcoef2 = A2\y;
pcoef3 = A3\y;
Note: The matrices A1, A2, and A3 are “tall and skinny.” Normally we
would compute (An′ · An)−1 (An′ · y ), however when matlab encounters
An\y it automatically gives us a solution in the least squares sense.
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (25/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
Example #1 — Warm-up 2 of 3
3 3 3
1 1.2 1.4 1.6 1.8 2 1 1.2 1.4 1.6 1.8 2 1 1.2 1.4 1.6 1.8 2
Example #1 — Warm-up 3 of 3
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (27/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
√
But let’s find the best fit of the form a + b x to this data! Notice
that this expression is linear in its parameters a, b, so we can solve
the corresponding least squares problem!
matlab>> A = [ones(size(x)) sqrt(x)];
pcoef = A\y;
xv = 1.0:0.01:2.1;
fv = pcoef(1) + pcoef(2)*sqrt(xv);
plot(xv,fv,’k-’,’linewidth’,3); hold on;
plot(x,y,’ko’,’linewidth’,3); hold off;
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (28/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
2.8
2.6
2.4
2.2
2 LSQ−error: 0.074920
1.8
Err √
Which gives us P{a+b x} = 0.0749
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (29/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
etc...
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (30/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
2.8
2.6
2.4
2.2
2 LSQ−error: 0.062771
1.8
Getting Multi-Dimensional
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (32/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
Example: Going 2D 1 of 10
matlab>> x=1:0.25:5;
y=1:0.25:5;
[X,Y]=meshgrid(x,y);
Fxy=1+sqrt(X)+Y.∧ 3+0.05*randn(size(X));
surf(x,y,Fxy)
150
100
50
0
6
4 5
4
2 3
2
0 1
Figure: 2D-data set, the vertexes on the surface are our data points.
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (33/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
Example: Going 2D 2 of 10
M(a, b, c) = a + bx + cy
matlab>> sz = size(X);
Bm = reshape(X,prod(sz),1);
Cm = reshape(Y,prod(sz),1);
Am = ones(size(Bm));
RHS = reshape(Fxy,prod(sz),1);
A = [Am Bm Cm];
coef = A \ RHS;
fit = coef(1) + coef(2)*X + coef(3)*Y;
fitError = Fxy - fit;
surf(x,y,fitError)
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (34/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
Example: Going 2D 3 of 10
150 30
20
100
10
0
50
−10
0 −20
6 6
4 5 4 5
4 4
2 3 2 3
2 2
0 1 0 1
Figure: The optimal model fit, and the fitting error for the
least squares best-fit in the model space M(a, b, c) = a +
bx + cy . Here, the total LSQ-error is 42,282.
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (35/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
Example: Going 2D 4 of 10
M(a, b, c) = a + bx + cy + dxy
matlab>> sz = size(X);
Bm = reshape(X,prod(sz),1);
Cm = reshape(Y,prod(sz),1);
Dm = reshape(X.*Y,prod(sz),1);
Am = ones(size(Bm));
RHS = reshape(Fxy,prod(sz),1);
A = [Am Bm Cm Dm];
coef = A \ RHS;
fit = coef(1) + coef(2)*X + coef(3)*Y + coef(4)*X.*Y;
fitError = Fxy - fit;
surf(x,y,fitError)
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (36/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
Example: Going 2D 5 of 10
150 30
20
100
10
0
50
−10
0 −20
6 6
4 5 4 5
4 4
2 3 2 3
2 2
0 1 0 1
Figure: The fitting error for the least squares best-fit in the
model space M(a, b, c) = a + bx + cy + dxy . — Still a pretty
bad fit. Here, the total LSQ-error is still 42,282.
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (37/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
Example: Going 2D 6 of 10
M(a, b, c) = a + bx + cy + dy 2
matlab>> sz = size(X);
Bm = reshape(X,prod(sz),1);
Cm = reshape(Y,prod(sz),1);
Dm = reshape(Y.*Y,prod(sz),1);
Am = ones(size(Bm));
RHS = reshape(Fxy,prod(sz),1);
A = [Am Bm Cm Dm];
coef = A \ RHS;
fit = coef(1) + coef(2)*X + coef(3)*Y + coef(4)*Y.*Y;
fitError = Fxy - fit;
surf(x,y,fitError)
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (38/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
Example: Going 2D 7 of 10
150 4
2
100
0
50
−2
0 −4
6 6
5 4 5
4
4 4
2 3 2 3
2 2
0 1 0 1
Figure: The fitting error for the least squares best-fit in the
model space M(a, b, c) = a + bx + cy + dy 2 . — We see a
significant drop in the error (one order of magnitude); and
the total LSQ-error has dropped to 578.8.
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (39/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
Example: Going 2D 7 12 of 10
xy y2 Both
κ(A) 86.2 107.3 170.5
κ(AT A) 7,422 11,515 29,066
Table: Condition numbers for the A-matrices (and
associated Normal Equations) for the different models.
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (40/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
Example: Going 2D 8 of 10
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (41/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
Example: Going 2D 9 of 10
150 0.2
0.1
100
0
50
−0.1
0 −0.2
6 6
4 5 5
4
4 4
2 3 2 3
2 2
0 1 0 1
Figure: The fitting error for the least squares best-fit in the
model space M(a, b, c) = a + bx + cy + dy 2 + ey 3 . — We
now have a pretty good fit. The LSQ-error is now down to
0.9864.
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (42/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
Example: Going 2D 10 of 10
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (43/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
At this point we can state the Linear Least Squares fitting problem
in any number of dimensions, and we can use exotic models if we
want to.
In 3D we need 10 parameters to fit a model with all linear, and
second order terms
M(a, b, c, d, e, f , g , h, i, j) =
a + bx + cy + dz + ex 2 + fy 2 + gz 2 + hxy + ixz + jyz
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (44/45)
Chebyshev Polynomials Examples
Least Squares, redux More than one variable? — No problem!
Joe Mahaffy, [email protected] Chebyshev Polynomials & Least Squares, redux — (45/45)