Chapter 5 - Function Approximation
Chapter 5 - Function Approximation
Last lecture:
Least Square Method for Regression
This lecture:
Function approximation
CHAPTER V APPROXIMATION OF FUNCTIONS
W3(x) = e-1(1-x)3 +e-1/33x(1-x)2 + e1/33x2 (1-x) + e1x3 f(x) 3rd order Weierstrass approx.
2.5
1.5
exact
1
Weierstrass
0.5
0
-1 -0.5 0 0.5 1 x
5.1.2 Comparison with Taylor series expansion
-0.24
Want: a better way to obtain Pn(x) so that Error(x) is more evenly distributed
-1 -0.5 0 0.5 1 x but max{|E(x)|} is smaller
5.2 Minimax Approximation
0.4
Error 𝑞3∗ 𝑥 = 0.994579 + 0.995668x + 0.542973 x2 + 0.179533x3
0.2 Minimax
E3(x) = ex - 𝑞3∗ 𝑥
0
0.06
Error Error in third order
-0.2
polynomial approx.
0.04
-0.4 Minimax
-1 -0.5 0 0.5 1 x 0.02 Taylor Series
0
Indeed the negative error and positive error are evened out.
-0.02
-1 -0.5 0 0.5 1 x
◊ Clearly, Taylor series approach, while simple, does not lead to an evenly distributed error.
Although the error near x=x0 is very small, its maximum error in the interval is much higher
than the one obtained via minimax approach.
◊ We must find an alternative robust approach that performs similarly to the minimax approximation.
1 1 1
a1 −1 x2dx = −1 exxdx = 2e-1 = 0.735789 exact
0.5 LSQ
Minimax
a0 = 1.175201 and a1 = 1.103638. 0
x
-1 -0.5 0 0.5 1
𝑟1∗ (x) = 1.175201 + 1.103638x
Comparison of errors in the linear approximations:
0.8
Error
0.6 LSQ
Minimax
0.4
Taylor series
0.2
-0.2
-0.4
-1 -0.5 0 0.5 1 x
5.3.3 Generalization to least square approximation
by minimizing
𝑏
E = [ 𝑎f(x) − σ𝑛𝑗=0 aj xj ]2 dx need to develop alternative method to find 𝑟𝑛∗ (x)
E 1.E+08
Solution: Minimization of Error E =0 Cond
aj 1.E+07
1.E+06
𝑏
-2 [ 𝑎f(x) − σ𝑛𝑖=0 ai xi ] xj dx 1.E+05
1.E+04
𝑏 𝑏 1.E+03 Cond(H(n))
σ𝑛𝑗=0 aj 𝑎xi+jdx = 𝑎f(x) xj dx 1.E+02
𝑏
1.E+01
𝟏
σ𝑛𝑗=0 aj [bi+j+1 - a i+j+1] = 𝑎f(x) xj dx cj 1.E+00
𝒊+𝒋+𝟏
1 2 3 4 5 6 n
5.4 Orthogonal Polynomial
0.0
0.0 0.2 0.4 0.6 0.8 1.0 1.2
x
◊ What does “orthogonal” mean?
There exists a sequence of polynomials {fn(x)|n≥0} with degree (fn) = n for all n and
(fn, fm) = 0 for n≠m, n>0 and m>0.
* n=0: f0(x) = c.
𝑏
Normalization requires: (f0, f0) = c2 𝑎w(x) dx = 1
𝑏
c = [ 𝑎w(x) dx]1/2
𝑏
a1,0 = -(x, f0)/(f0, f0) = -(x, f0) = -c 𝑎w(x) x dx = 1
𝑏 𝑏
a1,0 = - 𝑎w(x) x dx /[ 𝑎w(x) dx]1/2
1
a1,0 = -(x, f0) = -c −1 x dx = 0 an,j = - (xn, fj) / (fj, fj) = -(xn, fj)
1
y1(x) = x || y1(x) ||2 = −1 x2 dx ]1/2 = (2/3) 1/2
f1(x) = 3/2 x
Legendre polynomials
• Note: (fj, fj) =1 is not necessary as long as we know the value of || fj(x) ||2 which is usually the case
for well-known orthogonal polynomials.
Lecture 22
Last lecture:
Function approximation
This lecture:
by minimizing
𝑏
E = [ 𝑎f(x) − σ𝑛𝑗=0 aj xj ]2 dx need to develop alternative method to find 𝑟𝑛∗ (x)
E 1.E+08
Solution: Minimization of Error E =0 Cond
aj 1.E+07
1.E+06
𝑏
-2 [ 𝑎f(x) − σ𝑛𝑖=0 ai xi ] xj dx 1.E+05
1.E+04
𝑏 𝑏 1.E+03 Cond(H(n))
σ𝑛𝑗=0 aj 𝑎xi+jdx = 𝑎f(x) xj dx 1.E+02
𝑏
1.E+01
𝟏
σ𝑛𝑗=0 aj [bi+j+1 - a i+j+1] = 𝑎f(x) xj dx cj 1.E+00
𝒊+𝒋+𝟏
1 2 3 4 5 6 n
5.4 Orthogonal Polynomial
0.0
0.0 0.2 0.4 0.6 0.8 1.0 1.2
x
◊ What does “orthogonal” mean?
There exists a sequence of polynomials {fn(x)|n≥0} with degree (fn) = n for all n and
(fn, fm) = 0 for n≠m, n>0 and m>0.
* n=0: f0(x) = c.
𝑏
Normalization requires: (f0, f0) = c2 𝑎w(x) dx = 1
𝑏
c = [ 𝑎w(x) dx]-1/2
𝑏
a1,0 = -(x, f0)/(f0, f0) = -(x, f0) = -c 𝑎w(x) x dx
𝑏 𝑏
a1,0 = - 𝑎w(x) x dx /[ 𝑎w(x) dx]1/2
• Note: (fj, fj) =1 is not necessary as long as we know the value of || fj(x) ||2 which is usually the case
for well-known orthogonal polynomials.
5.4.3 Various common orthogonal polynomials
i) Legendre polynomials
* Weight function: w(x) = 1 on [-1, 1]
* Legendre functions are solutions to Legendre's differential eqn.:
𝑑 𝑑
[(1 − 𝑥 2 ) 𝑃(𝑥)] + 𝑛(𝑛 + 1)𝑃(𝑥) = 0
𝑑𝑥 𝑑𝑥
This ordinary differential equation is frequently encountered in physics and other technical fields.
In particular, it occurs when solving Laplace's equation (& related PDEs) in spherical coordinates
(−1)𝑛 𝑑 𝑛
* General expression: 𝑃𝑛 (𝑥) = 𝑛 [(1 − 𝑥 2 )𝑛 ],
2 𝑛! 𝑑𝑥 𝑛
P0(x) 1
P1(x) x
P2(x) (3x2-1) /2
P3(x) (5x3-3x) /2
P4(x) (35x4-30x2 +3) /8
P5(x) (63x5-70x3 +15x) /8
P6(x) (231x6-315x4 +105x2-5) /16
Legendre polynomials
* Orthogonality of Pn(x):
T0(x) 1
T1(x) x = cos(q )
T2(x) 2x2-1 = cos(2q ) =2cos2q-1
T3(x) 4x3-3 x = cos(3q ) =4cos3q- 3cosq
T4(x) 8x4-8 x2 +1
T5(x) 16x5-20x3 +5x
T6(x) 32x6-48x4 +18x2-1
Chebyshev polynomials
0, 𝑛≠𝑚
* Orthogonality: (Tn, Tm) = ቐ 𝜋, 𝑛 = 𝑚 = 0
𝜋/2, 𝑛 = 𝑚 > 0
• Chebyshev polynomials are important in approximation theory because the roots of the
Chebyshev polynomials of the first kind, which are also called Chebyshev nodes,
are used as nodes in polynomial interpolation.
Laguerre polynomials
1 𝑑𝑛
* General expression: 𝐿𝑛 𝑥 = 𝑥 𝑛 𝑒 −𝑥
𝑛!𝑒 −𝑥 𝑑𝑥 𝑛
Note: (y, fj) = σ𝑛𝑖=1 ai(fi, fj) = aj (fj, fj) for j=0, 1, ..., n.
𝑏
= 𝑎w(x) y(x) fj(x) dx / || fj ||2.
𝜕𝐸22 𝑏
= 0 -2 𝑎w(x)[f(x) − σ𝑛𝑖=1 aifi(x)]fj(x)dx = 0
𝜕𝑎𝑗
𝑏 𝑏
𝑎w(x)f(x)fj(x)dx = σ𝑛𝑖=1 ai 𝑎w(x)aifi(x)fj(x)dx = σ𝑛𝑖=1 ai (fi, fj) = aj || fj ||2.
𝑏
aj = 𝑎w(x)f(x)fj(x)dx / || fj ||2.
i.e. aj = (f, fj) / (fj, fj) the only work needed is the evaluation of (f, fj).
5.5.2 Applications to arbitrary [a, b] using Legendre polynomials
2𝑖+1
• Rn(t) = σ𝑛𝑖=1 ai Pi(t), t [-1, 1] ai = (F, Pi) / (Pi, Pi) = (F, Pi).
2
1 1
(F, P1) = −1 e1+t ∗t dt = 2 a1 =3/2*2 = 3
0
1
(F, P2) = −1 e1+t ∗(3∗t2−1)/2 dt = e2 – 7 a2 = 0.9726403 0 0.5 1 1.5 2
1
(F, P3) = −1 e1+t ∗(5∗t3−3∗t)/2 dt = 37-5e2 a3 = 0.1915183
0.2
E2
0.15
E3
0.1
0.05
-0.05
-0.1
-0.15
-0.2
0 0.5 1 1.5 2 x
5.5.2 Applications using Chebyshev polynomials for f(x)
• w(x) = 1/ 1 − 𝑥 2
Construct Cn(x) to approximate f(x):
Cn(x) = σ𝑛𝑗=0 ′ cj Tj(x) (' means taking c0/2, instead of c0, for j=0)
0, 𝑛≠𝑚
(Tn, Tm) = ቐ 𝜋, 𝑛 = 𝑚 = 0
𝜋/2, 𝑛 = 𝑚 > 0
2 1 𝑓(𝑥)𝑇𝑗 (𝑥)
cj = −1 𝑑𝑥 for j = 0, 1,... n.
1−𝑥 2
Solution:
For f(x) = ex, x[-1, 1]
2 𝜋 𝑐𝑜𝑠 𝜃
cj = 0 𝑒 𝑐𝑜𝑠(𝑗 𝜃)𝑑𝜃 3
c0 = 2.5321376, c1 = 1.13031812,
2
c2 = 0.27149534, c3 = 0.04433685,
c4 = 0.00547424, c5 = 0.000542926 1.5 f(x)
C1(x)
C2(x)
C1(x) = c0/2 + c1x = 1.26607 + 1.13032x 1 C3(x)
3 0.008
Error_q*3
0.006 Error_C3
2.5
f(x) Error_C4
0.004
2
C4(x) 0.002
1.5 C3(x) 0
-0.002
1
-0.004
0.5 -0.006
0 -0.008
-1 -0.75 -0.5 -0.25 0 0.25 0.5 0.75 1 x
-1 -0.75 -0.5 -0.25 0 0.25 0.5 0.75 1 x
C3(x) = 0.994571 + 0.997328x + 0.542991x2 + 0.177347x3 𝑞3∗ (x) and C3(x) are very close.
𝑞3∗ (x) = 0.994579 + 0.995668x + 0.542973 x2 + 0.179533x3 C4(x) has much less error than C3(x).
Example: Expand f(x) = ex, -1 x1, using Chebyshev polynomials Tn(x)
1.E+01
c(k)
1.E-01
1.E-07
1.E-09
This type of behavior is called exponential convergence.
1.E-11
1.E-13
It is typical for smooth functions.
1.E-15
0 5 10 15 k
Example: Expand f(x) = ex, -1 x1, using Chebyshev polynomials Tn(x)
𝜋
f(x) ~ Cn(x)= σ𝑛𝑗=0 ′ cj Tj(x) 2
cj = 0 𝑒
𝑐𝑜𝑠 𝜃
𝑐𝑜𝑠(𝑗 𝜃)𝑑𝜃
1.E+01
c(k)
1.E-01
1.E-07
1.E-09
This type of behavior is called exponential convergence.
1.E-11
1.E-13
It is typical for smooth functions.
1.E-15
0 5 10 15 k
Supplemental Reading
Chapter 5 APPROXIMATION OF FUNCTIONS
Example 1 Padé Approximation
Background: Padé Approximation is the "best" approximation of a function by a
rational function of given order. A Padé approximant often gives better
approximation of the function than truncating its Taylor series and it may
still work where the Taylor series does not converge. For these reasons Padé
approximants are used extensively in computer calculations.
General idea:
Given a function f(x) and two integers m ≥ 0 and n ≥ 0, then the Padé
approximant of order (m, n) is the rational function
a0 + a1x + a2 x 2 + ... + am x m
R( x) =
1 + b1x + b2 x 2 + ... + bn x n
which agrees with f(x) to the highest possible order, which amounts to
f (0) = R (0) = a0 , f ' (0) = R' (0) , f " (0) = R" (0) ,…
f ( m + n) (0) = R ( m + n) (0)
Illustration:
a + a x + a2 x 2
Approximate f(x) = exp(-x) in the form of R2,2 ( x) = 0 1
1 + b1x + b2 x 2
1 2 1 3 1 4
(1 − x + x − x + x + ... )(1 + b1x + b2 x 2 ) = a0 + a1x + a2 x 2
2! 3! 4!
1 2 1 3 1 4 b b
1− x + x − x + x + ... b1x − b1x 2 + 1 x 3 − 1 x 4 + ...
2! 3! 4! 2! 3!
b
+ b2 x 2 − b2 x 3 + 2 x 4 + ... = a0 + a1x + a2 x 2
2!
Collecting coefficient of various powers of x
x3 : -1/3! + b1/2! - b2 = 0
x2 : 1/2! - b1 + b2 = a2
x1 : -1+ b1 = a1
x0 : 1 = a0
The solution to the first two equations give:
b1 = 1/2 b2 = 1/12
The third and forth equations give
a1 = -1/2 a2 = 1/12
and finally a0 = 1
1 − x / 2 + x 2 / 12
Thus, R2,2 ( x) =
1 + x / 2 + x 2 / 12
* If we continue the process, we can obtain
1 − x / 2 + x 2 / 10 − x 3 / 120
R3,3 ( x) =
1 + x / 2 + x 2 / 10 + x 3 / 120
* Comparison
25
exp(-x)
pade2,2
20 Pade3,3
TS4
15
10
0
-3 -2.5 -2 -1.5 -1 -0.5 0 x
1.6
exp(-x)
1.4 pade2,2
1.2 Pade3,3
TS4
1 TS6
0.8
0.6
0.4
0.2
0
0 0.5 1 1.5 2 2.5 3 x
Clearly, for x > 0 even R2,2 is better than TS4 and TS6.
For x <0, R2,2 is comparable with TS4 in -2<x<0.
Example 2 Function approximation using Chebyshev polynomials
1.2
f(x)
C1(x)
1
C3(x)
0.8
0.6
0.4
0.2
0
0 0.2 0.4 0.6 0.8 1 x
1.2
f(x)
C6(x)
1
C10(x)
C15(x)
0.8
0.6
0.4
0.2
0
0 0.2 0.4 0.6 0.8 1 x
1.E+00
|c(k)|
1.E-01
1
1.E-02
2
1.E-03
1.E-04
1.E-05
1 10 k 100