Assignment 3 Answer
Assignment 3 Answer
Group 1
Question 1
Find the linear least squares polynomial approximation to f (x) on the indi-
cated interval if
Question 2
Find the least squares polynomial approximation of degree 2 to the functions
and intervals in Question 1 as the following
1
(a) . f (x) = x2 + 3x + 2, x ∈ [0, 1]
(b) . f (x) = x3 , x ∈ [0, 2]
1
(c) . f (x) = , x ∈ [1, 3]
x
(d) . f (x) = ex , x ∈ [0, 2]
1 1
(e) . f (x) = cos x + sin 2x, x ∈ [0, 1]
2 3
(f ) . f (x) = x ln x, x ∈ [1, 3]
Question 3
Find the least squares polynomial approximation of degree 2 on the interval
[−1, 1] for the functions in Question 1 as the following
Question 4
Use the Gram-Schmidt Orthonormalization process to construct ϕ0 (x), ϕ1 (x),
ϕ2 (x) and ϕ3 (x) for the following intervals
(a) . [0, 1]
(b) . [0, 2]
(c) . [1, 3]
2
Question 5
Repeat Question 1 using the results of Question 4.
Conclusion
Group 1 uses Microsoft Excel and MATLAB as an available software to execute
the solutions and utilizes online LATEXwebsite https://www.overleaf.
com to wrap up the article.
References
[1] R.L. Burden, J.D. Faires, and A.M. Burden. Numerical Analysis. Cengage
Learning, 2015.
3
Question 1
a)
The normal equations for 𝑃1 (𝑥) = 𝑎1 𝑥 + 𝑎0 are
1 1 1
𝑎0 ∫0 1 𝑑𝑥 + 𝑎1 ∫0 𝑥 𝑑𝑥 = ∫0 (𝑥 2 + 3𝑥 + 2) 𝑑𝑥,
1 1 1
𝑎0 ∫0 𝑥 𝑑𝑥 + 𝑎1 ∫0 𝑥 2 𝑑𝑥 = ∫0 (𝑥 3 + 3𝑥 2 + 2𝑥) 𝑑𝑥,
Thus, the linear least squares polynomial approximation for 𝑓(𝑥) = 𝑥 2 + 3𝑥 + 2 on [0, 1] is
11
𝑃1 (𝑥) = 4𝑥 + . (See Figure 1.1.)
6
y
6
5
𝑦 = 𝑃1 (𝑥)
4
𝑦 = 𝑥 2 + 3𝑥 + 2
3
0 x
0 0.2 0.4 0.6 0.8 1
Figure 1.1
b)
The normal equations for 𝑃1 (𝑥) = 𝑎1 𝑥 + 𝑎0 are
2 2 2
𝑎0 ∫0 1 𝑑𝑥 + 𝑎1 ∫0 𝑥 𝑑𝑥 = ∫0 𝑥 3 𝑑𝑥,
2 2 2
𝑎0 ∫0 𝑥 𝑑𝑥 + 𝑎1 ∫0 𝑥 2 𝑑𝑥 = ∫0 𝑥 4 𝑑𝑥,
y
8
𝑦 = 𝑥3
6
𝑦 = 𝑃1 (𝑥)
2
0 x
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
-2
-4
Figure 1.2
c)
The normal equations for 𝑃1 (𝑥) = 𝑎1 𝑥 + 𝑎0 are
3 3 31
𝑎0 ∫1 1 𝑑𝑥 + 𝑎1 ∫1 𝑥 𝑑𝑥 = ∫1 𝑥
𝑑𝑥,
3 3 3
𝑎0 ∫1 𝑥 𝑑𝑥 + 𝑎1 ∫1 𝑥 2 𝑑𝑥 = ∫1 1 𝑑𝑥,
1
Thus, the linear least squares polynomial approximation for 𝑓(𝑥) = 𝑥 on [1, 3] is 𝑃1 (𝑥) =
−0.29584𝑥 + 1.14098. (See Figure 1.3.)
Figure 1.3
y
1.2
0.8
0.6
𝑦 = 𝑃1 (𝑥)
1
0.4 𝑦=
𝑥
0.2
0 x
1 1.5 2 2.5 3
d)
The normal equations for 𝑃1 (𝑥) = 𝑎1 𝑥 + 𝑎0 are
2 2 2
𝑎0 ∫0 1 𝑑𝑥 + 𝑎1 ∫0 𝑥 𝑑𝑥 = ∫0 𝑒 𝑥 𝑑𝑥,
2 2 2
𝑎0 ∫0 𝑥 𝑑𝑥 + 𝑎1 ∫0 𝑥 2 𝑑𝑥 = ∫0 𝑥𝑒 𝑥 𝑑𝑥,
Thus, the linear least squares polynomial approximation for 𝑓(𝑥) = 𝑒 𝑥 on [0, 2] is 𝑃1 (𝑥) =
3𝑥 + 0.194528. (See Figure 1.4.)
y
8
4 𝑦 = 𝑃1 (𝑥)
3 𝑦 = 𝑒𝑥
0 x
0 0.5 1 1.5 2
Figure 1.4
e)
The normal equations for 𝑃1 (𝑥) = 𝑎1 𝑥 + 𝑎0 are
1 1 1 1 1
𝑎0 ∫0 1 𝑑𝑥 + 𝑎1 ∫0 𝑥 𝑑𝑥 = ∫0 (2 cos 𝑥 + 3 sin 2𝑥) 𝑑𝑥,
1 1 1 x x
𝑎0 ∫0 𝑥 𝑑𝑥 + 𝑎1 ∫0 𝑥 2 𝑑𝑥 = ∫0 (2 cos x + 3 sin 2x) 𝑑𝑥,
1 1
Thus, the linear least squares polynomial approximation for 𝑓(𝑥) = cos 𝑥 + sin 2𝑥 on [0,
2 3
1] is 𝑃1 (𝑥) = 0.091671𝑥 + 0.610924. (See Figure 1.5.)
y
0.75
𝑦 = 𝑃1 (𝑥)
0.7
0.65
0.6 1 1
𝑦= cos 𝑥 + sin 2𝑥
2 3
0.55
0.5 x
0 0.2 0.4 0.6 0.8 1
Figure 1.5
f)
The normal equations for 𝑃1 (𝑥) = 𝑎1 𝑥 + 𝑎0 are
3 3 3
𝑎0 ∫1 1 𝑑𝑥 + 𝑎1 ∫1 𝑥 𝑑𝑥 = ∫1 𝑥 ln 𝑥 𝑑𝑥,
3 3 3
𝑎0 ∫1 𝑥 𝑑𝑥 + 𝑎1 ∫1 𝑥 2 𝑑𝑥 = ∫1 𝑥 2 ln 𝑥 𝑑𝑥,
Thus, the linear least squares polynomial approximation for 𝑓(𝑥) = 𝑥 ln 𝑥 on [1, 3] is 𝑃1 (𝑥) =
5
3
𝑥 − 1.861456. (See Figure 1.6.)
y
3.5
2.5
2 𝑦 = 𝑃1 (𝑥)
1.5
𝑦 = 𝑥 ln 𝑥
1
0.5
0 x
1 1.5 2 2.5 3
-0.5
Figure 1.6
Question 2
𝑎0 = 2, 𝑎1 = 3, 𝑎2 = 1.
𝑎0 = 0.4, 𝑎1 = −2.4, 𝑎2 = 3.
Consequently, the least squares polynomial approximation of degree 2 for 𝑓(𝑥) = 𝑥 3 on [0, 2] is
𝑃2 (𝑥) = 3𝑥 2 − 2.4𝑥 + 0.4.
1
(c). 𝑓(𝑥) = 𝑥 , [1, 3]
1 1
(e). 𝑓(𝑥) = 2 cos 𝑥 + 3 sin 2𝑥 , [0, 1]
ans = 2
ans = 0
ans = 2/3
ans = 0
ans = 2/5
ans = 14/3
ans = 2
ans = 26/15
Therefore, 𝑃2 = 𝑥 2 + 3𝑥 + 2
b)
1 1 1 1
𝑎0 ∫ 1 𝑑𝑥 + 𝑎1 ∫ 𝑥 𝑑𝑥 + 𝑎2 ∫ 𝑥 2 𝑑𝑥 = ∫ 𝑥 3
−1 −1 −1 −1
1 1 1 1
𝑎0 ∫ 𝑥 𝑑𝑥 + 𝑎1 ∫ 𝑥 2 𝑑𝑥 + 𝑎2 ∫ 𝑥 3 𝑑𝑥 = ∫ 𝑥(𝑥 3 )
−1 −1 −1 −1
1 1 1 1
𝑎0 ∫ 𝑥 2 𝑑𝑥 + 𝑎1 ∫ 𝑥 3 𝑑𝑥 + 𝑎2 ∫ 𝑥 4 𝑑𝑥 = ∫ 𝑥 2 (𝑥 3 )
−1 −1 −1 −1
2
2𝑎0 + 0𝑎1 + 𝑎 = 0
3 2
2
0𝑎0 + 𝑎 + 0𝑎2 = 0.4
3 1
2 2
𝑎0 + 0𝑎1 + 𝑎2 = 0
3 5
We use Matlab to calculate the least square polynomials of degree 2
Therefore, 𝑃2 = 0.6𝑥
c)
1 1 1 1
1
𝑎0 ∫ 1 𝑑𝑥 + 𝑎1 ∫ 𝑥 𝑑𝑥 + 𝑎2 ∫ 𝑥 2 𝑑𝑥 = ∫
−1 −1 −1 −1 𝑥
1 1 1 1
1
𝑎0 ∫ 𝑥 𝑑𝑥 + 𝑎1 ∫ 𝑥 2 𝑑𝑥 + 𝑎2 ∫ 𝑥 3 𝑑𝑥 = ∫ 𝑥 ( )
−1 −1 −1 −1 𝑥
1 1 1 1
1
𝑎0 ∫ 𝑥 2 𝑑𝑥 + 𝑎1 ∫ 𝑥 3 𝑑𝑥 + 𝑎2 ∫ 𝑥 4 𝑑𝑥 = ∫ 𝑥 2 ( )
−1 −1 −1 −1 𝑥
2
2𝑎0 + 0𝑎1 + 𝑎 = 0
3 2
2
0𝑎0 + 𝑎 + 0𝑎2 = 2
3 1
2 2
𝑎
3 0
+ 0𝑎1 + 𝑎
5 2
=0
We use Matlab to calculate the least square polynomials of degree 2
Therefore, 𝑃2 = 3𝑥
d)
1 1 1 1
𝑎0 ∫ 1 𝑑𝑥 + 𝑎1 ∫ 𝑥 𝑑𝑥 + 𝑎2 ∫ 𝑥 2 𝑑𝑥 = ∫ 𝑒 𝑥
−1 −1 −1 −1
1 1 1 1
𝑎0 ∫ 𝑥 𝑑𝑥 + 𝑎1 ∫ 𝑥 2 𝑑𝑥 + 𝑎2 ∫ 𝑥 3 𝑑𝑥 = ∫ 𝑥𝑒 𝑥
−1 −1 −1 −1
1 1 1 1
𝑎0 ∫ 𝑥 2 𝑑𝑥 + 𝑎1 ∫ 𝑥 3 𝑑𝑥 + 𝑎2 ∫ 𝑥 4 𝑑𝑥 = ∫ 𝑥 2 (𝑒 𝑥 )
−1 −1 −1 −1
2
2𝑎0 + 0𝑎1 + 𝑎 = 2.3504024
3 2
2
0𝑎0 + 𝑎 + 0𝑎2 = 0.7357589
3 1
2 2
𝑎0 + 0𝑎1 + 𝑎2 = 0.878885
3 5
Therefore, 𝑃2 = 0.5367215𝑥 2 + 1.10363832𝑥 + 0.99629404
e)
1 1 1 1
1 1
𝑎0 ∫ 1 𝑑𝑥 + 𝑎1 ∫ 𝑥 𝑑𝑥 + 𝑎2 ∫ 𝑥 2 𝑑𝑥 = ∫ cos 𝑥 + sin 2𝑥 𝑑𝑥
−1 −1 −1 −1 2 3
1 1 1 1
1 1
𝑎0 ∫ 𝑥 𝑑𝑥 + 𝑎1 ∫ 𝑥 2 𝑑𝑥 + 𝑎2 ∫ 𝑥 3 𝑑𝑥 = ∫ 𝑥( cos 𝑥 + sin 2𝑥) 𝑑𝑥
−1 −1 −1 −1 2 3
1 1 1 1
1 1
𝑎0 ∫ 𝑥 2 𝑑𝑥 + 𝑎1 ∫ 𝑥 3 𝑑𝑥 + 𝑎2 ∫ 𝑥 4 𝑑𝑥 = ∫ ( cos 𝑥 + sin 2𝑥)𝑥 2 𝑑𝑥
−1 −1 −1 −1 2 3
2
2𝑎0 + 0𝑎1 + 𝑎 = 0.841470985
3 2
2
0𝑎0 + 𝑎 + 0𝑎2 = 0.290265183
3 1
2 2
𝑎0 + 0𝑎1 + 𝑎2 = 0.23913363
3 5
Therefore, 𝑃2 = −0.2326314𝑥 2 + 0.43539777𝑥 + 0.4982793
f)
1 1 1 1
𝑎0 ∫ 1 𝑑𝑥 + 𝑎1 ∫ 𝑥 𝑑𝑥 + 𝑎2 ∫ 𝑥 2 𝑑𝑥 = ∫ 𝑥 𝑙𝑛 𝑥 𝑑𝑥
−1 −1 −1 −1
1 1 1 1
𝑎0 ∫ 𝑥 𝑑𝑥 + 𝑎1 ∫ 𝑥 2 𝑑𝑥 + 𝑎2 ∫ 𝑥 3 𝑑𝑥 = ∫ 𝑥(𝑥 𝑙𝑛 𝑥) 𝑑𝑥
−1 −1 −1 −1
1 1 1 1
𝑎0 ∫ 𝑥 2 𝑑𝑥 + 𝑎1 ∫ 𝑥 3 𝑑𝑥 + 𝑎2 ∫ 𝑥 4 𝑑𝑥 = ∫ 𝑥 2 (𝑥 𝑙𝑛 𝑥) 𝑑𝑥
−1 −1 −1 −1
1
As ∫−1 𝑥 𝑙𝑛 𝑥 𝑑𝑥 does not exist so no approximation holds in [-1,1]
Question 4
(a) . [0, 1]
(b) . [0, 2]
(c) . [1, 3]
Solution
Note that
The set of polynomial functions ϕ0 , ϕ1 , · · · , ϕn defined in the following way is
orthogonal on [a, b] with respect to the weight function ω
ϕ0 (x) ≡ 1 ϕ1 (x) = x − B1 for each x in [a, b]
As well as R1 R1 2
3
x dx x dx 1
B2 = R−1
1 = 0 =⇒ C2 = R−11 =
x2 dx 1 dx 3
−1 −1
implies
1 1
ϕ2 (x) = (x − B2 )ϕ1 (x) − C2 ϕ0 (x) = (x − 0)x − = x2 −
3 3
Then R1 R1
−1
x · (x2 − 13 )2 dx −1
x2 · (x2 − 13 ) dx 4
B3 = R1 = 0 =⇒ C3 = R1 =
(x2 − 13 )2 dx 2
x dx 15
−1 −1
1
implies
1 4 3
ϕ3 (x) = (x − B3 )ϕ2 (x) − C3 ϕ1 (x) = (x − 0)(x2 − ) − x = x3 − x
3 15 5
(a).
Using the Gram-Schmidt process with ω ≡ 1 and ϕ0 (x) ≡ 1 for each x in [0, 1]
gives: R1
x dx 1 1
B1 = R01 = =⇒ ϕ1 (x) = (x − B1 )ϕ0 (x) = x −
1 dx 2 2
0
As well as R1 R1
0
x · (x − 21 )2 dx 1 0
x · (x − 12 ) dx 1
B2 = R1 = =⇒ C2 = R1 =
(x − 12 )2 dx 2 1 dx 12
0 0
implies
1 1 1 1
ϕ2 (x) = (x − B2 )ϕ1 (x) − C2 ϕ0 (x) = (x − )(x − ) − = x2 − x +
2 2 12 6
Then R
1 R1
0
x · (x2 − x + 61 )2 dx 1 0
x · (x − 21 ) · (x2 − x + 16 ) dx 1
B3 = R1 = =⇒ C3 = R1 =
(x2 − x + 16 )2 dx 2 1 2
(x − 2 ) dx 15
0 0
implies
3 3 1
ϕ3 (x) = (x − B3 )ϕ2 (x) − C3 ϕ1 (x) = x3 − x2 + x −
2 5 20
(b).
Using the Gram-Schmidt process with ω ≡ 1 and ϕ0 (x) ≡ 1 for each x in [0, 1]
gives: R2
x dx
B1 = R02 = 1 =⇒ ϕ1 (x) = (x − B1 )ϕ0 (x) = x − 1
0
1 dx
As well as R2 R2
0
x · (x − 1)2 dx 0
x · (x − 1) dx 1
B2 = R2 = 1 =⇒ C2 = R2 =
(x − 1)2 dx 1 dx 3
0 0
implies
1 2
ϕ2 (x) = (x − B2 )ϕ1 (x) − C2 ϕ0 (x) = (x − 1)(x − 1) − = x2 − 2x +
3 3
Then R
2 R2
0
x(x2 − 2x + 32 )2 dx 0
x · (x − 1) · (x2 − 2x + 23 ) dx 4
B3 = R 2 = 1 =⇒ C3 = R2 =
(x2 − 2x + 23 )2 dx (x − 1)2 dx 15
0 0
2
implies
12 2
ϕ3 (x) = (x − B3 )ϕ2 (x) − C3 ϕ1 (x) = x3 − 3x2 + x−
5 5
(c).
Using the Gram-Schmidt process with ω ≡ 1 and ϕ0 (x) ≡ 1 for each x in [0, 1]
gives: R3
x dx
B1 = R13 = 2 =⇒ ϕ1 (x) = (x − B1 )ϕ0 (x) = x − 2
1
1 dx
As well as R3 R3
1
x · (x − 2)2 dx 1
x · (x − 2) dx 1
B2 = R3 = 2 =⇒ C2 = R3 =
(x − 2)2 dx 1 dx 3
1 1
implies
1 11
ϕ2 (x) = (x − B2 )ϕ1 (x) − C2 ϕ0 (x) = (x − 2)(x − 2) − = x2 − 4x +
3 3
Then R
3 11 2
R3 11
1
x(x2 − 4x + 3
) dx 1
x · (x − 1) · (x2 − 4x + 3
) dx 4
B3 = R 3 = 2 =⇒ C3 = R3 =
(x2 − 4x + 11 2
) dx (x − 1)2 dx 15
1 3 1
implies
57 34
ϕ3 (x) = (x − B3 )ϕ2 (x) − C3 ϕ1 (x) = x3 − 6x2 + x−
5 5
Then, we are done. ■