Approximation PDF
Approximation PDF
**4/5/13 ET
Given a set of data points (x1 , y1 ), (x2 , y2 ), . . ., (xm , ym ), a normal and useful practice in many
applications in statistics, engineering and other applied sciences is to construct a curve that is
considered to be the “best fit” for the data, in some sense.
Several types of “fits” can be considered. But the one that is used most in applications is the
“least-squares fit”. Mathematically, the problem is the following:
such that the error E(a0 , a1 , . . . , an ) in the least-squares sense in minimized; that is,
m
X
E(a0 , a1 , . . . , an ) = (yi − a0 − a1 xi − a2 x2i − · · · − an xni )2
i=1
465
466CHAPTER 10. ORTHOGONAL POLYNOMIALS AND LEAST-SQUARES APPROXIMATIONS TO FUNCT
is minimum.
m
∂E X
= −2 (yi − a0 − a1 xi − · · · − an xni )
∂a0
i=1
m
∂E X
= −2 xi (yi − a0 − a1 xi − · · · − an xni )
∂a1
i=1
..
.
m
∂E X
= −2 xni (yi − a0 − a1 xi − · · · − an xni )
∂an
i=1
m
X m
X m
X m
X m
X
a0 1 + a1 x i + a2 x2i + · · · + an xni = yi
i=1 i=1 i=1 i=1 i=1
Xm Xm m
X Xm
a0 x i + a1 x2i + · · · + an xn+1
i = xi y i
i=1 i=1 i=1 i=1
.. ..
. .
m
X m
X m
X m
X
a0 xni + a1 xn+1
i + · · · + an x2n
i = xni yi
i=1 i=1 i=1 i=1
Set
m
X
sk = xki , k = 0, 1, . . . , 2n
i=1
m
X
bk = xki yi , k = 0, 1, . . . , n
i=1
m
X m
X
s0 a0 + s1 a1 + · · · + sn an = b0 (Note that 1= x0i = s0 .)
i=1 i=1
s1 a0 + s2 a1 + · · · + sn+1 an = b1
.. ..
. .
sn a0 + sn+1 a1 + · · · + s2n an = bn
where
s0 s1 ··· sn a0 b0
s1 s2 ··· sn+1 a1 b1
S=
.. .. ,
.. a=
.. ,
b=
.. .
. . . . .
sn sn+1 · · · s2n an bn
Define
x21 xn1
1 x1 ···
1
x2 x22 ··· xn2
1 x23 ··· xn3
V = x3
.. .. .. ..
. . . .
1 xm x2m · · · xnm
Then the above system has the form:
V T V a = b.
The matrix V is known as the Vandermonde matrix, and we have seen in Chapter 6 that
this matrix has full rank if xi ’s are distinct. In this case, the matrix S = V T V is symmetric
and positive definite [Exercise] and is therefore nonsingular. Thus, if xi ’s are distinct, the
equation Sa = b has a unique solution.
468CHAPTER 10. ORTHOGONAL POLYNOMIALS AND LEAST-SQUARES APPROXIMATIONS TO FUNCT
We have described least-squares approximation to fit a set of discrete data. Here we describe
continuous least-square approximations of a function f (x) by using polynomials.
Given a function f (x), continuous on [a, b], find a polynomial Pn (x) of degree at most n:
Pn (x) = a0 + a1 x + a2 x2 + · · · + an xn
such that the integral of the square of the error is minimized. That is,
Z b
E= [f (x) − Pn (x)]2 dx
a
is minimized.
∂E
= 0, i = 0, 1, . . . , n.
∂ai
Since
Z b
E= [f (x) − (a0 + a1 x + a2 x2 + · · · + an xn )]2 dx,
a
Z b
∂E
= −2 [f (x) − a0 − a1 x − a2 x2 − · · · − an xn ] dx
∂a0 a
Z b
∂E
= −2 x[f (x) − a0 − a1 x − a2 x2 − · · · − an xn ] dx
∂a1 a
..
.
Z b
∂E
= −2 xn [f (x) − a0 − a1 x − a2 x2 − · · · − an xn ] dx
∂an a
So,
Z b Z b Z b Z b Z b
∂E
= 0 ⇒ a0 1 dx + a1 x dx + a2 x2 dx + · · · + an xn dx = f (x) dx
∂a0 a a a a a
Similarly,
Z b Z b Z b Z b Z b
∂E i i+1 i+2 i+n
= 0 ⇒ a0 x dx + a1 x dx + a2 x dx + · · · + an x dx = xi f (x) dx,
∂ai a a a a a
i = 1, 2, 3, . . . , n.
Denote
Z b Z b
xi dx = si , i = 0, 1, 2, 3, . . . , 2n, and bi = xi f (x) dx, i = 0, 1, . . . , n.
a a
a 0 s 0 + a 1 s 1 + a 2 s 2 + · · · + a n s n = b0
a0 s1 + a1 s2 + a2 s3 + · · · + an sn+1 = b1
..
.
a0 sn + a1 sn+1 + a2 sn+2 + · · · + an s2n = bn .
470CHAPTER 10. ORTHOGONAL POLYNOMIALS AND LEAST-SQUARES APPROXIMATIONS TO FUNCT
or in matrix notation
s0 s1 s2 ··· sn a0 b0
s1 s2 s3 ··· sn+1 a1 b1
. = .
. .. .. ..
.
. . . . .. ..
sn sn+1 sn+2 · · · s2n an bn
Denote
a0 b0
a1 b1
S = (si ), a=
.. ,
b=
.. .
. .
an bn
Then we have the system of normal equations:
Sa = b
The solution of these equations will yield the coefficients a0 , a1 , . . . , an of the least-squares poly-
nomial Pn (x).
Step 2. Compute b0 , b1 , . . . , bn :
For i = 0, 1, . . . , n do
Rb
bi = a xi f (x) dx
End
Step 3. Form the matrix S from the numbers s0 , s1 , . . . , s2n and the vector b from the numbers
b0 , b1 , . . . , bn .
s0 s1 . . . sn b0
s1 s2 . . . sn+1 b
S= . . . , b = .1 .
. .. .. .
. .
sn sn+1 . . . s2n bn
Example 10.3
Thus, ! !
s0 s1 2 0
S= =
s1 s2 0 23
1
1
Z
b0 = ex dx = e − = 2.3504
−1 e
1
2
Z
b1 = ex x dx = = 0.7358
−1 e
The normal system is: ! ! !
2 0 a0 b0
=
0 23 a1 b1
This gives
a0 = 1.1752, a1 = 1.1037
Accuracy Check:
P1 (0.5) = 1.7270, e0.5 = 1.6487
1
1
Z
b0 = ex dx = e − = 2.3504
−1 e
1
2
Z
b1 = xex dx = = 0.7358
−1 e
1
5
Z
b2 = x2 ex dx = e − = 0.8789.
−1 e
Accuracy Check:
P2 (0.5) = 1.6889
e0.5 = 1.6487
Example 10.4
1
1 5
Z
b0 = (x2 + 5x + 6) dx = + +6
0 3 2
53
=
6
Z 1 Z 1
2
b1 = x(x + 5x + 6) dx = (x3 + 5x2 + 6x) dx
0 0
1 5 6 59
= + + =
4 3 2 12
Accuracy Check:
|8.833−8.75|
Relative error: |8.75| = 0.0095.
1 1
1 2 3
S = 21 1 1
3 4
1 1 1
3 4 5
53 59
b0 = , b1 = ,
6 12
Z 1 1
1 5 6 69
Z
2 2
b2 = x (x + 5x + 6) dx = (x4 + 5x3 + 6x2 ) dx = + + = .
0 0 5 4 3 20
P2 (x) = 6 + 5x + x2 (Exact)
The least-squares approximation using monomial polynomials, as described above, is not numer-
ically effective; since the system matrix S of normal equations is very often ill-conditioned.
10.1. DISCRETE LEAST-SQUARES APPROXIMATIONS 475
For example, when the interval is [0, 1], we have seen that S is a Hilbert matrix, which is
notoriously ill-conditioned for even modest values of n. When n = 5, the condition number of
this matrix = cond(S) = O(105 ). Such computations can, however, be made computationally
effective by using a special type of polynomials, called orthogonal polynomials.
Definition 10.5. The set of functions {φ0 , φ1 , . . . , φn } in [a, b] is called a set of orthogonal
functions, with respect to a weight function w(x), if
Z b 0 if i 6= j
w(x)φj (x)φi (x) dx =
a Cj if i = j
Using this interesting property, least-squares computations can be more numerically effective,
as shown below. Without any loss of generality, let’s assume that w(x) = 1.
where {φn }nk=0 is a set of orthogonal polynomials. That is, the basis for generating Pn (x)
in this case is a set of orthogonal polynomials.
The question now arises: Is it possible to write Pn (x) as a linear combination of the or-
thogonal polynomials? The answer is yes and provided in the following. It can be shown
[Exercise]:
Given the set of orthogonal polynomials {Qi (x)}ni=0 , a polynomial Pn (x) of degree ≤ n, can be
written as:
for some a0 , a1 , . . . , an .
Finding the least-squares approximation of f (x) on [a, b] using orthogonal polynomials, then
can be stated as follows:
476CHAPTER 10. ORTHOGONAL POLYNOMIALS AND LEAST-SQUARES APPROXIMATIONS TO FUNCT
Given f (x), continuous on [a, b], find a0 , a1 , . . . , an using a polynomial of the form:
where
{φk (x)}nk=0
is a given set of orthogonal polynomials on [a, b], such that the error function:
Z b
E(a0 , a1 , . . . , an ) = [f (x) − (a0 φ0 (x) + · · · an φn (x))]2 dx
a
is minimized.
As before, we set
∂E
= 0, i = 0, 1, . . . , n.
∂ai
Now Z b
∂E
= −2 φ0 (x)[f (x) − a0 φ0 (x) − a1 φ1 (x) − · · · − an φn (x)] dx.
∂a0 a
Setting this equal to zero, we get
Z b Z b
φ0 (x)f (x) dx = (a0 φ0 (x) + · · · + an φn (x))φ0 (x) dx.
a a
and Z b
φ0 (x)φi(x) dx = 0, i 6= 0.
a
That is,
b
1
Z
a0 = φ0 (x)f (x) dx.
C0 a
Similarly,
Z b
∂E
= −2 φ1 (x)[f (x) − a0 φ0 (x) − a1 φ1 (x) − · · · − an φn (x)] dx.
∂a1 a
10.1. DISCRETE LEAST-SQUARES APPROXIMATIONS 477
∂E
so, setting ∂a1 = 0, we get
b
1
Z
a1 = φ1 (x)f (x) dx
C1 a
In general, we have
b
1
Z
ak = φk (x)f (x) dx, k = 0, 1, . . . , n,
Ck a
where Z b
Ck = φ2k (x) dx.
a
Z b Z b
Where Ck = = w(x)φ2k (x)dx
a a
is minimized.
Step 1. Compute Ck , k = 0, 1, . . . , n as follows:
For k = 0, 1, 2, . . . , n do
Rb
Ck = a w(x)φ2k (x) dx
End
478CHAPTER 10. ORTHOGONAL POLYNOMIALS AND LEAST-SQUARES APPROXIMATIONS TO FUNCT
The next question is: How to generate a set of orthogonal polynomials on [a, b], with respect
to a weight function w(x)?
The classical Gram-Schmidt process (see Chapter 7), can be used for this purpose. Starting
with the set of monomials {1, x, . . . , xn }, we can generate the orthonormal set of polynomials
{Qk (x)}.
Recall from the last chapter that the first few Legendre polynomials are given by:
φ0 (x) =1
φ1 (x) =x
1
φ2 (x) = x2 − 3
3
= x3 −
φ3 (x) 5x
etc.
The least-squares polynomial will then be given by Pn (x) = a0 Q0 (x) + a1 Q1 (x) + · · · + an Qn (x).
R1 R1
= 2
C0 −1 φ0 (x) dx = −1 1 dx = 2
R1 2 R1 2 2
C1 = −1 φ1 (x) dx = −1 x dx = 3
1 2
R1 2 R1 2
8
C2 = −1 φ2 (x) dx = −1 x − 3 dx = 45 .
and so on.
Example 10.7
Find linear and quadratic least-squares approximation to f (x) = ex using Legendre polyno-
mials.
φ0 (x) = 1, φ1 (x) = x
1 1 1
x3
1 1 2
Z Z
C1 = φ21 (x) dx = x dx = 2
= + = .
−1 −1 3 −1 3 3 3
1 1
1 1 1 1
Z Z
x x
a0 = φ0 (x)e dx e dx = e−
C0 −1 2 −1 2 e
Z 1
1
a1 = f (x)φ1 (x)dx
C1 −1
3 1 x 3
Z
= e xdx = .
2 −1 e
Accuracy Check:
1 1 3
P1 (0.5) = e− + · 0.5 = 1.7270
2 e e
e0.5 = 1.6487
|1.7270−1.6487|
Relative error: |1.6487| = 0.0475.
1 1 3
a0 = e− , a1 = (Already computed above)
2 e e
Step 1. Compute
1
1 2 1
Z Z
C2 = =φ22 (x) dx
x − dx 2
−1 −1 3
5 1
x 2 x3 1 8
= − · + x =
5 3 3 a −1 45
Step 2. Compute
1
1
Z
a2 = ex φ2 (x) dx
−1 C2
45 1 x
1
Z
2
a2 = e x − dx
8 −1 3
7
=e−
e
Accuracy Check:
P2 (0.5) = 1.7151
e0.5 = 1.6487
|1.7151−1.6487|
Relative error: |1.6487| = 0.0403.
Compare this relative error with that obtained earlier with an non-orthogonal polynomial of
degree 2.
10.3. CHEBYSHEV POLYNOMIALS: ANOTHER WONDERFUL FAMILY OF ORTHOGONAL POLYNOMIAL
To see that Tn (x) is a polynomial of degree n in our familiar form, we derive a recursive
relation by noting that
Tn (x) = cos(nθ), 0 ≤ θ ≤ π.
Tn+1 (x) = cos(n + 1)θ = cos nθ cos θ − sin nθ sin θ
Tn−1 (x) = cos(n − 1)θ = cos nθ cos θ + sin nθ sin θ
The right-hand side still does not look like a polynomial in x. But note that cos θ = x
So,
T0 (x) = 1, T1 (x) = x
Using this recursive relation, the Chebyshev polynomials of the successive degrees can be gen-
erated:
and so on.
We now show that Chebyshev polynomials are orthogonal with respect to the weight function
1
w(x) = √ in the interval [−1, 1].
1 − x2
−1 0 if m 6= n
Tm (x)Tn (x)
Z
√ dx =
1 1 − x2 π
2 if m = n.
First,
1
Tm (x)Tn (x)
Z
√ dx, m 6= n.
−1 1 − x2
Z 1
cos(m arccos x) cos(n arccos x)
= √ dx
−1 1 − x2
Since
θ = arccos x
1
dθ = − √ dx,
1 − x2
10.4. THE LEAST-SQUARE APPROXIMATION USING CHEBYSHEV POLYNOMIALS483
Z 0
− cos mθ cos nθdθ
π
Z π
= cos mθ cos nθdθ
0
1
Now, cos mθ cos nθ can be written as [cos(m + n)θ + cos(m − n)θ]
2
So,
Z π
cos mθ cos nθ dθ
0
1 π 1 π
Z Z
= cos(m + n)θ dθ + cos(m − n)θ dθ
2 0 2 0
π π
1 1 1 1
= sin(m + n)θ + sin(m − n)θ
2 (m + n) 0 2 (m − n) 0
= 0.
−1
Tn2 (x) dx
Z
π
√ = for n ≥ 1.
1 1−x 2 2
Then, it is easy to see that using the orthogonal property of Chebyshev polynomials:
484CHAPTER 10. ORTHOGONAL POLYNOMIALS AND LEAST-SQUARES APPROXIMATIONS TO FUNCT
1
T 2 (x)
Z
C0 = √0 dx = π
−1 1 − x2
1
T 2 (x)
Z
π
Ck = √k dx = , k = 1, . . . , n
−1 1−x 2 2
where
1
2 f (x)Ti (x) dx
Z
ai = √ , i = 1, · · · , n
π −1 1 − x2
and
1
1 f (x) dx
Z
a0 = √
π −1 1 − x2
Example 10.9
Here
P1 (x) = a0 φ0 (x) + a1 φi (x) = a0 T0 (x) + a1 T1 (x) = a0 + a1 x,
where
1
1 ex dx
Z
a0 = √ ≈ 1.2660
π −1 1 − x2
1
2 xex
Z
a1 = √ dx ≈ 1.1303
π −1 1 − x2
Accuracy Check:
P1 (0.5) = 1.8312;
e0.5 = 1.6487
10.5. MONIC CHEBYSHEV POLYNOMIALS 485
|1.6487−1.8312|
Relative error: 1.6487 = 0.1106.
Note that Tk (x) is a Chebyshev polynomial of degree k with the leading coefficient 2k−1 , k ≥ 1.
Thus we can generate a set of monic Chebyshev polynomials from the polynomials Tk (x) as
follows:
As seen above the Chebyshev polynomials can, of course, be used to find least-squares poly-
nomial approximations. However, these polynomials have several other wonderful polynomial
approximation properties. First, we state the minimax property of the Chebyshev poly-
nomials.
Interpretation: The above results say that the absolute maximum of the monic Chebyshev
polynomial of degree n, T̃n (x), over [−1, 1] is less than or equal to that of any polynomial Pn (x)
over the same interval.
Recall from Chapter 6 that error in polynomial interpolation of a function f (x) with the
nodes, x0 , x1 , . . . , xn by a polynomial Pn (x) of degree at most n is given by
f n+1 (ξ)
E = f (x) − P (x) = Ψ(x),
(n + 1)!
where Ψ(x) = (x − x0 )(x − x1 ) · · · (x − xn ).
The question is: How to choose these (n + 1) nodes x0 , x1 , . . . , xn so that |Ψ(x)| is minimized
in [−1, 1]?
The answer can be given from the above minimax property of the monic Chebyshev polynomials.
Thus,
1
• The smallest absolute maximum value of Ψ(x) with x0 , x1 , . . . , xn as chosen above, is: .
2n
If the interval is [a, b], different from [−1, 1], then, the zeros of T̃n+1 (x) need to be shifted by
using the transformation:
1
x̃ = [(b − a)x + (a + b)]
2
10.6. MINIMAX POLYNOMIAL APPROXIMATIONS WITH CHEBYSHEV POLYNOMIALS487
Example 10.10
Let the interpolating polynomial be of degree at most 2 and the interval be [1.5, 2].
is as small as possible.
We will show below how minimax property of the Chebyshev polynomials can be gainfully used.
First note that | a1n Pn (x) − Pn−1 (x)| is a monic polynomial. So, by the minimax property, we
have
1 1
max | Pn (x) − Pn−1 (x)| ≥ max |T̃n (x)| = n−1 .
x∈[−1,1] an x∈[−1,1] 2
Thus, if we choose
Pn−1 (x) = Pn (x) − an T̃n (x),
Then the minimum value of the maximum error of approximating Pn (x) by Pn−1 (x) over [−1, 1]
is given by:
|an |
max |Pn (x) − Pn−1 (x)| = n−1 .
−1≤x≤1 2
|f (n+1) (ξ(x))||xn+1 |
ET R (x) = Reminder after n terms =
(n + 1)!
|an−1 |
|Pn−1 (x) − Pn−2 (x)| = .
2n−2
Example 10.11
x4
Find the economized power series for cos x = 1 − 21 x2 + 4! − · · · for 0 ≤ x ≤ 1 with a tolerance
ǫ = 0.05.
10.6. MINIMAX POLYNOMIAL APPROXIMATIONS WITH CHEBYSHEV POLYNOMIALS489
1 x4
P4 (x) = 1 − x2 + 0 · x3 +
2 4!
1
|TR (x)| ≤ (1)(1)5 = 0.0083.
120
Step 4. Maximum absolute accumulated error = Maximum absolute truncation error + max-
1
imum absolute Chebyshev error = 0.0083 + 24 · 18 = 0.0135 which is greater than ǫ = 0.05.
Thus, the economized power series of f (x) = cos x for 0 ≤ x ≤ 1 with an error tolerance of
ǫ = 0.05 is the 3rd degree polynomial:
Accuracy Check: We will check below how accurate this approximation is for three values of
x in 0 ≤ x ≤ 1: two extreme values x = 0 and x = 1, and one intermediate value x = 0.5.
For x=0.5.
cos(0.5) = 0.8776
P3 (0.5) = 0.8802
Error = | cos(0.5) − P3 (0.5)| = | − 0.0026| = 0.0026.
For x=0.
For x=1.
Remark: These errors are all much less than 0.05 even though theoretical error-bound, 0.0135,
exceeded it.