The Use of Chebyshev Polynomials for …wil.byimplication.com/files/chebyshev.pdfThe Use of...
-
Upload
vuongthuan -
Category
Documents
-
view
233 -
download
5
Transcript of The Use of Chebyshev Polynomials for …wil.byimplication.com/files/chebyshev.pdfThe Use of...
Ateneo de Manila University
Ma195a15 Final project
The Use of Chebyshev Polynomials forApproximating Functions
Author:Wilhansen Joseph B. Li
Supervisor:Dr. Roden David
September 27, 2010
Chapter 1
Introduction
1.1 Overview
Function approximation is just one of the many terms used to describe the process of compressing a largeamount of data to a compact representation that can be used to:
1. Interpolate values between two data points,
2. Predict values outside of the subdomain given by the data set and
3. Create measures that can be used to describe the data
The broad term for this is “modeling”. Other terms that do the almost the same thing include “statisticalmodeling”, “data fitting”, “data modeling”, “parameter estimation”, “series transforms”, etc. Although theydiffer slightly in semantics, they generally follow the general idea. For example, statistical modeling may focusmore on predicting data and describing them rather than interpolating values while function approximationis more interested in interpolating values between points given by the data set and doesn’t really care aboutprediction. Also, their purposes might be different like how statistical measures are used to form conclusionswhile function approximations might be used to implement trancendental functions on a machine that canonly perform arithmetic or how series transformations are used in signal processing to compress audio-visualdata.
How modeling is done largely depends on the data set; no single model fits all kinds of data. For example,bernoulli events might be better modeled using the normal distribution but the normal distribution is notused to model the levels of a sound wave over time as the Fourier series or Haar wavelets would better modelit.
The interest in this paper is the use of Chebyshev polynomials to approximate functions. Furthermore,various classes of mathematical functions will be analyzed in order to conclude which kinds of functions couldbest be modeled by Chebyshev polynomials. Scilab[1] source code will provided.
1.2 Vector Space of Functions
A vector space F can be created where each vector is a function; this is because functions have linearity: iff(x), g(x) ∈ F and a, b ∈ R then (af + bg)(x) = af(x) + bg(x). Moreover, a set G ⊆ F which restricts Fto functions defined over a fixed interval [a, b] is a subspace because domains of functions are not affected bylinear combinations of functions.
Each vector in F has an uncountably infinite number of elements (i.e. the dimension of F is infinite). Con-sider f(x) ∈ F that’s defined over [0, 1]; its elements, {a0, a1, . . . , an} are then: a0 = f(0), a1 = f(1/n), a2 =f(2/n), . . . , an = f(1). However, because f(x) is defined over a connected interval in R, there is an infinitenumber of points in any interval so n → ∞. Thus, F actually has an infinite dimension.
1
1.2.1 Magnitude of a function
The magnitude of a vector can be described by the square root of the summation of the square of its elements.For a function f(x) ∈ F which is defined over a domain D = [a, b], we can define the magnitude as a Riemannsum which results in an integral:
∥f(x)∥ = limn→∞
√√√√ n∑i=0
(f
(a+ i
b− a
n
))2b− a
n= lim
∆x→0
√√√√ n∑i=0
(f (a+ i∆x))2∆x =
√∫D
(f(x))2dx (1.1)
Moreover, it can be confirmed the properties of vector spaces carry over:
∥cf(x)∥ = c∥f(x)∥ (Homogeneity of degree 1)
∥f(x) + g(x)∥ ≤ ∥f(x)∥+ ∥g(x)∥ (Triangle inequality)
∥f(x)∥ ≥ 0 with ∥f(x)∥ = 0 ⇐⇒ f(x) = 0 (Positive Definiteness)
For the magnitudes of elements in F to be a field, we require that all magnitudes be finite (i.e. the integralsmust converge). Moreover, elements in such set still forms a vector space since any linear combination of twoconvergent integrals is still convergent.
1.2.2 Inner Product of functions
An inner product space can be defined over F . Just as how the magnitude of a function is defined byintegration, the same will be done. The inner product is described to be the sum of the products of componentsbetween two vectors. If f(x), g(x), h(x) ∈ F are defined over D, then the inner product ⟨f, g⟩ is:
⟨f, g⟩ =∫D
f(x)g(x)dx (1.2)
Note that properties of inner product spaces carry over:
⟨f, f⟩ =∫D
f(x)f(x)dx =
∫D
(f(x))2dx = ∥f(x)∥2
⟨f, g⟩ =∫D
f(x)g(x)dx =
∫D
g(x)f(x)dx = ⟨g, f⟩
⟨cf, g⟩ =∫D
cf(x)g(x)dx = c
∫D
f(x)g(x)dx = c⟨f, g⟩
⟨f + g, h⟩ =∫D
(f(x) + g(x))h(x)dx =
∫D
f(x)h(x)dx+
∫D
g(x)h(x)dx = ⟨f, h⟩+ ⟨g, h⟩
⟨f, g⟩ ≤ ∥f(x)∥∥g(x)∥ (Cauchy-Schwarz Inequality)
Carrying over the definition in linear algebra, two functions f(x), g(x) defined over D is orthogonal if:
⟨f, g⟩ =∫D
f(x)g(x)dx = 0
1.2.3 Projection
The projection of the function g onto f is defined by
Pf (g) =⟨g, f⟩⟨f, f⟩
. (1.3)
This gives a measure on how “close” the function g is to f . The higher the value, the closer it is. Scalingthe function f(x) by Pf (g), it will give the scaled f(x) which best matches g(x) (i.e. the least squares fit).That is, if c ∈ R then:
min ∥cf − g∥2 = ∥Pf (g)f − g∥2 (1.4)
2
The proof is as follows:
min ∥cf − g∥2 ⇐⇒ d
dc
∫D
(cf(x)− g(x))2dx = 0
d
dc
∫D
(cf(x)− g(x))2dx =d
dc
∫D
[c2f2(x)− 2cf(x)g(x) + g2(x)
]dx
=d
dc
[c2∫D
f2(x)dx− 2c
∫D
f(x)g(x)dx+
∫D
g2(x)dx
]= 2c
∫D
f2(x)dx− 2
∫D
f(x)g(x)dx = 0
c =
∫Df(x)g(x)dx∫Df2(x)dx
=⟨g, f⟩⟨f, f⟩
= Pf (g) �
1.3 Orthogonal Basis Functions
Basis functions are basically a (possibly infinite) set of functions that can be used to approximate a function viaa linear combination. That is, given a function f(x), there exists numbers {c1, c2, . . . , cn}, called coefficients,over a field (usually R) for a set of basis functions {T1(x), T2(x), . . . , Tn(x)} such that:
f(x) ≈ c1T1(x) + c2T2(x) + · · ·+ cnTn(x) =∑i
ciTi(x) (1.5)
If the set of basis functions is infinite, the function can still be approximated by a finite number of elementsin that set without exceeding a certain error threshold.
If the basis functions {T0(x), T1(x), . . . , Tn(x)} over the domain D is orthogonal then∫D
Ti(x)Tj(x)w(x)dx =
{0 i = j
λi = 0 i = j
where w(x) is the weight function that depends on the nature of the basis functions. Note that in this case,the inner product ⟨f, g⟩ is redefined as:
⟨f, g⟩ =∫D
f(x)g(x)w(x)dx. (1.6)
If λi = 1 for all i then it can be said that the basis is orthonormal.This is analogous to orthogonal basis in the inner product space Rn where the inner product of two basis
elements results in a zero if they’re not the same or some non-zero value if they’re the same. Intuitively,orthogonality means that the functions do not “overlap” when being projected so a coefficient, ci can beadjusted without causing “side effects” to other coefficients.
The process of determining such values of ci that can best approximate the function is called projectionas discussed in 1.2.3 with the slight modification that in some classes of functions, an additional weighingfunction w(x) is multiplied to the two product of two other functions prior to integrating (as in (1.6)). If Ti(x)is orthogonal, the process of determining ci simplifies to as follows:
f(x) ≈ c1T1(x) + · · ·+ cnTn(x)
f(x)Ti(x)w(x) ≈ c1T1(x)Ti(x)w(x) + · · ·+ ciTi(x)Ti(x)w(x) + · · ·+ cnTn(x)Ti(x)w(x)∫D
f(x)Ti(x)w(x)dx ≈∫D
c1T1(x)Ti(x)w(x)dx+ · · ·+∫D
ciT2i (x)w(x)dx+ · · ·+
∫D
cnTn(x)Ti(x)w(x)dx∫D
f(x)Ti(x)w(x)dx = 0 + · · ·+ ciλi + · · ·+ 0
3
Thus:
ci =1
λi
∫D
f(x)Ti(x)w(x)dx =1
⟨Ti, Ti⟩⟨f, Ti⟩ = PTi(f). (1.7)
Note that if the basis are not orthogonal, then there will be terms other than ciλi that will be non-zero causingsome difficulties in determining ci because a system of linear equations will appear which requires anothersolving step.
To illustrate the projection process1:
!" "#$%&'()*+"%*',-.()"+(/%0(./"
! ! ! ! "!
! ! ! "!
! ! ! ##$%!
! ! "!
! "!
"!
!"#$%&%'()*+(,-,*./'0#-%',*012"#%"34516475"8982:"9;;<=2;">7?@32A52"?B"612"<;2"?B"!"#$#%&'()*$+(#C"D9;4;"B<7E64?7;"9:2";=933"842E2;"?B";45793"6196"E97"F2";E932A"97A"E?=F472A"6?"8:?A<E2"97"988:?G4=964?7"6?"97"?:454793"
B<7E64?7H"97A"612"8:?E2;;"?B"@?:>475"?<6"1?@"=<E1"?B"29E1"F9;4;"
B<7E64?7"6?";<="4;"E9332A",-+./)*$+(C"0?"988:?G4=962"9"B<7E64?7"<;475"F9;4;"B<7E64?7;"@2"=<;6"@?:>"?<6"9";E939:"I93<2"6196"
:28:2;276;"1?@"=<E1"612"?:454793"B<7E64?7"&012"4;"34>2"612"29E1"F9;4;"B<7E64?7"3$012C"J2"A?"614;"FK"47625:96475"612"8:?A<E6"&0123$012"?I2:"612"B<33"A?=947"?B"&C"
"""""""
! " = c1
! " = c2
! " = c3
"
L;475"614;"8:?M2E64?7"8:?E2;;"?I2:"933"?<:"F9;4;"B<7E64?7;":26<:7;"9"
I2E6?:"?B"988:?G4=964?7"E?2BB4E4276;C"(B"@2";E932"612"E?::2;8?7A475"
F9;4;"B<7E64?7"FK"612"E?2BB4E4276;N"
" =c1
" =c2
" =c3"
N"97A";<="612":2;<36;"@2"?F6947"?<:"988:?G4=962A"B<7E64?7C"
"""""""""""""""""""""""""""""""""
#ciBi ="
Scaling them we get
!" "#$%&'()*+"%*',-.()"+(/%0(./"
! ! ! ! "!
! ! ! "!
! ! ! ##$%!
! ! "!
! "!
"!
!"#$%&%'()*+(,-,*./'0#-%',*012"#%"34516475"8982:"9;;<=2;">7?@32A52"?B"612"<;2"?B"!"#$#%&'()*$+(#C"D9;4;"B<7E64?7;"9:2";=933"842E2;"?B";45793"6196"E97"F2";E932A"97A"E?=F472A"6?"8:?A<E2"97"988:?G4=964?7"6?"97"?:454793"
B<7E64?7H"97A"612"8:?E2;;"?B"@?:>475"?<6"1?@"=<E1"?B"29E1"F9;4;"
B<7E64?7"6?";<="4;"E9332A",-+./)*$+(C"0?"988:?G4=962"9"B<7E64?7"<;475"F9;4;"B<7E64?7;"@2"=<;6"@?:>"?<6"9";E939:"I93<2"6196"
:28:2;276;"1?@"=<E1"612"?:454793"B<7E64?7"&012"4;"34>2"612"29E1"F9;4;"B<7E64?7"3$012C"J2"A?"614;"FK"47625:96475"612"8:?A<E6"&0123$012"?I2:"612"B<33"A?=947"?B"&C"
"""""""
! " = c1
! " = c2
! " = c3
"
L;475"614;"8:?M2E64?7"8:?E2;;"?I2:"933"?<:"F9;4;"B<7E64?7;":26<:7;"9"
I2E6?:"?B"988:?G4=964?7"E?2BB4E4276;C"(B"@2";E932"612"E?::2;8?7A475"
F9;4;"B<7E64?7"FK"612"E?2BB4E4276;N"
" =c1
" =c2
" =c3"
N"97A";<="612":2;<36;"@2"?F6947"?<:"988:?G4=962A"B<7E64?7C"
"""""""""""""""""""""""""""""""""
#ciBi ="
then finally summing the scaled functions:
!" "#$%&'()*+"%*',-.()"+(/%0(./"
! ! ! ! "!
! ! ! "!
! ! ! ##$%!
! ! "!
! "!
"!
!"#$%&%'()*+(,-,*./'0#-%',*012"#%"34516475"8982:"9;;<=2;">7?@32A52"?B"612"<;2"?B"!"#$#%&'()*$+(#C"D9;4;"B<7E64?7;"9:2";=933"842E2;"?B";45793"6196"E97"F2";E932A"97A"E?=F472A"6?"8:?A<E2"97"988:?G4=964?7"6?"97"?:454793"
B<7E64?7H"97A"612"8:?E2;;"?B"@?:>475"?<6"1?@"=<E1"?B"29E1"F9;4;"
B<7E64?7"6?";<="4;"E9332A",-+./)*$+(C"0?"988:?G4=962"9"B<7E64?7"<;475"F9;4;"B<7E64?7;"@2"=<;6"@?:>"?<6"9";E939:"I93<2"6196"
:28:2;276;"1?@"=<E1"612"?:454793"B<7E64?7"&012"4;"34>2"612"29E1"F9;4;"B<7E64?7"3$012C"J2"A?"614;"FK"47625:96475"612"8:?A<E6"&0123$012"?I2:"612"B<33"A?=947"?B"&C"
"""""""
! " = c1
! " = c2
! " = c3
"
L;475"614;"8:?M2E64?7"8:?E2;;"?I2:"933"?<:"F9;4;"B<7E64?7;":26<:7;"9"
I2E6?:"?B"988:?G4=964?7"E?2BB4E4276;C"(B"@2";E932"612"E?::2;8?7A475"
F9;4;"B<7E64?7"FK"612"E?2BB4E4276;N"
" =c1
" =c2
" =c3"
N"97A";<="612":2;<36;"@2"?F6947"?<:"988:?G4=962A"B<7E64?7C"
"""""""""""""""""""""""""""""""""
#ciBi ="
�
i
ciTi(x) =
1Illustrations from [3]
4
Chapter 2
Chebyshev Polynomials
2.1 Definition
Chebyshev polynomials arise as the solution to the Chebyshev differential equation:
(1− x2)d2y
dx2− x
dy
dx+ n2y = 0 n = 0, 1, 2, . . . (2.1)
let x = cos t, the differential equation then becomes:
(1− cos2 t)
(d2y
dt2
(dt
dx
)2
+dy
dt
d2t
dx2
)− cos t
dy
dt
dt
dx+ n2y = 0
sin2 t
(d2y
dt2
(− 1√
1− cos2 t
)2
+dy
dt
(− cos t
(1− cos2 t)32
))− cos t
dy
dt
(− 1√
1− cos2 t
)+ n2y = 0
sin2 t
(d2y
dt2
(− 1
sin t
)2
+dy
dt
(− cos t
sin3 t
))− cos t
dy
dt
(− 1
sin t
)+ n2y = 0
sin2 t1
sin2 t
d2y
dt2− sin2 t
cos t
sin3 t
dy
dt+ cos t
1
sin t
dy
dt+ n2y = 0
d2y
dt2− cos t
sin t
dy
dt+
cos t
sin t
dy
dt+ n2y = 0
d2y
dt2+ n2y = 0
whose solution is given by [2]:
y = A cos(nt) +B sin(nt) |x| ≤ 1
y = A cos(n arccosx) +B sin(n arccosx) |x| ≤ 1
y = ATn(x) +BUn(x)
where Tn(x) and Un(x) is defined as the Chebyshev polynomial of the first and second kind respectively withdegree n. Both Chebyshev polynomials are in the domain [−1, 1] and have their degree n ∈ Z ∪ {0}. Thereare two kinds of Chebyshev polynomials but the focus will be on the first kind (this will be implied wheneverthe kind is not specified).
The Chebyshev polynomial can be generated by the following recurrence relation [2]:
T0(x) = 1
T1(x) = x
Tn+1(x) = 2xTn(x)− Tn−1(x)
(2.2)
5
In Scilab, the command chepol(n,var) generates the Chebyshev polynomial of degree n. Alternatively, if thecoefficient matrix of Chebyshev Polynomials T0(x) to Tn(x) is desired, listing 2.1 is more useful.
Listing 2.1: Fast Generation of the Coefficient Matrix of Chebyshev Polynomials from T0(x) to Tn(x)
//Generates an (n+1) by (n+1) c o e f f i c i e n t matrix o f the Chebyshev po lynomia l sfrom T 0 to T n .
function T = che c o e f f g e n (n)n = n + 1T = zeros (n , n)T(1 , 1 ) = 1i f n < 2
returnend
T(2 ,2 ) = 1
for i = 3 : nrow = 2 ∗ T( i −1 , : )row = [ 0 , row ( 1 : ( s ize ( row , ’ c ’ )−1) ) ]T( i , : ) = row − T( i − 2 , : )
endendfunction
-1
-0.5
0
0.5
1
1.5
-1 -0.5 0 0.5 1
n = 0n = 1
n = 2n = 3
n = 4n = 5
Figure 2.1: Graph of the first 6 Chebyshev Polynomials
A Chebyshev series of degree n is the linear combination of Chebyshev polynomials from 0 to n. That is,if Sn(x) is a Chebyshev series,
Sn(x) =n∑
i=0
ciTi(x) (2.3)
for some ci ∈ R. A smaller n means that Sn has a low degree while a larger n means Sn has a high degree.
6
2.1.1 Angle Domain (Angular Chebyshev)
The domain Chebyshev polynomial Tn(x) can be transformed to the angle domain T θn(t) = cos(nt) with
t ∈ [0, π] which is similar to how the Chebyshev differential equation is simplified. This effectively transformsthe Chebyshev polynomials into half of the Fourier series (the Fourier series includes the sin(x) functions1).Moreover, it should be noted that this transformation makes the distribution of points uniform. that is, whileTn(x) has a non-unity weight function, T θ
n(t) has no weight function (the weight function is 1) as seen in thenext section.
The Chebyshev Polynomials in the angular domain may be referred as the Angular Chebyshev Polynomialsbut it will be more accurate to call them the Angular Chebyshev series instead since they are not polynomialsanymore.
2.2 Orthogonality
The Chebyshev polynomial Tn(x) are orthogonal with respect to the weight
w(x) =1√
1− x2. (2.4)
The angular Chebyshev series, however, do not need a weight function (i.e. w(x) = 1).Orthogonality can be shown by integrating T θ
n(x)
∫ π
0
T θm(t)T θ
n(t)dt =
∫ π
0
cos(mt) cos(nt)dt =
0 m = n
π m = n = 0π2 otherwise
(2.5)
Proof:
If m = n = 0:
∫ π
0
cos(mt) cos(nt)dt =
∫ π
0
cos(0) cos(0)dt =
∫ π
0
dt = π.
If m = n = 0:
∫ π
0
cos(mt) cos(nt)dt =
∫ π
0
cos((n+m)t) + cos((n−m)t)
2dt∫ π
0
cos((n+m)t) + cos((n−m)t)
2dt =
∫ π
0
cos((n+m)t) + cos(0)
2dt =
∫ π
0
cos((n+m)t) + 1
2dt
=
[sin((n+m)t)
2(n+m)+
t
2
]π0
=sin((n+m)π)
2(n+m)+
π
2− sin(0)
2(n+m)− 0
2
since (n+m) ∈ Z, sin((n+m)π) = sin(π) = 0:
∫ π
0
cos(mt) cos(nt)dt =0
2(n+m)+
π
2=
π
2.
1More information on the Fourier series is provided by [4]
7
If n = m:
∫ π
0
cos(mt) cos(nt)dt =
∫ π
0
cos((n+m)t) + cos((n−m)t)
2dt
=
[sin((n+m)t)
2(n+m)+
sin((n−m)t)
2(n−m)
]π0
since (n+m), (n−m) ∈ Z:
∫ π
0
cos(mt) cos(nt)dt = 0. �
Note that no weight function is needed. Transforming it to Tn(x), x = cos t ⇒ −(1− x2)−0.5dx = dt:
∫ x(π)
x(0)
Tm(x)Tn(x)
−√1− x2
dx =
∫ 1
−1
Tm(x)Tn(x)√1− x2
dx =
∫ 1
−1
Tm(x)Tn(x)w(x)dx =
0 m = n
π m = n = 0π2 otherwise
(2.6)
2.3 Expansion of xn in a Series of Tn(x)
The Chebyshev polynomial is defined by the recurrence relation:
Tn+1(x) = 2xTn(x)− Tn−1(x)
Rewriting:
xTn(x) =1
2(Tn+1(x) + Tn−1(x))
xT1(x) = x2
xT0(x) = T1(x) = x
(2.7)
This gives us a recurrence relation for obtaining the expansion of xn as a series of Tn(x).
2.4 Rational Chebyshev Polynomials
Another variant of the Chebyshev polynomials, called Rational Chebyshev polynomials, is defined as follows:
Rn(x) = Tn
(x− 1
x+ 1
)(2.8)
with a weight function of:
wR(x) =1
(x+ 1)√x. (2.9)
All properties of Tn(x) carry over, to Rn(x).
8
2.5 Function Approximation
From 1.3, given a function f(x) defined on [−1, 1], there exist {c0, c1, . . . , cn} such that
f(x) ≈∑i
ciTi(x).
ci can be computed by
ci =1
λi
∫ 1
−1
f(x)Ti(x)w(x)dx (2.10)
where
λi =
π i = 0π
2i = 1, 2, 3, . . .
(2.11)
T θi can be used if f(x) is defined on [0, π]:
cθi =1
λi
∫ π
0
f(x)T θi (x)dx (2.12)
9
Chapter 3
Computation
3.1 Monte Carlo Integration
When integrating functions, the black box model is assumed where no other information about the functionis known other than the set out numerical outputs {y0, y1, . . . , yp} given the inputs {x0, x1, . . . , xp}. In orderto perform integration with this restriction, Monte Carlo integration has to be used.
Monte Carlo integration is based on the theory of probability[3]. A random variable is a mapping of anyevent (whether numerical or not) to a number. For example, a random variable for a coin toss C(x) will returna 1 for a head and 0 for a tail. Similarly, any function f(x) can be a random variable. A probability densityfunction (pdf) p(x) is any function with the following characteristics:
• p(x) > 0 ∀x ∈ D
•∫Dp(x)dx = 1.
A pdf models how often a certain event appears, that is, how the events are distributed. Examples of these isthe normal distribution (the “bell-shaped” curve), the uniform distribution and the binomial distribution. Instatistics, f(x) ∼ p(x) means that the random variable f(x) has the distribution of p(x). The expected valueof f(x), written as E[f(x)] is the average of the random variable which is defined as:
E[f(x)] =
∫D
f(x)p(x)dx. (3.1)
While this calculates the average value of the random variable, it is also possible to take the mean of a largenumber of random samples called µ (an “estimator” for the actual mean µ) of the random variable. Thisis shown to be consistent by the Law of Large Numbers thus converges to the actual expected value of therandom variable for sufficiently many samples:
E[f(x)] ≈ µ =1
p+ 1
p∑i=0
f(xi) (3.2)
Thus, the integral of f(x) can be approximated by:∫D
f(x)dx =
∫D
f(x)p(x)
p(x)dx = E
[f(x)
p(x)
]≈ 1
p+ 1
p∑i=0
f(xi)
p(xi).
If we assume that the distribution is uniform over the interval D = [a, b], we let p(x) = (b− a)−1 thus:
1
p+ 1
p∑i=0
f(xi)
p(xi)=
1
p+ 1
p∑i=0
(b− a)f(xi) =b− a
p+ 1
p∑i=0
f(xi).
Here, b− a is basically the “volume” of the domain of integration. For a one-dimensional case, it’s the lengthof the interval.
10
Summarizing everything:∫ b
a
f(x)dx ≈ b− a
p+ 1
p∑i=0
f(xi) (The Monte Carlo Integrator) (3.3)
Listing 3.1: Monte Carlo Integration
// In t e g r a t e s a func t i on us ing the Monte−Carlo method .////@param f The func t i on to i n t e g r a t e//@param x ar r The samples to e va l ua t e//@param volume The volume o f i n t e g r a t i o nfunction y = mc( f , x arr , volume )
n = s ize ( x arr , ’ ∗ ’ )y = 0for i = 1 : n
y = y + f ( x a r r ( i ) )endy = (y ∗ volume ) /n
endfunction
Combining this with section 2.5, the projection over the Chebyshev polynomials can be approximated by:
cn =1
λn
∫ 1
−1
f(x)Tn(x)w(x)dx ≈ 2
λn(p+ 1)
p∑i=0
f(xi)Tn(xi)w(xi). (3.4)
Listing 3.2: Generate a Vector of Chebyshev Polynomials from degree 0 to n
//Generates an (n+1) v e r t i c a l v e c t o r con ta in ing the Chebyshev po lynomia l s fromT 0 to T n .
function T = gen che a r r (n)T = [ ]for i = 1 : n+1
T = [T; chepol ( i −1, ’ x ’ ) ]end
endfunction
Listing 3.3: Project a Series of Points to the Chebyshev Polynomials
// Pro j e c t s a da t a s e t to the Chebyshev Polynomials////@param xs The x−va l u e s o f the da t a s e t .//@param ys The y=va lu e s o f the da t a s e t .//@param che arr A v e r t i c a l v e c t o r o f Chebyshev Polynomials generated by
gen che ar r .function a = che pro j ( xs , ys , ch e a r r )
function y = w(x )y = 1/ sqrt(1−x∗x )
endfunction
a = [ ]n = s ize ( che arr , ’ r ’ )v = linspace (1 , s ize ( xs , ’ ∗ ’ ) , s ize ( xs , ’ ∗ ’ ) )
11
for k = 1 : n
function y = fun ( j )y = ys ( j ) ∗horner ( che a r r ( k ) , xs ( j ) ) ∗w( xs ( j ) )
endfunction
i f k == 1a = [ a , mc( fun , v , 2) /%pi ]
elsea = [ a , mc( fun , v , 2) ∗ 2 /%pi ]
end
endendfunction
Note that there will be problems if the sample points land on −1 or 1 as this will cause divide-by-zero errorsin w(x) even if the improper integral Tn(x)w(x)dx converges. A solution to this is to simply remove samplepoints very close to −1 or 1.
For T θn :
cn =1
λn
∫ π
0
f(x)T θn(x)dx ≈ π
λn(p+ 1)
p∑i=0
f(xi)Tθn(xi) (3.5)
Listing 3.4: Project a Series of Points to the Angular Chebyshev Series
// Pro j e c t s a da t a s e t to a the angu lar Chebyshev s e r i e s up to degree n////@param xs The x−va l u e s o f the da t a s e t//@param ys The y−va l u e s o f the da t a s e t//@param n The degree o f the angu lar Chebyshev s e r i e s ( i . e . from T 0ˆ\ t h e t a ( x )
, . . . , T nˆ\ t h e t a ( x ) )function a = che ang l e p r o j ( xs , ys , n )
funcprot (0 )a = [ ]v = linspace (1 , s ize ( xs , ’ ∗ ’ ) , s ize ( xs , ’ ∗ ’ ) )
for k = 0 : n
function y = che c ( i )y = ys ( i ) ∗ cos ( k∗xs ( i ) )
endfunction
i f k == 0a = [ a , mc( che c , v , 1) ]
elsea = [ a , mc( che c , v , 2) ]
end
endendfunction
Since the Angular Chebyshev series are defined at all points, there are no numerical problems so the samplepoints on T θ
n(x) could straightforwardly be evaluated.
12
3.2 Evaluation
Given the coefficients of the basis functions, the actual function can be approximated as described in 1.3.
Listing 3.5: Evaluate the Chebyshev Polynomials
//Eva luate a Chebyshev po lynomia l////@param che arr The v e r t i c a l v e c t o r o f Chebyshev po lynomia l s generated by
gen che ar r .//@param a arr The ho r i z on t a l v e c t o r o f the c o e f f i c i e n t s o f the Chebyshev
po lynomia l s generated by che p ro j .//@param x The po in t to e va l ua t e .function y = che eva l ( che arr , a ar r , x )
y = 0n = s ize ( che arr , ’ r ’ )for i = 1 : n
y = y + a a r r ( i ) ∗ horner ( che a r r ( i ) , x )end
endfunction
Listing 3.6: Evaluate the Angular Chebyshev Series
//Eva luate an angu lar Chebyshev s e r i e s////@param a The angu lar Chebyshev c o e f f i c i e n t s generated by c h e an g l e p r o j ( a
h o r i z on t a l v e c t o r ) .//@param x The po in t to e va l ua t efunction y = che ang l e e va l ( a , x )
n = s ize ( a , ’ ∗ ’ )y = 0for i = 0 : n−1
y = y + a ( i + 1) ∗ cos ( i ∗ x )end
endfunction
3.3 Rational Polynomial Approximation
As a benchmark, the function f(x) will also be approximated using rational polynomials. A rational polynomialis the ratio of two polynomial functions. Thus:
f(x) ≈ g(x)
h(x)=
a0x0 + a1x
1 + · · ·+ amxm
b0x0 + b1x1 + · · ·+ bnxn=
∑mi aix
i∑nj bjx
j
Transposing the summation:n∑
j=0
f(x)bjxj =
m∑i=0
aixi
−m∑i=0
aixi +
n∑j=0
f(x)bjxj = 0. (3.6)
13
Which can be seen as a dot product of two vectors:
[−x0 −x1 . . . −xm f(x)x0 f(x)x1 . . . f(x)xn
]
a0a1...
amb0b1...bn
= 0
Suppose there are p data points (xi, yi) where yi = f(xi). The equation now expands to:
−x0
0 −x10 · · · −xm
0 y0x00 y0x
10 · · · y0x
n0
−x01 −x1
1 · · · −xm1 y1x
01 y1x
11 · · · y1x
n1
−x02 −x1
2 · · · −xm2 y2x
02 y2x
12 · · · y2x
n2
......
. . ....
......
. . ....
−x0p −x1
p · · · −xmp ypx
0p ypx
1p · · · ypx
np
a0a1...
amb0b1...bn
= 0.
However, this system will always have a trivial solution which is b0 = b1 = · · · = a0 = a1 = · · · = 0. Toprevent this, fix b0 = 1 which also prevents h(x) from turning 0 ∀x. This transforms (3.6) into:
−m∑i=0
aixi +
n∑j=1
f(x)bjxj = −f(x) (3.7)
Let:
A =
−x0
0 −x10 · · · −xm
0 y0x10 y0x
20 · · · y0x
n0
−x01 −x1
1 · · · −xm1 y1x
11 y1x
21 · · · y1x
n1
−x02 −x1
2 · · · −xm2 y2x
12 y2x
22 . . . y2x
n2
......
. . ....
......
. . ....
−x0p −x1
p · · · −xmp ypx
1p ypx
2p · · · ypx
np
x =
a0a1...
amb1b2...bn
b =
−y0x
00
−y1x01
−y2x02
...−ypx
0p
=
−y0−y1−y2...
−yp
(3.8)
Thus the equation is now represented by Ax = b where x can be solved by the least-squares method (i.e.solving the system ATAx = AT b).
Listing 3.7: Setup a Linear System for Rational Approximation
//Setup the system of equa t i ons f o r l e a s t−squares r a t i o n a l po lynomia l f i t t i n g .////@param xs The x−va l u e s o f the input .//@param ys The y−va l u e s o f the input ( shou ld be the same s i z e as xs ) .//@param num degree The degree o f the numerator o f the approximated r a t i o n a l .//@param den degree The degree o f the denominator o f the approximated r a t i o n a l .////@return A The c o e f f i c i e n t matrix . (As in Ax = b )//@return b The r e s u l t a n t v ec t o r . (As in Ax = b )
14
function [A, b ] = r a t i o n a l s e t up ( xs , ys , numerator degree , denominator degree )m = max(0 , numerator degree ) + 1n = max(0 , denominator degree ) + 1p = s ize ( xs , ’ ∗ ’ )
A = zeros (p , n + m − 1)b = zeros (p , 1)
for i = 1 : pb( i ) = −ys ( i )A( i , 1) = −1x = xs ( i )
for j = 2 :mA( i , j ) = −xi f j + m <= n + mA( i , j + m − 1) = ys ( i ) ∗ x
endx = x ∗ xs ( i )
endfor j = (2∗m) : ( n + m − 1)
A( i , j ) = ys ( i ) ∗ xx = x ∗ xs ( i )
endend
endfunction
Listing 3.8: Approximate a Function by a Rational Polynomial
// Fi t a da t a s e t to a r a t i o n a l po lynomia l////@param xs The x−va l u e s o f the input .//@param ys The y−va l u e s o f the input ( shou ld be the same s i z e as xs ) .//@param num degree The degree o f the numerator o f the approximated r a t i o n a l .//@param den degree The degree o f the denominator o f the approximated r a t i o n a l .////@return R A ra t i o n a l po lynomia l ( type ’ r a t i ona l ’ ) which b e s t f i t s the da t a s e t
.function R = ra t i ona l app rox ( xs , ys , num degree , den degree )
[A, b ] = r a t i o n a l s e t up ( xs , ys , num degree , den degree )x = A \ bnum = poly ( x ( 1 : num degree + 1) , ’ x ’ , ’ c o e f f ’ )den = poly ( [ 1 ; x ( num degree + 2 : num degree + 1 + den degree ) ] , ’ x ’ , ’ c o e f f ’ )R = num/den
endfunction
3.4 Rational to Chebyshev Polynomial Conversion
Since Chebyshev Polynomials are polynomials, it is possible to express of xn with a series of Chebyshevpolynomials to degree n. One method for directly calculating this is by the recurrence relation shown in 2.3.Another method for calculating all expansions from x0 to xn given the Chebyshev Polynomials from T0(x) toTn(x) will be detailed here.
15
Ti(x) = a0x0 + a1x
1 + · · ·+ aixi which can be written as:
[a0 a1 · · · ai
]x0
x1
...xi
=[Ti(x)
].
So the Chebyshev Polynomials with degrees from 0 to n can be written as:1 0 0 · · · 00 1 0 · · · 0−1 0 2 · · · 0...
......
. . ....
· · · · · · · · · · · · 2n−1
x0
x1
x2
...xn
=
T0(x)T1(x)T2(x)
...Tn(x)
.
Let
P =
1 0 0 · · · 00 1 0 · · · 0−1 0 2 · · · 0...
......
. . ....
· · · · · · · · · · · · 2n−1
x =
x0
x1
x2
...xn
T =
T0(x)T1(x)T2(x)
...Tn(x)
, (3.9)
where P is the coefficient matrix of the Chebyshev Polynomials T0(x) to Tn(x) (which can be generated bylisting 2.1); thus
Px = T.
Note that the Ti(x) has a polynomial degree at most i so the diagonals of P are non-zero and all entries afterith column in row i are zeroes. Moreover, if i is odd, all even entries are zero and if i is even, all odd entires arezero. Thus, P is a sparse and lower-triangular matrix with non-zero trace which means that P is non-singular.P has an inverse (which is easily computed) so the expansion of xn in terms of the Chebyshev polynomialscan be calculated by:
x = P−1T. (3.10)
This also provides us a way to express any polynomial function in terms of Chebyshev Polynomials. Givena polynomial function f(x) = a0x
0 + a1x1 + · · ·+ anx
n, a matrix A can be constructed such that:
f(x) = Ax =[a0 a1 · · · an
]x0
x1
...xn
.
A is a row vector where the ith element corresponds to the coefficient of xi. Premultiplying A to (3.10):
f(x) = Ax = AP−1T (3.11)
Note that A is a 1× (n+ 1) vector and P is a (n+ 1)× (n+ 1) matrix so AP−1 is a 1× (n+ 1) vector. Let
C =[c0 c1 · · · cn
]= AP−1. (3.12)
Substituting this into (3.11),
f(x) = CT = c0T0(x) + c1T1(x) + · · ·+ cnTn(x). (3.13)
16
C then contains the coefficients of the Chebyshev polynomials that correspond to the polynomial function. Calternatively can be expressed in column vector form as follows:
c0c1...cn
= P−TAT = P−T
a0a1...an
(3.14)
which can now be arranged in the standard matrix form:
PT
c0c1...cn
=
a0a1...an
. (3.15)
If f(x) is expressed as a rational function g(x)/h(x), the procedure is to simply calculate the Chebyshevcoefficients for g(x) and h(x) separately. Specifically, a coefficient matrix P with degree max{deg(g), deg(h)}must be created and this matrix can be used for both g(x) and h(x). The row coefficient vectors Ag and Ah
can then be created from the coefficients of the polynomials of g(x) and h(x) respectively. These matrices nowmay be plugged in to (3.12) to solve the Chebyshev coefficients of g(x) and h(x) separately. The Chebyshevcoefficients of g(x) and h(x) is equivalently called the Chebyshev rational coefficients of f(x) which is differentfrom the rational Chebyshev in 2.4.
Listing 3.9: Convert Coefficients of Rational Polynomials to Chebyshev Rational Coefficients
//Converts r a t i o n a l c o e f f i c i e n t s to Chebyshev Rat iona l c o e f f i c i e n t s .////@param ra t i o n a l A l i s t o f r a t i o n a l ( or j u s t a r a t i o n a l ) f unc t i on s to conver t .////@return B A l i s t o f 2 by max( degree ( numerator ) , degree ( denominator ) ) matr ices
con ta in ing the conver ted c o e f f i c i e n t s . Note t ha t even i f the numerator anddenominator vary in degree , the matrix w i l l have the width o f the max degree.
function B = ra t i o n a l t o c h e ( r a t i o n a l )i f typeof ( r a t i o n a l ) == ’ r a t i o n a l ’
r a t i o n a l = l i s t ( r a t i o n a l )end
nCases = length ( r a t i o n a l )maxDegree = 0for i = 1 : nCases
maxDegree = max(maxDegree , degree ( r a t i o n a l ( i ) .num) , degree ( r a t i o n a l ( i ) . den ))
endP = inv ( c h e c o e f f g e n (maxDegree ) )B = l i s t ( )
for i = 1 : nCasesnum = [ coeff ( r a t i o n a l ( i ) .num) , zeros (1 , maxDegree − degree ( r a t i o n a l ( i ) .num) )
]den = [ coeff ( r a t i o n a l ( i ) . den ) , zeros (1 , maxDegree − degree ( r a t i o n a l ( i ) . den ) )
]B( $ + 1) = [num ∗ P; den ∗ P]
endendfunction
17
Listing 3.10: Evaluation of Chebyshev Rationals
// Eva lua tes the Chebyshev Rat iona l Polynomial a t x////@param che arr An array o f chebyshev po lynomia l s genera ted by gen che ar r .//@param num den arr A 2 by s i z e ( che arr , ’ r ’ ) matrix con ta in ing the
c o e f f i c i e n t s o f the chebyshev po lynomia l s .//@param x The po in t o f e va l ua t i on .function y = ch e r a t i o n a l e v a l ( che arr , num den arr , x )
num = 0den = 0
n = s ize ( che arr , ’ r ’ )for i = 1 : n
z = horner ( che a r r ( i ) , x )num = num + num den arr (1 , i ) ∗ zden = den + num den arr (2 , i ) ∗ z
endy = num / den
endfunction
18
Chapter 4
Analysis
4.1 Methodology
The process of evaluating the accuracy of Chebyshev polynomials involves:
1. Generating 30, 50 and 100 equally-spaced points on the interval [0, π].
2. Using each set of points to approximate functions using the Monte Carlo Integration for Angular Cheby-shev Series and Least Squares for Rational Polynomials.
3. Generating 200 random points {x0, x1, . . . , x200} uniformly on the interval [0, π].
4. Calculating the mean square error (MSE) using the randomly generated points with the formula:
MSE =1
n
n∑i=1
(f(xi)− f(xi))2 (4.1)
where n = 200, xi is the randomly-generated point, f(x) is the actual function and f(x) is the approxi-mated function.
The approximating functions to be tested are as follows:
1. Rational:
(a) Numerator degree = 4, denominator degree = 2
(b) Numerator degree = 5, denominator degree = 5
(c) Numerator degree = 5, denominator degree = 8
2. Angular Chebyshev Series
(a) Up to degree 6.
(b) Up to degree 10.
(c) Up to degree 13.
4.2 Functions
The following functions will be used to benchmark:
1. Polynomials
(a) x
(b) x2 + 1
19
(c) 116 (231x
6 − 315x4 + 105x2 − 5) (Legendre Polynomial P6(x))
(d) 12 (5x
3 + 3x2 − 3x− 1) (Legendre Polynomials P2(x) + P3(x))
2. Exponential Functions
(a) ex
(b) ex−π2 − e−(x−π
2 )/128
(c) ex−π2 (ex−
π2 + e−x+π
2 )−1
3. Trigonometric Functions
(a) sin(x)
(b) tan( xπ − .5)
(c) sin(5x) cos(x)
(d) sin(10x) (High frequency oscillation)
(e) sin(50x) + cos(10x) (Combined high frequency oscillation)
4. Hyperbolic Functions
(a) sinh(x− π2 )
(b) tanh(x− π2 )
(c) sech(x− π2 )
Listing 4.1: Graphing and MSE Calculation of Function Approximation Methods
function y = po ly 0 (x )y = x
endfunction
function y = po ly 1 (x )y = xˆ2 − 1
endfunction
function y = po ly 2 (x )y = (231∗xˆ6 − 315 ∗ xˆ4 + 105 ∗ xˆ2 − 5) /16
endfunction
function y = po ly 3 (x )y = (5 ∗ xˆ3 + 3 ∗ xˆ2 − 3 ∗ x − 1) /2
endfunction
function y = exp 0 (x )y = exp( x )
endfunction
function y = exp 1 (x )y = exp( x − %pi/2) − exp(−(x − %pi/2) /128)
endfunction
function y = exp 2 (x )y = exp( x − %pi/2) . / (exp(x−%pi/2) + exp(−x + %pi/2) )
endfunction
function y = t r i g 0 (x )
20
y = sin ( x )endfunction
function y = t r i g 1 (x )y = tan ( x/%pi − . 5 )
endfunction
function y = t r i g 2 (x )y = sin (5∗x ) .∗ cos ( x )
endfunction
function y = t r i g 3 (x )y = sin (10∗x )
endfunction
function y = t r i g 4 (x )y = sin (50∗x ) + cos (10∗x )
endfunction
function y = hyp 0 (x )y = sinh ( x − %pi/2)
endfunction
function y = hyp 1 (x )y = tanh ( x − %pi/2)
endfunction
function y = hyp 2 (x )y = sech (x − %pi/2)
endfunction
// Ca l cu l a t e s the Mean Square Error between two ve c t o r s .function y = mse ( y0 , y1 )
y = 0n = min( s ize ( y0 , ’ ∗ ’ ) , s ize ( y1 , ’ ∗ ’ ) )for i = 1 : n
y = y + ( y0 ( i ) − y1 ( i ) ) ˆ2endy = y / n
endfunction
////Graphs the t e s t f unc t i on s aga in s t the func t i on approximat ions and c a l c u l a t e s
the MSE.////@param samp l eS i z e sL i s t A l i s t o f sample s i z e s//@param nTestPoints The number o f po in t s to t e s t aga ins f o r c a l c u l a t i n g the
MSE.//@param shou l dP lo t A boo lean s t a t i n g whether the f unc t i on s shou ld be p l o t t e d
or not . When p l o t t i n g the l egend placement i s s e t to i n t e r a c t i v e .////@return r e s u l t s A 3−dimensiona l typed l i s t con ta in ing the MSEs. The ( i ) ( j ) ( k )
entry corresponds to the k ’ th approximat ing func t i on o f the j ’ th t e s tf unc t i on wi th samp l eS i z e sL i s t ( i ) samples .
21
function r e s u l t s = s t a r t a n a l y s i s ( sampleS i ze sL i s t , nTestPoints , shou ldPlot )funcprot (0 )RATIONAL N DEG = [4 , 5 , 5 ]RATIONAL D DEG = [2 , 5 , 8 ]CHE N TERMS = [6 , 10 , 13 ]
function r e s u l t s = ana lyze func ( f , fname , xs , x t e s t )ys = f ( xs )r a t 0 = ra t i ona l app rox ( xs , ys , RATIONAL N DEG(1) , RATIONAL D DEG(1) )r a t 1 = ra t i ona l app rox ( xs , ys , RATIONAL N DEG(2) , RATIONAL D DEG(2) )r a t 2 = ra t i ona l app rox ( xs , ys , RATIONAL N DEG(3) , RATIONAL D DEG(3) )
che 0 = che ang l e p r o j ( xs , ys , CHE N TERMS(1) )che 1 = che ang l e p r o j ( xs , ys , CHE N TERMS(2) )che 2 = che ang l e p r o j ( xs , ys , CHE N TERMS(3) )
y t e s t = f ( x t e s t )ou tput ra t 0 = horner ( rat 0 , x t e s t )ou tput ra t 1 = horner ( rat 1 , x t e s t )ou tput ra t 2 = horner ( rat 2 , x t e s t )output che 0 = che ang l e e va l ( che 0 , x t e s t )output che 1 = che ang l e e va l ( che 1 , x t e s t )output che 2 = che ang l e e va l ( che 2 , x t e s t )
r e s u l t s = t l i s t ( [ ’ constant ’ , ’ r a t 0 ’ , ’ r a t 1 ’ , ’ r a t 2 ’ , ’ che 0 ’ , ’ che 1 ’ , ’che 2 ’ ] , . . .
mse ( ytes t , ou tput ra t 0 ) , . . .mse ( ytes t , ou tput ra t 1 ) , . . .mse ( ytes t , ou tput ra t 2 ) , . . .mse ( ytes t , output che 0 ) , . . .mse ( ytes t , output che 1 ) , . . .mse ( ytes t , output che 2 ) )
i f shou ldPlotf = s c f ( )f . f igure name = fnamef . a u t o r e s i z e = ”on”
plot2d ( xtes t ’ , . . .[ output rat 0 ’ output rat 1 ’ output rat 2 ’ output che 0 ’ output che 1 ’
output che 2 ’ ytes t ’ ] , . . .s t y l e = [2 , 3 , 4 , 5 , 6 , 7 , 1 ] )e = gce ( )lgnd = legend ( e . ch i ld ren , [ ”Rat iona l 4/2” ; ”Rat iona l 5/5” ; ”Rat iona l 5/8”
; . . .”Angular Chebyshev 6” ; ”Angular Chebyshev 10” ; ”Angular Chebyshev 13” ;
fname ] , 5)end
endfunction
r e s u l t s = l i s t ( )
x t e s t = gsort (rand (1 , nTestPoints ) ∗ %pi , ’ g ’ , ’ i ’ )
22
for sampleSize = samp l eS i z e sL i s txs = linspace (0 , %pi , sampleSize )r e s = t l i s t ( [ ’ constant ’ , . . .’ po ly 0 ’ , ’ po ly 1 ’ , ’ po ly 2 ’ , ’ po ly 3 ’ , . . .’ exp 0 ’ , ’ exp 1 ’ , ’ exp 2 ’ , . . .’ t r i g 0 ’ , ’ t r i g 1 ’ , ’ t r i g 2 ’ , ’ t r i g 3 ’ , ’ t r i g 4 ’ , . . .’ hyp 0 ’ , ’ hyp 1 ’ , ’ hyp 2 ’ ] , . . .ana lyze func ( poly 0 , ”Poly 1” , xs , x t e s t ) , . . .ana lyze func ( poly 1 , ”Poly 2” , xs , x t e s t ) , . . .ana lyze func ( poly 2 , ”Poly 3” , xs , x t e s t ) , . . .ana lyze func ( poly 3 , ”Poly 4” , xs , x t e s t ) , . . .ana lyze func ( exp 0 , ”Exp 1” , xs , x t e s t ) , . . .ana lyze func ( exp 1 , ”Exp 2” , xs , x t e s t ) , . . .ana lyze func ( exp 2 , ”Exp 3” , xs , x t e s t ) , . . .ana lyze func ( t r i g 0 , ”Trig 1” , xs , x t e s t ) , . . .ana lyze func ( t r i g 1 , ”Trig 2” , xs , x t e s t ) , . . .ana lyze func ( t r i g 2 , ”Trig 3” , xs , x t e s t ) , . . .ana lyze func ( t r i g 3 , ”Trig 4” , xs , x t e s t ) , . . .ana lyze func ( t r i g 4 , ”Trig 5” , xs , x t e s t ) , . . .ana lyze func ( hyp 0 , ”Hyp 1” , xs , x t e s t ) , . . .ana lyze func ( hyp 1 , ”Hyp 2” , xs , x t e s t ) , . . .ana lyze func ( hyp 2 , ”Hyp 3” , xs , x t e s t ) )
r e s u l t s ( $ + 1) = re send
endfunction
//// Ca l cu l a t e s the MSE of Chebyshev approximat ions o f f unc t i on f w. r . t . to the
sample s i z e and graphs them .////@param nSampleS i zesLis t An ascending l i s t ( not a vec t o r ) o f i n t e g e r s
con ta in ing the samples to be graphed . e . g . l i s t (10 , 20 , 30 , 40 , 50 , 60)//@param nTestPoints The number o f t e s t po in t s to be randomly generated and
t e s t e d aga in s t f o r MSE ca l c u l a t i o n .//@param te s tDeg ree s A l i s t o f i n t e g e r s o f the Angular Chebyshev po lynomia l s to
be t e s t e d . i . e . l i s t (3 , 5) w i l l t e s t a ga in s t T 0 ( x ) to T 3 ( x ) and T 0 ( x ) toT 5 ( x ) .
//@param f The func t i on to be ana lyzed .////@return mseGraphs A l en g t h ( nSampleS i zesLis t ) by l en g t h ( t e s tDeg ree s ) matrix
whose ( i , j ) th entry conta ins the MSE of Angular Chebyshev t e s tDegree s ( j )wi th sample s i z e nSampleS i zesLis t ( i )
function mseGraphs = chebyshev ana ly s i s ( nSampleSizesList , nTestPoints ,t e s tDegrees , f )
x t e s t = gsort (rand (1 , nTestPoints ) ∗ %pi , ’ g ’ , ’ i ’ )y t e s t = f ( x t e s t )mseGraphs = [ ]
for sampleSize = nSampleS izesL i s txs = linspace (0 , %pi , sampleSize )ys = f ( xs )
23
r e s = [ ]
for deg = te s tDegree sche approx = che ang l e p r o j ( xs , ys , deg )output che = che ang l e e va l ( che approx , x t e s t )r e s = [ res , mse ( ytes t , output che ) ]
endmseGraphs = [ mseGraphs ; r e s ]
end
f = s c f ( )
f . f i gure name = ”Chebyshev MSE Accuracy”f . a u t o r e s i z e = ”on”
leg names = [ ]for deg = te s tDegree s
leg names = [ leg names , ”n = ” + string ( deg ) ]end
x ax i s = [ ]for i = nSampleS izesL i s t
x ax i s = [ x ax i s ; i ]end
plot2d ( x ax i s , mseGraphs )e = gce ( )lgnd = legend ( e . ch i ld ren , leg names , 1)axes = gca ( )axes . x l a b e l . t ex t = ”Samples”axes . y l a b e l . t ex t = ”MSE”
endfunction
4.3 Results
Table 4.1 shows the mean square error calculations of the function approximation method with respect tospecific functions at 30 and 100 samples. The ‘a’, ‘b’,. . . suffix of function classes corresponds to the enumer-ation in section 4.2. Values less than 1 × 10−6 are rounded off to 0 while values exceeding 9999.0 and below0.1000 are shown in scientific notation. In the interest of space, note the shorthand m ⊕ n = m × 10n andm⊖n = m×10−n. For example, 5.12⊕3 = 5120 and 1.28⊖2 = .0128. Figure 4.1 shows the graphs of notablecases with 50 sample points.
4.4 Remarks
Angular Chebyshev series usually did worse than their rational counterparts as seen in table 4.1 and figure4.1. For straight lines, the angular Chebyshev series were not very accurate because of their oscillatory nature.Moreover, as seen in 4.1a, 4.1b and 4.1e, they tend to offshoot at the edges of of the function. The angularChebyshev series also did poorly for polynomials linearly independent of Chebyshev polynomials. However,for trigonometric functions, specifically for those with high frequencies, rational polynomials did a lot worse,
24
Tab
le4.1:
MeanSquareErrorsof
FunctionApproxim
ationat
VariousNumber
ofSam
pleswith20
0TestPoints
Function
Ratl.a
Ratl.b
Ratl.c
Cheb
.a
Cheb
.b
Cheb
.c
Inputs
30
100
30
100
3010
030
100
3010
030
100
Polya
0.000
0.000
0.00
00.00
00.00
00.00
02.40
0⊖2
2.98
4⊖3
3.31
9⊖2
3.33
4⊖3
3.71
9⊖2
3.48
1⊖3
Poly
b0.000
0.000
0.00
00.00
00.00
00.00
01.87
3⊖1
2.66
2⊖2
2.60
5⊖1
2.77
0⊖2
3.02
3⊖1
2.96
5⊖2
Polyc
1.756
1.393
0.12
88.35
6⊖2
22.10
18.37
4.88
7⊕5
1.40
1⊕5
5.55
5⊕5
8.27
3⊕4
5.94
6⊕5
7.01
1⊕4
Poly
d0.000
0.000
0.00
00.00
00.00
00.00
019
.07
3.16
925
.53
2.89
128
.441
2.888
Expa
0.000
0.000
0.00
00.00
01.44
0⊖5
0.00
01.40
40.24
191.84
90.21
292.02
90.2072
Expb
0.000
0.000
0.00
00.00
00.00
00.00
04.05
0⊖2
8.24
0⊖3
5.27
6⊖2
6.44
2⊖3
6.22
8⊖2
6.49
9⊖3
Expc
0.000
0.000
0.00
00.00
00.00
00.00
02.14
8⊖3
2.03
5⊖4
3.05
1⊖3
2.80
9⊖4
3.43
3⊖3
3.11
7⊖4
Triga
0.000
0.000
0.00
00.00
00.00
00.00
08.83
7⊖4
3.90
7⊖4
7.07
9⊖4
1.58
7⊖4
6.25
7⊖4
1.06
3⊖4
Trigb
0.000
0.000
0.00
00.00
00.00
00.00
01.44
0⊖3
2.22
0⊖4
2.31
8⊖3
2.20
6⊖4
3.38
8⊖3
2.94
9⊖4
Trigc
5.230
241
.16.09
421
5.3
223.4
7.14
118.34
3⊖2
8.26
9⊖2
5.11
1⊖3
4.97
3⊖3
1.83
2⊖3
1.51
2⊖3
Trigd
27.11
2.990
8.14
22.33
718
.43
16.00
0.45
900.45
910.22
030.21
821.10
2⊖2
1.07
6⊖2
Trige
4.218
3994
.030
9.2
1.64
577
.12
32.70
1.06
00.96
60.84
600.49
630.87
080.4938
Hypa
0.000
0.000
0.00
00.00
00.00
00.00
02.77
1⊖2
5.77
9⊖3
4.18
4⊖2
4.30
5⊖3
6.05
0⊖2
5.27
2⊖3
Hypb
0.000
0.000
0.00
00.00
00.00
00.00
03.76
7⊖3
3.53
6⊖4
6.45
4⊖3
5.78
6⊖4
9.55
0⊖3
8.49
2⊖4
Hypc
0.000
0.000
0.00
00.00
00.00
00.00
01.45
2⊖3
1.70
9⊖4
1.90
2⊖3
1.92
4⊖4
2.27
6⊖3
2.21
4⊖4
25
Figure 4.1: Graph of Functions and their Approximations at 50 Linear Sample Points
(a) Polynomial (a)
Rational 4/ 2Rational 5/ 5
Rational 5/ 8
Angular Chebyshev 6Angular Chebyshev 10Angular Chebyshev 13
Poly 1
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5
(b) Exponential (c)
Rational 4/ 2Rational 5/ 5
Rational 5/ 8
Angular Chebyshev 6Angular Chebyshev 10Angular Chebyshev 13
Exp 3
0.0
0.2
0.4
0.6
0.8
1.0
1.2
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5
(c) Trigonometric (c)
Rational 4/ 2Rational 5/ 5
Rational 5/ 8
Angular Chebyshev 6Angular Chebyshev 10Angular Chebyshev 13
Trig 3
- 30
- 25
- 20
- 15
- 10
- 5
0
5
10
15
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5
(d) Trigonometric (d)
Rational 4/ 2Rational 5/ 5
Rational 5/ 8
Angular Chebyshev 6Angular Chebyshev 10Angular Chebyshev 13
Trig 4
- 300
- 250
- 200
- 150
- 100
- 50
0
50
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5
(e) Hypergeometric (c)
Rational 4/ 2Rational 5/ 5
Rational 5/ 8
Angular Chebyshev 6Angular Chebyshev 10Angular Chebyshev 13
Hyp 3
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5
26
exhibiting numerical instability at some points (see figure 4.1c and 4.1d). Having higher-degree rationalpolynomials did not mitigate the instability but in fact, exacerbated it.
One thing to note about the Chebyshev series is that they are generally more stable than rational polyno-mials. While rational polynomials are more accurate in many cases, they exhibit instability on high-frequencyfunctions, specifically, they exhibit sharp jumps at some points. In contrast, the Chebyshev series are moreconsistent in their errors with no sharp jumps though their MSE is higher than the rational polynomials’.
Figure 4.2: MSE v.s. Sample Size for Poly (a) on Angular Chebyshev Series with 200 Test Points
n = 3n = 5n = 8n = 13
0
1
2
3
4
5
6
10 20 30 40 50 60 70 80 90 100
Samples
MSE
Also, another thing to note is that high degree Chebyshev series have higher MSEs then low degreeChebyshev series. However, with more sample points, high degree Chebyshev series benefit more than lowdegree Chebyshev series as seen in figure 4.2. In other words, high degree Chebyshev series are more sensitiveto sample sizes than low degree ones.
27
Bibliography
[1] Scilab Consortium. Scilab. Available from: http://www.scilab.org [cited September 15, 2010].
[2] Richard Culham. Chebyshev polynomials, March 2004. Available from: http://www.mhtl.uwaterloo.
ca/courses/me755/web_chap6.pdf [cited September 3, 2010].
[3] Robin Green. Spherical harmonic lighting: The gritty details [online]. January 2003. Available from: http://www.research.scea.com/gdc2003/spherical-harmonic-lighting.html [cited September 3, 2010].
[4] Gilbert Strang. Linear Algebra and Its Applications. Thomson Learning, 3rd edition, 1988.
28