







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








Problem 1: Consider the data in the following table
xi 1 2 4 5
yi 2 3 5 6
We want to find the least squares polynomial of degree 2
P (x) = a 0 + a 1 x + a 2 x
2 (2)
for the data in the following ways.
(a) Write the normal equations and solve them analytically.
(b) Write a linear least squares problem minu∈R 3 E = ||Au − b|| 2 for the data, where
u = (a 0 , a 1 , a 2 )
T
. Solve this linear least squares problem analytically with QR decompo-
sition. Compute the error E.
(c) Write a program for part (b) to verify your solutions.
Solution:
Note that in the formulation above,
1 x 1 x
2 1 1 x 2 x
2 2
1 x 3 x
2 3 1 x 4 x^24
, u =
a 0
a 1
a 2
(^) , b =
y 1
y 2
y 3
y 4
Plugging in the values of xi and yi into Au = b, we obtain
Au =
a 0
a 1
a 2
= b.
It is better to approach part (b) first. From part (b), we see that the polynomial in (2) is
a line.
a) Note: The solution to the normal equations described in this part is a simplifica-
tion. Consult pages 484-486 of textbook for a proper procedure of writing out normal
equations.
We have a linear least squares problem
min u∈R^3
E = ||Au − b|| 2.
The normal equations associated to this problem are
T Au = A
T b.
For the problem above, we have
u =
(^) u =
Thus,
u = (A
T A)
− 1 A
T b =
Thus the polynomial in (2) is written as
P (x) = 1 + x.
b) We now use Gram-Schmidt process to compute the QR decomposition of A. Be-
low, a 1 , a 2 , a 3 are the columns of matrix A, not the elements of vector u. First compute
the columns of Q:
q˜ 1 = a 1 =
q 1 =
q˜ 1
||q˜ 1 || 2
1 2 1 2 1 2 1 2
q ˜ 2 = a 2 − (q
T 1 a^2 )q^1 =
1 2 1 2 1 2 1 2
q 2 =
q˜ 2
||q˜ 2 || 2
√^2 10 − √^1 10 √^1 10 √^2 10
q ˜ 3 = a 3 − (q
T 1 a^3 )q^1 −^ (q
T 2 a^3 )q^2 =
1 2 1 2 1 2 1 2
√^2 10 − √^1 10 √^1 10 √^2 10
3 2 −
3 2 −
3 2 3 2
q 3 =
q˜ 3
||q˜ 3 || 2
3 2 −
3 2 −
3 2 3 2
1 2 −
1 2 −
1 2 1 2
c) Implementing the QR factorization and running it to decompose A, we obtain the
following matrices:
This agrees with our computation in part (b). The rest of calculations above can also be
verified.
Problem 2: For the data in problem 1, construct the least squares approximation of the
form be
ax , and compute the error.
Solution: Instead directly minimizing the least squares error to
y = be
ax ,
we can convert this problem to
log y = log b + ax. (3)
The resulting system is
Au =
1 x 1
1 x 2
1 x 3
1 x 4
log b
a
log y 1
log y 2
log y 3
log y 4
= b.
For the data given in (1), we have
log b
a
log 2
log 3
log 5
log 6
QR factorization of A gives
q 1 q 2 q 3
1 2
√^2 10 1 2
√^1 10 1 2
√^1 10 1 2
√^2 10
|| q˜ 1 || 2 q
T 1 a^2
0 || q˜ 2 || 2
Thus, (don’t confuse two different entities denoted as b below)
[ log b
a
u∗
− 1 Q
T b =
Hence, log b = 0.4858, a = 0.2708, or
b = e
The error is
||Au
∗ − b|| 2 =
log 2
log 3
log 5
log 6
Note that this error corresponds to the modified problem (3).
Section 8.5, Problem 4: Find the general continuous least squares trigonometric poly-
nomial Sn(x) for f (x) = e
x on [−π, π].
Solution: The continuous least squares approximation Sn(x) is in the form
Sn(x) =
a 0
∑^ n
k=
(ak cos kx + bk sin kx),
where
a 0 =
π
∫ (^) π
−π
f (x) dx,
ak =
π
∫ (^) π
−π
f (x) cos kx dx,
bk =
π
π
−π
f (x) sin kx dx,
with k = 1, 2 ,.. .. Thus,
a 0 =
π
∫ (^) π
−π
e
x dx =
π
e
x
x=π
x=−π
π
(e
π − e
−π ), X
ak =
π
∫ (^) π
−π
e
x cos kx dx,
bk =
π
∫ (^) π
−π
e
x sin kx dx.
To determine ak and bk we need to evaluate
e
x cos kx dx and
e
x sin kx dx, respectively.
Integrating the first integral by parts twice, we have
∫
e
x cos kx dx = e
x sin^ kx
k
e
x sin^ kx
k
dx = e
x sin^ kx
k
x cos^ kx
k^2
e
x cos^ kx
k^2
dx.
Multiplying both sides by k
2 , we obtain
k
2
e
x cos kx dx = ke
x sin kx + e
x cos kx −
e
x cos kx dx,
or
∫
e
x cos kx dx =
ke
x sin kx
k^2 + 1
e
x cos kx
k^2 + 1
Thus,
ak =
π
∫ (^) π
−π
e
x cos kx dx
π(k^2 + 1)
ke
x sin kx + e
x cos kx
]x=π
x=−π
k
π(k^2 + 1)
e
π − e
−π
Similarly,
∫
e
x sin kx dx = −
ke
x cos kx
k^2 + 1
e
x sin kx
k^2 + 1
Thus,
bk =
π
π
−π
e
x sin kx dx
π(k^2 + 1)
− ke
x cos kx + e
x sin kx
]x=π
x=−π
k · (−1)
k
π(k^2 + 1)
e
π − e
−π
Thus, the continuous least squares trigonometric polynomial is
Sn(x) =
2 π
(e
π − e
−π ) +
∑^ n
k=
k
π(k^2 + 1)
e
π − e
−π
cos kx −
k · (−1)
k
π(k^2 + 1)
e
π − e
−π
sin kx
e
π − e
−π
π
n ∑
k=
k
(k
2
(cos kx − k sin kx)
Section 8.5, Problem 7(a): Determine the discrete least squares trigonometric polyno-
mial Sn(x) for f (x) = cos 2x, using m = 4, n = 2, on the interval [−π, π].
Solution: We use the notation of Theorem 8.13, which states that the constants in
the summation
Sn(x) =
a 0
n− 1 ∑
k=
(ak cos kx + bk sin kx),
are
ak =
m
2 m− 1 ∑
j=
yj cos kxj , for each k = 0, 1 ,... , n,
and
bk =
m
2 m− 1 ∑
j=
yj sin kxj , for each k = 1, 2 ,... , n − 1.
For our problem, we will find the discrete least squares polynomial of degree n = 2, S 2 (x).
For m = 4, the nodes are
xj = −π +
j
m
π and yj = f (xj ) = cos 2xj , for j = 0, 1 ,... , 7. (2m − 1 = 7)
The trigonometric polynomial is
S 2 (x) =
a 0
where
ak =
j=
yj cos kxj =
j=
cos 2xj cos kxj , for each k = 0, 1 , 2. (n = 2),
bk =
j=
yj sin kxj =
j=
cos 2xj sin kxj , for k = 1,
and the coefficients are
a 0 =
j=
cos
− π +
j
π
cos
− π +
j
π
cos(− 2 π) + cos
3 π
π
π
3 π
a 1 =
7 ∑
j=
cos
− π +
j
π
cos
− π +
j
π
cos(− 2 π) cos(−π) + cos
3 π
cos
3 π
π
π
cos
π
π
cos
π
π
3 π
cos
3 π
a 2 =
j=
cos
− π +
j
π
cos
− π +
j
π
cos(− 2 π) cos(− 2 π) + cos
3 π
2
cos
3 π
2
cos(−π) cos(−π)
cos
π
cos
π
π
cos
π
3 π
cos
3 π
b 1 =
j=
cos
− π +
j
π
sin
− π +
j
π
cos(− 2 π) sin(−π) + cos
3 π
2
sin
3 π
4
π
2
π
sin
π
π
sin
π
π
3 π
sin
3 π
Thus, the trigonometric least squares polynomial S 2 (x) defined in equation (5) is S 2 (x) =
cos 2x. X
Section 8.5, Problem 15: Show that the functions
φ 0 (x) =
1 2 , φ 1 (x) = cos x,... , φn(x) = cos nx,
φn+1(x) = sin x,... , φ 2 n− 1 (x) = sin(n − 1)x
are orthogonal on [−π, π] with respect to w(x) ≡ 1.
Solution: {φ 0 , φ 1 ,... , φn} is said to be an orthogonal set of functions for the interval
[a, b] with respect to the weight function w if
b
a
φj (x)φk(x)w(x) dx =
0 , when j 6 = k,
αk > 0 , when j = k.
Note that
∫ (^) π
−π
cos jx cos kx dx =
0 , when j 6 = k,
π, when j = k.
π
−π
sin jx sin kx dx =
0 , when j 6 = k,
π, when k = k.
∫ (^) π
−π
dx =
π
2
∫ (^) π
−π
cos jx sin kx dx = 0 , for all j, k
∫ (^) π
−π
cos kx dx = 0 , for all k
∫ (^) π
−π
sin kx dx = 0 , for all k
Thus, the functions in (6) are orthogonal on [−π, π] with respect to w(x) ≡ 1.