3. 3
Introduction
• Newton-Cotes and Romberg Integration usually use
table of the values of function.
• These methods are exact for polynomials less than N
degrees.
• General formula of these methods are as bellow:
b n
∫ f ( x)dx ≅ ∑w
a i =1
i f ( xi )
• In Newton-Cotes method the subintervals has the
same length.
4. 4
• But in Gaussian Integration we have the exact
formula of function.
• The points and weights are distinct for specific
number N.
5. 5
Gaussian Integration
• For Newton-Cotes methods we have:
b
b −a
1. ∫ f ( x )dx ≅ [ f (a) + f (b)].
a
2
b
b −a a +b
2. ∫
b
f ( x )dx ≅
6
f (a ) + 4 f (
2
) + f (b) .
• And in general form:
b n
∫ f ( x)dx ≅ ∑ w f ( x )i i xi = a + (i − 1)h i ∈ {1,2,3,..., n}
a i =1
n
b− a n t− j
wi = ∏ dt
n − 1 ∫ j =1, j ≠ i i − j
0
6. 6
• But suppose that the distance among points are not
equal, and for every w and x we want the integration
to be exact for polynomial of degree less than 2n-1.
n 1
1.∑ wi = ∫ dx
i =1 −1
n 1
2.∑ xi wi = ∫ xdx
i =1 −1
.............
n 1
2n.∑ x 2 n −1 wi = ∫ x 2 n −1 dx
i =1 −1
7. 7
• Lets look at an example:
n =2 w1 , w2 , x1 , x 2 .
.w1 + w2 = 2
1
2.x w + x w = 0
1 1
2 2
1
2 ⇒2,4 ∴x 1 = x 2 ⇒3 ∴x 1 = .
2 2 2
2
.x 1 w1 + x 2 w2 = 3
2
3 3
3
4.x 1 w1 + x 3 2 w2 = 0
1
x1 = −x 2 = , w1 = w2 =1.
3
• So 2-point Gaussian formula is:
1
1 −1
−
∫
1
f ( x ) dx ≅ f (
3
)+ f(
3
).
8. 8
Legendre Polynomials
• Fortunately each x is the roots of Legendre Polynomial.
1 d 2
PN ( x) = ( x − 1) n . n = 0,1,2,.....
2 n n! dx
• We have the following properties for Legendre
Polynomials.
1.Pn ( x) Has N Zeros in interval(-1,1).
2.( n +1) Pn +1 ( x ) = ( 2n +1) xPn ( x ) − nPn −1 ( x).
1
2
3. ∫ Pn ( x ) Pm ( x) dx = δmn
−1
2mn +1
1
4. ∫ x k Pn ( x) dx = 0 k = 0,1,2......, n - 1
−1
2 n +1 ( n!) 2
1
5.∫ x Pn ( x ) dx =
n
-1
(2n +1)!
9. 9
• Legendre Polynomials make orthogonal bases in (-1,1)
interval.
• So for finding Ws we must solve the following
equations:
n 1
1.∑ wi = ∫ dx = 2
i =1 −1
n 1
2.∑ wi x 2
i = ∫ xdx = 0
i =1 −1
....................
....................
n 1
1
n.∑ wi x n −1i = ∫ x n −1 dx = (1 − (−1) n )
i =1 −1
n
10. 10
• We have the following equation which has unique
answer:
... x1 w1
n −1 T 2
1 x1
1 x2 ... x 2 w2
n −1 0
. = .
... ... ... ...
1
1 ... x n wn n (1 − (− 1) )
n −1 n
xn
• Theorem: if Xs are the roots of legendre polynomials
1
and we got W from above equation then ∫P ( x)dx is −
1
exact for P ∈Π2 n −1 .
11. 11
• Proof:
p ∈ Π 2 n −1 ⇒ p( x) = q ( x) Pn ( x) + r ( x).
n −1 n −1
q( x) = ∑ q j Pj ( x) ; r ( x) = ∑ r j Pj ( x).
j =0 j =0
1 1 1 n −1 n −1
∫ p( x)dx = ∫ (q( x) P ( x) + r ( x))dx = ∫ ( P ( x)∑ q P ( x) + ∑ r P ( x))dx =
-1 −1
n
−1
n
j =0
j j
j =0
j j
n −1 1 n −1 1
∑ q ∫ P ( x) P ( x)dx + ∑ r ∫ P ( x) P (x)dx = 2r .
j =0
j j n
j =0
j 0 j 0
−1 −1
⇒
n n n
∑ w p( x ) = ∑ w (q( x ) P
i =1
i i
i =1
i i N ( x) + r ( xi )) = ∑ wi r ( xi )
i =1
n n −1 n −1 n n −1 1
= ∑ wi ∑ r j Pj ( xi ) = ∑ r j ∑ wi Pj ( x) = ∑ r j ∫ Pj ( x)dx = 2r0 .
i =1 j =0 j =0 i =1 j =0 −1
12. 12
Theorem:
1 n (x − x j )
wi = ∫ [ Li ( x )] dx ∏ (x
2
Li ( x ) =
−1 j = , j ≠i
1 i −xj )
Proof:
1 2
[ Li ( x)] 2 ∈ Π 2 n−2 ⇒ ∫ [ Li ( x)] 2 = ∑ w j [ Li ( x j )]
n
= wi .
−1 j =1
13. 13
Error Analysis for
Gaussian Integration
• Error analysis for Gaussian integrals can be derived
according to Hermite Interpolation.
b
Theorem : The error made by gaussian integration in approximation the integral ∫ f ( x )dx is ::
a
(b − a ) 2 n +1 ( N !) 4
EN ( f ) = f (2n)
(ξ ) ξ ∈ [ a, b].
(2n + 1)((2n)!) 3
14. 14
Gaussian Integration for Improper
Integrals
• Suppose we want to compute the following integral:
1
f ( x)
∫
−1 1−x2
dx
• Using Newton-Cotes methods are not useful in here
because they need the end points results.
• We must use the following:
1 1−ε
f ( x) f ( x)
∫
−1 1− x 2
dx ≅ ∫ε
−1+ 1− x 2
dx
15. 15
• But we can use the Gaussian formula because it does
not need the value at the endpoints.
• But according to the error of Gaussian integration,
Gaussian integration is also not proper in this case.
• We need better approach.
Definition : The Polynomial set { Pi } is orthogonal in (a, b) with respect to w(x) if :
b
∫ w( x) P ( x)P
a
i j ( x) dx = 0 for i ≠ j
then we have the following approximation :
b n
∫ w( x) f ( x)dx ≅ ∑ wi f ( xi )
a i =1
where xi are the roots for Pn and
b
wi = ∫ w( x)[ Li ( x)] dx
2
a
will compute the integral exactly when f ∈ Π 2 n −1
16. 16
Definition : Chebyshev Polynomials Tn ( x ) is defined as :
n
2
n
Tn ( x ) = ∑ x n −2 k ( x 2 −1) k
k =0 2 k
Tn ( x ) = 2 xTn ( x) − Tn −1 ( x), n ≥ 1, T0 ( x) = 1, T1 ( x ) = x.
If - 1 ≤ x ≤ 1 then :
( 2i −1)π
Tn ( x ) = cos( n arccos x). roots xi = cos .
2n
1
1
∫
−1 1−x 2
Ti ( x )T j ( x ) dx = 0 if i ≠ j.
• So we have following approximation:
1
1 π n (2i − 1)π
∫ f ( x)dx ≅ ∑ f ( xi ), xi = cos
n i =1 2n i ∈ {1,2,3,..., n}.
−1 1− x2
17. Legendre-Gaussian Integration
17
Algorithms
a,b: Integration Interval,
N: Number of Points,
f(x):Function Formula.
Initialize W(n,i),X(n,i).
Ans=0;
b−a b−a a+b
A( x ) = f( x+ ).
2 2 2
For i=1 to N do:
Ans=Ans+W(N,i)*A(X(N,i));
Return Ans;
End
Figure 1: Legendre-Gaussian Integration Algorithm
18. 18
a,b: Integration Interval,
tol=Error Tolerance.
f(x):Function Formula.
Initialize W(n,i),X(n,i).
Ans=0;
b −a b −a a +b
A( x ) = f( x+ ).
2 2 2
For i=1 to N do:
If |Ans-Gaussian(a,b,i,A)|<tol then return Ans;
Else
Ans=Gaussian(a,b,i,A);
Return Ans;
End
Figure 2: Adaptive Legendre-Gaussian Integration Algorithm.
(I didn’t use only even points as stated in the book.)
19. 19
Chebychev-Gaussian Integration
Algorithms
a,b: Integration Interval,
N: Number of Points,
f(x):Function Formula.
(b − a ) a +b a −b
A( x) = 1 − x 2 f( + x)
2 2 2
For i=1 to N do:
Ans=Ans+ A(xi); //xi chebyshev
roots
Return Ans*pi/n;
End
Figure 3: Chebyshev-Gaussian Integration Algorithm
20. 20
a,b: Integration Interval,
tol=Error Tolerance.
f(x):Function Formula.
(b − a ) a + b a − b
A( x ) = 1 − x 2 f( + x)
2 2 2
For i=1 to N do:
If |Ans-Chebyshev(a,b,I,A)|<tol then return Ans;
Else
Ans=Chebyshev(a,b,I,A);
Return Ans;
End
Figure 4: Adaptive Chebyshev-Gaussian Integration Algorithm
21. 21
Example and MATLAB
Implementation and Results
Figure 5:Legendre-Gaussian Integration
25. 25
Testing Strategies:
• The software has been tested for
polynomials less or equal than 2N-1
degrees.
• It has been tested for some random inputs.
• Its Result has been compared with MATLAB
Trapz function.
33. 33
Conclusion
• In this talk I focused on Gaussian Integration.
• It is shown that this method has good error
bound and very useful when we have exact
formula.
• Using Adaptive methods is Recommended Highly.
• General technique for this kind of integration
also presented.
• The MATLAB codes has been also explained.