0% found this document useful (0 votes)
55 views

Assignment 3 Answer

The document contains questions regarding finding linear and quadratic least squares polynomial approximations for various functions over given intervals. Group 1, led by Zhou Yuhao, will use Microsoft Excel, MATLAB and LaTeX to solve the problems and report their work. They are asked to find linear and quadratic approximations for functions like x2, e x, 1/x and others over intervals like [0,1], [1,3], and [-1,1]. They are also asked to apply the Gram-Schmidt orthonormalization process to construct orthogonal polynomials over the given intervals.

Uploaded by

dina
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Assignment 3 Answer

The document contains questions regarding finding linear and quadratic least squares polynomial approximations for various functions over given intervals. Group 1, led by Zhou Yuhao, will use Microsoft Excel, MATLAB and LaTeX to solve the problems and report their work. They are asked to find linear and quadratic approximations for functions like x2, e x, 1/x and others over intervals like [0,1], [1,3], and [-1,1]. They are also asked to apply the Gram-Schmidt orthonormalization process to construct orthogonal polynomials over the given intervals.

Uploaded by

dina
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Assignment 3

Orthogonal polynomials [1]

Group 1

Group Leader: ZHOU YUHAO

ALYA NAZURAH BINTI NAZEER KHAN 17172511/1


NUR ASHIQIN BINTI JOHAN @ JASMI 17145296/2
SHIVANESH A/L SIVAKUMAR 17181773/1
ZHOU YUHAO 17131708/1
SAFA MALIK 17199694/1

Question 1
Find the linear least squares polynomial approximation to f (x) on the indi-
cated interval if

(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 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

(a) . f (x) = x2 + 3x + 2, x ∈ [−1, 1]


(b) . f (x) = x3 , x ∈ [−1, 1]
1
(c) . f (x) = , x ∈ [−1, 1]
x
(d) . f (x) = ex , x ∈ [−1, 1]
1 1
(e) . f (x) = cos x + sin 2x, x ∈ [−1, 1]
2 3
(f ) . f (x) = x ln x, x ∈ [−1, 1]

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.

(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]

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𝑥) 𝑑𝑥,

Performing the integration yields


1 23 1 1 9
𝑎0 + 𝑎1 = , 𝑎0 + 𝑎1 = .
2 6 2 3 4
These two equations in two unknowns can be solved to obtain
11
𝑎0 = 6
𝑎𝑛𝑑 𝑎1 = 4.

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 𝑑𝑥,

Performing the integration yields


8 32
2𝑎0 + 2𝑎1 = 4, 2𝑎0 + 𝑎1 = .
3 5

These two equations in two unknowns can be solved to obtain


8 18
𝑎0 = − 5 𝑎𝑛𝑑 𝑎1 = 5
.
Thus, the linear least squares polynomial approximation for 𝑓(𝑥) = 𝑥 3 on [0, 2] is 𝑃1 (𝑥) =
18 8
𝑥 − . (See Figure 1.2.)
5 5

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 𝑑𝑥,

Performing the integration yields


26
2𝑎0 + 4𝑎1 = ln(3), 4𝑎0 + 𝑎 = 2.
3 1

These two equations in two unknowns can be solved to obtain


𝑎0 = 1.14098 𝑎𝑛𝑑 𝑎1 = −0.29584.

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 𝑥𝑒 𝑥 𝑑𝑥,

Performing the integration yields


8
2𝑎0 + 2𝑎1 = e2 − 1, 2𝑎0 + 𝑎1 = 𝑒 2 + 1.
3

These two equations in two unknowns can be solved to obtain


𝑎0 = 0.194528 𝑎𝑛𝑑 𝑎1 = 3.

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) 𝑑𝑥,

Performing the integration yields


1 − cos 2 − 3 sin 1 − 1
𝑎0 + 𝑎1 = ,
2 6
1 1 sin 2 − 2 cos 2 + 6 sin 1 + 6 cos 1 − 6
𝑎0 + 𝑎1 = .
2 3 12

These two equations in two unknowns can be solved to obtain


𝑎0 = 0.610924 𝑎𝑛𝑑 𝑎1 = 0.091671.

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 𝑥 𝑑𝑥,

Performing the integration yields


9 ln(3) 26 26
2𝑎0 + 4𝑎1 = − 2, 4𝑎0 + 𝑎1 = 9 ln 3 − .
2 3 9

These two equations in two unknowns can be solved to obtain


5
𝑎0 = −1.861456 𝑎𝑛𝑑 𝑎1 = 3.

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

(a). 𝑓(𝑥) = 𝑥 2 + 3𝑥 + 2, [0, 1]

The normal equations for 𝑃2 (𝑥) = 𝑎2 𝑥 2 + 𝑎1 𝑥 + 𝑎0 are


1 1 1 1
𝑎0 ∫ 1 𝑑𝑥 + 𝑎1 ∫ 𝑥 𝑑𝑥 + 𝑎2 ∫ 𝑥 2 𝑑𝑥 = ∫ 𝑥 2 + 3𝑥 + 2 𝑑𝑥 ,
0 0 0 0
1 1 1 1
𝑎0 ∫ 𝑥 𝑑𝑥 + 𝑎1 ∫ 𝑥 2 𝑑𝑥 + 𝑎2 ∫ 𝑥 3 𝑑𝑥 = ∫ 𝑥(𝑥 2 + 3𝑥 + 2) 𝑑𝑥,
0 0 0 0
1 1 1 1
𝑎0 ∫ 𝑥 2 𝑑𝑥 + 𝑎1 ∫ 𝑥 3 𝑑𝑥 + 𝑎2 ∫ 𝑥 4 𝑑𝑥 = ∫ 𝑥 2 (𝑥 2 + 3𝑥 + 2) 𝑑𝑥 .
0 0 0 0

Performing the integration yields


1 1 23
𝑎0 + 𝑎1 + 𝑎2 = ,
2 3 6
1 1 1 9
𝑎0 + 𝑎1 + 𝑎2 = ,
2 3 4 4
1 1 1 97
𝑎0 + 𝑎1 + 𝑎2 = .
3 4 5 60
These three equations in three unknowns can be solved to obtain

𝑎0 = 2, 𝑎1 = 3, 𝑎2 = 1.

Consequently, the least squares polynomial approximation of degree 2 for 𝑓(𝑥) = 𝑥 2 + 3𝑥 + 2 on


[0, 1] is 𝑃2 (𝑥) = 𝑥 2 + 3𝑥 + 2.

(b). 𝑓(𝑥) = 𝑥 3 , [0, 2]

The normal equations for 𝑃2 (𝑥) = 𝑎2 𝑥 2 + 𝑎1 𝑥 + 𝑎0 are


2 2 2 2
𝑎0 ∫ 1 𝑑𝑥 + 𝑎1 ∫ 𝑥 𝑑𝑥 + 𝑎2 ∫ 𝑥 2 𝑑𝑥 = ∫ 𝑥 3 𝑑𝑥 ,
0 0 0 0
2 2 2 2
𝑎0 ∫ 𝑥 𝑑𝑥 + 𝑎1 ∫ 𝑥 2 𝑑𝑥 + 𝑎2 ∫ 𝑥 3 𝑑𝑥 = ∫ 𝑥 4 𝑑𝑥,
0 0 0 0
2 2 2 2
𝑎0 ∫ 𝑥 2 𝑑𝑥 + 𝑎1 ∫ 𝑥 3 𝑑𝑥 + 𝑎2 ∫ 𝑥 4 𝑑𝑥 = ∫ 𝑥 5 𝑑𝑥 .
0 0 0 0

Performing the integration yields


8
2𝑎0 + 2𝑎1 + 𝑎2 = 4,
3
8 32
2𝑎0 + 𝑎1 + 4𝑎2 = ,
3 5
8 32 32
𝑎0 + 4𝑎1 + 𝑎2 = .
3 5 3
These three equations in three unknowns can be solved to obtain

𝑎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]

The normal equations for 𝑃2 (𝑥) = 𝑎2 𝑥 2 + 𝑎1 𝑥 + 𝑎0 are


3 3 3 3
1
𝑎0 ∫ 1 𝑑𝑥 + 𝑎1 ∫ 𝑥 𝑑𝑥 + 𝑎2 ∫ 𝑥 2 𝑑𝑥 = ∫ 𝑑𝑥 ,
1 1 1 1 𝑥
3 3 3 3
𝑎0 ∫ 𝑥 𝑑𝑥 + 𝑎1 ∫ 𝑥 2 𝑑𝑥 + 𝑎2 ∫ 𝑥 3 𝑑𝑥 = ∫ 1 𝑑𝑥,
1 1 1 1
3 3 3 3
2 3 4
𝑎0 ∫ 𝑥 𝑑𝑥 + 𝑎1 ∫ 𝑥 𝑑𝑥 + 𝑎2 ∫ 𝑥 𝑑𝑥 = ∫ 𝑥 𝑑𝑥 .
1 1 1 1

Performing the integration yields


26
2𝑎0 + 4𝑎1 + 𝑎 = ln 3,
3 2
26
4𝑎0 + 𝑎 + 20𝑎2 = 2,
3 1
26 242
𝑎0 + 20𝑎1 + 𝑎 = 4.
3 5 2
These three equations in three unknowns can be solved to obtain

𝑎0 = 1.723534, 𝑎1 = −0.931351, 𝑎2 = 0.158878.


1
Consequently, the least squares polynomial approximation of degree 2 for 𝑓(𝑥) = 𝑥 on [1, 3] is
𝑃2 (𝑥) = 0.158878𝑥 2 − 0.931351𝑥 + 1.723534.

(d). 𝑓(𝑥) = 𝑒 𝑥 , [0, 2]

The normal equations for 𝑃2 (𝑥) = 𝑎2 𝑥 2 + 𝑎1 𝑥 + 𝑎0 are


2 2 2 2
𝑎0 ∫ 1 𝑑𝑥 + 𝑎1 ∫ 𝑥 𝑑𝑥 + 𝑎2 ∫ 𝑥 2 𝑑𝑥 = ∫ 𝑒 𝑥 𝑑𝑥 ,
0 0 0 0
2 2 2 2
𝑎0 ∫ 𝑥 𝑑𝑥 + 𝑎1 ∫ 𝑥 2 𝑑𝑥 + 𝑎2 ∫ 𝑥 3 𝑑𝑥 = ∫ 𝑥𝑒 𝑥 𝑑𝑥,
0 0 0 0
2 2 2 2
𝑎0 ∫ 𝑥 𝑑𝑥 + 𝑎1 ∫ 𝑥 𝑑𝑥 + 𝑎2 ∫ 𝑥 𝑑𝑥 = ∫ 𝑥 2 𝑒 𝑥 𝑑𝑥.
2 3 4
0 0 0 0

Performing the integration yields


8
2𝑎0 + 2𝑎1 + 𝑎2 = 𝑒 2 − 1,
3
8
2𝑎0 + 𝑎1 + 4𝑎2 = 𝑒 2 + 1,
3
8 32
𝑎0 + 4𝑎1 + 𝑎2 = 2𝑒 2 − 2.
3 5
These three equations in three unknowns can be solved to obtain

𝑎0 = 1.167168, 𝑎1 = 0.082079, 𝑎2 = 1.45896.


Consequently, the least squares polynomial approximation of degree 2 for 𝑓(𝑥) = 𝑒 𝑥 on [0, 2] is
𝑃2 (𝑥) = 1.45896𝑥 2 + 0.082079𝑥 + 1.167168.

1 1
(e). 𝑓(𝑥) = 2 cos 𝑥 + 3 sin 2𝑥 , [0, 1]

The normal equations for 𝑃2 (𝑥) = 𝑎2 𝑥 2 + 𝑎1 𝑥 + 𝑎0 are


1 1 1 1
2
1 1
𝑎0 ∫ 1 𝑑𝑥 + 𝑎1 ∫ 𝑥 𝑑𝑥 + 𝑎2 ∫ 𝑥 𝑑𝑥 = ∫ cos 𝑥 + sin 2𝑥 𝑑𝑥 ,
0 0 0 0 2 3
1 1 1 1
1 1
𝑎0 ∫ 𝑥 𝑑𝑥 + 𝑎1 ∫ 𝑥 2 𝑑𝑥 + 𝑎2 ∫ 𝑥 3 𝑑𝑥 = ∫ 𝑥 ( cos 𝑥 + sin 2𝑥) 𝑑𝑥,
0 0 0 0 2 3
1 1 1 1
1 1
𝑎0 ∫ 𝑥 2 𝑑𝑥 + 𝑎1 ∫ 𝑥 3 𝑑𝑥 + 𝑎2 ∫ 𝑥 4 𝑑𝑥 = ∫ 𝑥 2 ( cos 𝑥 + sin 2𝑥) 𝑑𝑥 .
0 0 0 0 2 3

Performing the integration yields


1 1 1 1
𝑎0 + 𝑎1 + 𝑎2 = sin(1) + (− cos(2) + 1),
2 3 2 6
1 1 1 1 1 1 1
𝑎0 + 𝑎1 + 𝑎2 = (sin(1) + cos(1) − 1) + ( sin(2) − cos(2)),
2 3 4 2 3 4 2
1 1 1 1 − cos(2) + 2 sin(2) − 1
𝑎0 + 𝑎1 + 𝑎2 = cos(1) − sin(1) + .
3 4 5 2 12
These three equations in three unknowns can be solved to obtain

𝑎0 = 0.4880058, 𝑎1 = 0.829183, 𝑎2 = −0.7375119.


1
Consequently, the least squares polynomial approximation of degree 2 for 𝑓(𝑥) = 2 cos 𝑥 +
1
3
sin 2𝑥 on [0, 1] is 𝑃2 (𝑥) = −0.7375119𝑥 2 + 0.829183𝑥 + 0.4880058.

(f). 𝑓(𝑥) = 𝑥 ln 𝑥 , [1, 3]

The normal equations for 𝑃2 (𝑥) = 𝑎2 𝑥 2 + 𝑎1 𝑥 + 𝑎0 are


3 3 3 3
𝑎0 ∫ 1 𝑑𝑥 + 𝑎1 ∫ 𝑥 𝑑𝑥 + 𝑎2 ∫ 𝑥 2 𝑑𝑥 = ∫ 𝑥 ln 𝑥 𝑑𝑥 ,
1 1 1 1
3 3 3 3
𝑎0 ∫ 𝑥 𝑑𝑥 + 𝑎1 ∫ 𝑥 2 𝑑𝑥 + 𝑎2 ∫ 𝑥 3 𝑑𝑥 = ∫ 𝑥 2 ln 𝑥 𝑑𝑥,
1 1 1 1
3 3 3 3
𝑎0 ∫ 𝑥 𝑑𝑥 + 𝑎1 ∫ 𝑥 𝑑𝑥 + 𝑎2 ∫ 𝑥 𝑑𝑥 = ∫ 𝑥 3 ln 𝑥 𝑑𝑥 .
2 3 4
1 1 1 1

Performing the integration yields


26 9
2𝑎0 + 4𝑎1 + 𝑎 = −2 + ln 3,
3 2 2
26 26
4𝑎0 + 𝑎1 + 20𝑎2 = 9 ln(3) − ,
3 9
26 242 81
𝑎0 + 20𝑎1 + 𝑎2 = −5 + ln(3).
3 5 4
These three equations in three unknowns can be solved to obtain

𝑎0 = −0.9089635, 𝑎1 = 0.627584, 𝑎2 = 0.25977.


Consequently, the least squares polynomial approximation of degree 2 for 𝑓(𝑥) = 𝑥 ln 𝑥 on [1, 3]
is 𝑃2 (𝑥) = 0.25977𝑥 2 + 0.627584𝑥 − 0.9089635.
Question 3

a) The normal equations for 𝑃(𝑥) = 𝑎2 𝑥 2 + 𝑎1 𝑥 + 𝑎0

We ask MATLAB to calculate the integration of the function given:


1 1 1 1
𝑎0 ∫ 1 𝑑𝑥 + 𝑎1 ∫ 𝑥 𝑑𝑥 + 𝑎2 ∫ 𝑥 2 𝑑𝑥 = ∫ 𝑥 2 + 3𝑥 + 2
−1 −1 −1 −1
1 1 1 1
𝑎0 ∫ 𝑥 𝑑𝑥 + 𝑎1 ∫ 𝑥 𝑑𝑥 + 𝑎2 ∫ 𝑥 𝑑𝑥 = ∫ 𝑥(𝑥 2 + 3𝑥 + 2)
2 3
−1 −1 −1 −1
1 1 1 1
𝑎0 ∫ 𝑥 2 𝑑𝑥 + 𝑎1 ∫ 𝑥 3 𝑑𝑥 + 𝑎2 ∫ 𝑥 4 𝑑𝑥 = ∫ 𝑥 2 (𝑥 2 + 3𝑥 + 2)
−1 −1 −1 −1

ans = 2
ans = 0
ans = 2/3
ans = 0
ans = 2/5
ans = 14/3
ans = 2
ans = 26/15

The integration gives:


2 14
2𝑎0 + 0𝑎1 + 𝑎2 =
3 3
2
0𝑎0 + 𝑎 + 0𝑎2 = 2
3 1
2 2 26
𝑎0 + 0𝑎1 + 𝑎2 =
3 5 15
We use Matlab to calculate the least square polynomials of degree 2
The MATLAB Command Window displays the following reesults

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

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]

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 ϕk (x) = (x − Bk )ϕk−1 (x) − Ck ϕk−2


(SAMPLE).
Using the Gram-Schmidt process with ω ≡ 1 and ϕ0 (x) ≡ 1 for each x in
[−1, 1] gives: R1
x dx
B1 = R−1
1 = 0 =⇒ ϕ1 (x) = (x − B1 )ϕ0 (x) = x
−1
1 dx

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. ■

You might also like