You are on page 1of 8

Introduction

Outline
Numerical Integration with
Unequal Segments
Matlab
Multiple Integrals
Matlab
In-Class Problem due
Thursday, November 13th

Homework due Tuesday 11/18


Chapra: 19.2, 19.5, 19.7,
19.21, 20.1, 20.17

Composite Trapezoid Rule

Recall integration interval divided into n equal segments and


trapezoid rule applied to each segment

I ba

n1

f x 0 f xi f xn
i1

2n

With n unequal segments


I h1

h f x f x ... h f x f x

f x 0 f x1
2

n1

where hi is the width of segment i


**Note that the fi term in one integral is the fi-1 term in the next

Matlab: Composite Trapezoid Rule

z = trapz(x,y)
x and y are vectors of data
z is a scalar value of the integral
Works for both equal and unequal segments

Double Integral

Integrate in one dimension first, then in the second dimension


Order is not important
d

f x,y dx dy f x,y dy dx

Double Integral: Analytical Solution

Example: T(x,y) = 2xy + 2x x2 2y2 + 72 for plate that is 8 m long


(x direction) and 6 m wide (y direction). Calculate average T.
6 8

2xy 2x x
0 0

2y 72 dxdy
2

6 0 8 0

x
2
2
2
x
y

2xy
72x dy

3
0
0

6 0 8 0

512
16y
2
512
2
32y

64y

576y

64y 64 3 16y 576 dy


3
3
0
0

60 80
60 80
6

1152 384 1024 1152 3456 2816

58.67
48
48

Double Integral: Numerical Solution

Example: T(x,y) = 2xy + 2x x2 2y2 + 72 for plate that is 8 m long


(x direction) and 6 m wide (y direction). Calculate average T.
6 8

2xy 2x x
0 0

2y 2 72 dxdy

6 0 8 0

Two segment composite trapezoid needs to be evaluated at 3 x and


3 y data points
x

f(x,y)

72

54

64

70

40

24

54

48

Double Integral: Numerical Solution

Two segment composite trapezoid needs to be evaluated at 3 x and


3 y data points
x

f(x,y)

72

54

64

70

40

24

54

48

Integrate over x first


72 2 64 24
448
y = 0: I 8

54 2 70 54

y = 3: I 8

496

y = 6: I 8

0 2 40 48

256

Integrate over y second

448 2 496 256

I 6

Average
2544
53 58.67
48

2544

Matlab: Double Integral

q = dblquad(fun,xmin,xmax,ymin,ymax,tol)
Example: q = (@(x,y) 2*x*y + 2*x x^2 2y^2 + 72, 0, 8, 0, 6)

**Note: triplequad works exactly the same for a 3-dimensional function

You might also like