31
數數數數 2008, Applied Mathematics NDHU 1 Numerical Integration

Numerical Integration

  • Upload
    etana

  • View
    105

  • Download
    0

Embed Size (px)

DESCRIPTION

Numerical Integration. Four 2-variate Gaussians. Four 2-variate Gaussians. Gaussian pdf. Weight sum of Gaussian pdfs. myfx4.m. Plot 4G. plot_4G.m. Integration of 4G. demo_int_4G.m. Double integration. Numeric calculus for double integrals. demo_ex2_4G.m. Example. - PowerPoint PPT Presentation

Citation preview

Page 1: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 1

Numerical Integration

Page 2: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 2

Four 2-variate Gaussians

Page 3: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 3

Four 2-variate Gaussians

Page 4: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 4

Gaussian pdf

Page 5: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 5

Weight sum of Gaussian pdfs

k

kkk pq ),|()( yAxx

Page 6: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 6

myfx4.m

Page 7: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 7

Plot 4Gplot_4G.m

Page 8: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 8

Integration of 4Gdemo_int_4G.m

Double integration

Page 9: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 9

Numeric calculus for double integrals

Page 10: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 10

D

yx dxdyedsyxf1

1

1

1

)( ),(22 2)1(erf

Plot of domain D(x, y)

-1.5

-1

-0.5

0

0.5

1

1.5

-1.5 -1 -0.5 0 0.5 1 1.5

Example

Approx. integral 2.230985141404140

True Integral 2.230985141404130

demo_ex2_4G.m

2.230985172585607 by dblquard.m

Page 11: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 11

exp(cos(x))plot_expcos.m

Page 12: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 12

Definite Integrationdemo_quad.m

Page 13: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 13

Symbolic integration

demo_int.m

Page 14: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 14

Example

-5 -4 -3 -2 -1 0 1 2 3 4 5-10

0

10

20

30

40

50

function of x:x.^2+2*x-5

fx1 =

Inline function: fx1(x) = 1./3.*x.^3+x.^2-5.*x

Page 15: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 15

Numerical integration - quadrature

Page 16: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 16

Counter example

>> demo_intfunction of x:(1-sin(x.^2)).^(1/3)Warning: Explicit integral could not be found.

Page 17: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 17

-5 -4 -3 -2 -1 0 1 2 3 4 50

0.2

0.4

0.6

0.8

1

1.2

1.4

Page 18: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 18

plot_sin13.m

Page 19: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 19

Numerical integration

demo_quad2.m

Page 20: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 20

Mesh

Page 21: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 21

Lower and upper sum

Page 22: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 22

Lower sum : lower bound

Page 23: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 23

Upper sum : upper bound

Page 24: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 24

Composite Trapezoid rule

Page 25: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 25

Uniform mesh

Page 26: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 26

Error Analysis

Page 27: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 27

Partition size

Page 28: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 28

Composite Trapezoid rule

input s, a and b f = inline(s); Set n h = (b-a)/n; ans = 1/2*(f(a)+f(b)) for i=1:n-1 add f(a+i*h) to ans ans= ans*h

Page 29: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 29

f = inline(s); Set nh = (b-a)/n; ans = 1/2*(f(a)+f(b))

Input s,a,b

Flow Chart

for i=1:n-1

add f(a+i*h) to ansans=

ans*h

EXIT

Page 30: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 30

Simpson rule for numerical integration

b

aabfbfbafafabdxxf

baCf

5)4(

4

)(2880

)()()2

(4)(6

)(

withexists b)(a,in number a then ],,[ If

Page 31: Numerical   Integration

數值方法2008, Applied Mathematics NDHU 31

Exercise

Draw a flow chart to illustrate integration by the composite Trapezoid rule

Implement the composite Trapezoid rule for numerical integration, including flow chart and Matlab codes

Test your matlab function with the following integration

* Test your matlab function with definite integration of the weight sum of four Gaussian pdfs

* Compare your results with those obtained by using quad.m

f(x)=exp(cos(x))

0)(xf