Gaussian Integration

Preview:

DESCRIPTION

Presented at Computer Science Department, Sharif University of Technology (Advanced Numerical Methods).

Citation preview

1

Gaussian Gaussian IntegrationIntegration

M. Reza Rahimi,M. Reza Rahimi,Sharif University of Technology,Sharif University of Technology,

Tehran, Iran.Tehran, Iran.

2

OutlineOutline• Introduction• Gaussian Integration• Legendre Polynomials• N-Point Gaussian Formula• Error Analysis for Gaussian Integration• Gaussian Integration for Improper Integrals• Legendre-Gaussian Integration Algorithms• Chebyshev-Gaussian Integration Algorithms• Examples, MATLAB Implementation and Results• Conclusion

3

IntroductionIntroduction• 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:

• In Newton-Cotes method the subintervals has the same length.

b

a

n

iii xfwdxxf

1

)()(

4

• But in Gaussian Integration we have the exact formula of function.

• The points and weights are distinct for specific number N.

5

Gaussian Gaussian IntegrationIntegration

• For Newton-Cotes methods we have:

• And in general form:

.)()2

(4)(6

)( .2

.)()(2

)( .1

b

bfba

fafab

dxxf

bfafab

dxxf

b

b

a

dtji

jt

n

abw

nihiaxxfwdxxf

n n

ijji

b

a

n

iiii

0 ,1

1

1

,...,3,2,1 )1( )()(

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.

1

1

12

1

12

1

1

1

1

1

1

.2

.............

.2

.1

dxxwxn

xdxwx

dxw

ni

n

i

n

n

iii

n

ii

7

• Lets look at an example:

• So 2-point Gaussian formula is:

.1 ,3

1

.3

134,2

0.4

3

2.3

0.2

2.1

.,,, 2

2121

12

22

12

223

113

222

112

2211

21

2121

wwxx

xxx

wxwx

wxwx

wxwx

ww

xxwwn

.)3

1()

3

1()(

1

1

ffdxxf

8

Legendre Legendre PolynomialsPolynomials

• Fortunately each x is the roots of Legendre Polynomial.

• We have the following properties for Legendre Polynomials.

.0,1,2,....n .)1(!2

1)( 2 n

nN xdx

d

nxP

1

1-

21

1

1

1

1

11

)!12(

)!(2)(5.

1-n.,0,1,2.....k 0)(.4

12

2)()(.3

).()()12()()1(2.

1,1).interval(-in ZerosN Has )(.1

n

ndxxPx

dxxPx

mndxxPxP

xnPxxPnxPn

xP

n

nn

nk

mnmn

nnn

n

9

• Legendre Polynomials make orthogonal bases in (-1,1) interval.

• So for finding Ws we must solve the following equations:

))1(1(1

.

....................

....................

0.2

2.1

1

1

1

1

1

n

1i

1

1

2

1

11

nnn

i

in

i

ii

n

ii

ndxxxwn

xdxxw

dxw

10

• We have the following equation which has unique answer:

• Theorem: if Xs are the roots of legendre polynomials and we got W from above equation then is exact for .

1

1

)( dxxP

12 nP

))1(1(1

.

0

2

.

...1

............

...1

...1

2

1

1

122

111

n

n

T

nnn

n

n

nw

w

w

xx

xx

xx

11

• Proof:

.2)()()(

)())()()(()(

.2)()()()(

))()()(())()()(()(

).()( ; )()(

).()()()(

0

1

1

1

01

1

01

1

0

1 1 1

0

1

1

0

1

0

1

1

1

0

1

0

1

1

1

0

1

1-

1

1

1

0

1

0

12

rdxxPrxPwrxPrw

xrwxrxPxqwxpw

rdxxPxPrdxxPxPq

dxxPrxPqxPdxxrxPxqdxxp

xPrxrxPqxq

xrxPxqxpp

j

n

jj

n

iji

n

jj

n

i

n

jijji

n

i

n

i

n

iiiiNiiii

j

n

jjnj

n

jj

n

jjj

n

jjjnn

n

jjj

n

jjj

nn

12

Theorem:

1

1 ,1

2

)(

)()( )(

n

ijj ji

jiii xx

xxxLdxxLw

Proof:

.)()()(21

1 1

222

2i

n

jjijini wxLwxLxL

13

Error Analysis for Error Analysis for Gaussian IntegrationGaussian Integration

• Error analysis for Gaussian integrals can be derived according to Hermite Interpolation.

.ba, )())!2)((12(

)!()()(

::is )( integral ion theapproximatin n integratiogaussian by madeerror The :Theorem

)2(3

412

b

a

nn

N fnn

NabfE

dxxf

14

Gaussian Integration for Improper Gaussian Integration for Improper IntegralsIntegrals

• Suppose we want to compute the following integral:

• Using Newton-Cotes methods are not useful in here because they need the end points results.

• We must use the following:

1

121

)(dx

x

xf

dxx

xfdx

x

xf

1

12

1

12 1

)(

1

)(

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.

12

2

b

a 1

en exactly wh integral thecompute will

)()(

and for roots theare where

)()()(

:ionapproximat following thehave then we

jifor 0)()()(

:if w(x)respect to with b)(a,in orthogonal is Pset Polynomial The :Definition

n

b

a

ii

ni

n

iii

j

b

a

i

i

f

dxxLxww

Px

xfwdxxfxw

dxxPxPxw

16

• So we have following approximation:

1

12

101

222

0

j.i if 0)()(1

1

.2

)12(cos roots ).arccoscos()(

: then11- If

.)(,1)( ,1 ),()(2)(

)1(2

)(

:as defined is )( sPolynomial Chebyshev :Definition

dxxTxTx

n

ixxnxT

x

xxTxTnxTxxTxT

xxk

nxT

xT

ji

in

nnn

kkn

n

kn

n

.,...,3,2,1 2

)12(cos ,)()(

1

1

1

1

12

nin

ixxf

ndxxf

x

n

iii

17Legendre-Gaussian Integration Legendre-Gaussian Integration

AlgorithmsAlgorithmsa,b: Integration Interval,

N: Number of Points,f(x):Function Formula.

Initialize W(n,i),X(n,i).Ans=0;

).22

(2

)(ba

xab

fab

xA

For i=1 to N do:Ans=Ans+W(N,i)*A(X(N,i));

Return Ans;

End

FigureFigure 1: Legendre-Gaussian Integration Algorithm1: Legendre-Gaussian Integration Algorithm

18

a,b: Integration Interval,tol=Error Tolerance.

f(x):Function Formula.

Initialize W(n,i),X(n,i).Ans=0;

).22

(2

)(ba

xab

fab

xA

For i=1 to N do:If |Ans-Gaussian(a,b,i,A)|<tol then return Ans;

ElseAns=Gaussian(a,b,i,A);

Return Ans;

End

Figure 2: Adaptive Legendre-Gaussian Integration Algorithm.Figure 2: Adaptive Legendre-Gaussian Integration Algorithm.(I didn’t use only even points as stated in the book.)(I didn’t use only even points as stated in the book.)

19

Chebychev-Gaussian Integration Chebychev-Gaussian Integration AlgorithmsAlgorithms

a,b: Integration Interval,N: Number of Points,

f(x):Function Formula.

For i=1 to N do:Ans=Ans+ A(xi); //xi chebyshev

roots

Return Ans*pi/n;

End

FigureFigure 3: Chebyshev-Gaussian Integration Algorithm3: Chebyshev-Gaussian Integration Algorithm

)22

(2

)(1)( 2 x

babaf

abxxA

20

a,b: Integration Interval,tol=Error Tolerance.

f(x):Function Formula.

For i=1 to N do:If |Ans-Chebyshev(a,b,I,A)|<tol then return Ans;

ElseAns=Chebyshev(a,b,I,A);

Return Ans;

End

Figure 4: Adaptive Chebyshev-Gaussian Integration AlgorithmFigure 4: Adaptive Chebyshev-Gaussian Integration Algorithm

)22

(2

)(1)( 2 x

babaf

abxxA

21

Example and MATLAB Example and MATLAB Implementation and ResultsImplementation and Results

Figure 5:Legendre-Gaussian IntegrationFigure 5:Legendre-Gaussian Integration

22

Figure 6: AdaptiveFigure 6: Adaptive Legendre-Gaussian IntegrationLegendre-Gaussian Integration

23

Figure 7:Chebyshev-Gaussian IntegrationFigure 7:Chebyshev-Gaussian Integration

24

Figure 8:Adaptive Chebyshev-Gaussian IntegrationFigure 8:Adaptive Chebyshev-Gaussian Integration

25

Testing Strategies: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.

26

Examples:Examples:

1.5833.Resualt Software To According

1.5000.Resualt Software To According

.6667.1))1(1

1

)0(1

14

)1(1

1)(

6

)1(1(

.0000.1))1(1

1

)1(1

1)(

2

)1(1(

.5707.12

)1tan()1tan(1

1

int3

int2

222

22

1

12

GaussianPo

GaussianPo

Simpson

Trapezoid

exact ArcArcdxx

Example 1:Gaussian-LegendreExample 1:Gaussian-Legendre

27

0.4640.

0.6494.

.0792.0)35.10)(6

03(

.0005.0)30)(2

03(

.4999.0)2

1

2()

2(

int3

int2

95.1

9

930

3

0

2

2

2

GaussianPo

GaussianPo

Simpson

Trapezoid

xexactx

ee

e

eedxxe

.3105|))!2)((12(

)!()02(|

.4105|)(sin))!2)((12(

)!()0(|)sin(

b].[a, )())!2)((12(

)!()()(

43

4122

0

423

412

0

23

412

nenn

ndxe

nnn

ndxx

fnn

nabfE

nx

nn

nn

n

Example 2:Gaussian-LegendreExample 2:Gaussian-Legendre

Example 3:Gaussian-LegendreExample 3:Gaussian-Legendre

28

.00008.0error1.151376

.00027.0error1.151565

.36227.0error1.149024

.00871.0error1.142583

.06493.0error1.21622 2

.15129.1)1ln(2

1

1

a

a

a

a

a

23

02

xdxx

x

.00005.0error0.499896

.00013.0error0.500075

.00275.0error0.502694

.03597.0error0.463973

.14943.0error0.649372

.49994.02

a

a

a

a

a

3

0

3

0

2

2

x

x edxxe

Example 4:Gaussian-LegendreExample 4:Gaussian-Legendre

Example 5:Gaussian-LegendreExample 5:Gaussian-Legendre

29

877755.1.47666903Point-3

385020.5.91940603Point2

::)sin(

019234.2.35619449Point-3

019234.2.35619449Point2

::)sin(

236915.1.60606730Point-3

797927.1.19283364Point2

::)sin(

339745.0.78539816Point-3

339745.0.78539816Point-2

::)sin(

2

0

2

2

3

0

2

0

2

2/

0

2

dxx

dxx

dxx

dxx

Example 6:Gaussian-LegendreExample 6:Gaussian-Legendre

6626731.57079632::Trapzoid

9892102.35580550::Trapzoid

3556793.14159265::Trapzoid

6903600.78460183::Trapzoid

749986.3.14131064 Point-8

162258.3.14132550Point-7

123817.3.14606122Point-6

211956.3.08922572Point-5

676239.3.53659228Point-4

-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 10

0.5

1

1.5

2

2.5

3

3.5

-0.57 0.57 -0.77 0.77

30

448013.1.15137188105error::nIntegratioGaussian Adaptive)2

351486.1.15114335105error::nIntegratioGaussian Adaptive)1

::1

4-

5-

3

02

dxx

x

784837.0.49988858105error::nIntegratioGaussian 2)Adaptive

291620.0.49980229105error::nIntegratioGaussian 1)Adaptive

::

4-

5-

3

0

2

dxxe x

Example 7:Adaptive Gaussian-LegendreExample 7:Adaptive Gaussian-Legendre

31

4082711.39530571 nIntegratio ChebyshevPoint -3

428604.0.48538619nIntegratio ChebyshevPoint -2

565488.0.33089431::ChebyshevPoint -3

0::ChebyshevPoint -2

Example 8:Gaussian-ChebyshevExample 8:Gaussian-Chebyshev

32Example 9:Example 9:

0)6

5

2)5

0)4

3

2)3

0)2

2)1

533

522

511

433

422

411

333

322

311

233

222

211

332211

321

xwxwxw

xwxwxw

xwxwxw

xwxwxw

xwxwxw

www

21

23

22

322

21

23

311

22

2322

23

2111

23

522

511

322

311

23

322

311

2211

)()(),()(1

5,4

14,2

xx

xxxwxxxwxxxwxxxw

xxwxw

xwxw

xxwxw

xwxw

212

12

3122

32

111 ))(()( wwxxxwxxxw

214

112

11

332121

5

3.

5

22,

3

225,3

.0)2,

xxxwxw

xwxxww

09

81

9

5

3

22 3321

211 xwwwxw

0,5

3,

5

3,,

9

8,

9

5,

9

5,,

321

321

xxx

www

33

ConclusioConclusionn

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

Recommended