Docsity

The Trapezoidal Rule - Lecture Notes | AER E 161, Study notes of Aerospace Engineering

Toggle sidebar
bg1
D. Haugli, Lecturer Aer E 161 Aerospace Engineering
5/1/2003 The Trapezoidal Rule, Page 1 Iowa State University
The Trapezoidal Rule
The trapezoidal rule uses a first-order polynomial (i.e., the equation of a line) to estimate the
function
()
xf in the incremental integral,
()
∫
−
=
i
i
x
x
idxxfI
1
.
Thus,
()
xaayxf 101 +=≅ . To avoid confusion, the subscript 1 on 1
y (indicating that the
polynomial is first-order) will be dropped in the derivation that follows.
With a bit of algebraic trickery, the solution to the incremental integral is,
()
()
()
()()()
()
()()
() ()
() ()
()
()()
()
()( )
.
2
1
,
2
1
2
1
,
2
1
2
1
,
2
1
2
1
2
,
2
1
,
2
1
,
2
1
,
2
1
,
2
1
,
11
11
110101
1101
1101
11110
11110
2
1
2
110
2
10
10
1
1
−−
−−
−−
−−
−−
−−−
−−−
−−
+−=
+−=
+++−=
++
−=
++−=
−++−=
−++−=
−+−=
+=
+=
−
−
∫
iiii
iiii
iiii
iiii
iiii
iiiiii
iiiiii
iiii
x
x
x
x
i
yyxx
yyxx
xaaxaaxx
xxaaxx
xxaaxx
xxxxaxxa
xxxxaxxa
xxaxxa
xaxa
dxxaaI
i
i
i
i
This result yields the general trapezoidal rule, which works for unequally-sized increments,
()( )
∑∑
=
−−
=
+−==
n
i
iiii
n
i
iyyxxII
1
11
12
1.
In the case were the increments,
()
1−
−ii xx are of equal size, x∆, the trapezoidal rule becomes,
pf3

Partial preview of the text

Download The Trapezoidal Rule - Lecture Notes | AER E 161 and more Study notes Aerospace Engineering in PDF only on Docsity!

D. Haugli, Lecturer Aer E 161 Aerospace Engineering

The Trapezoidal Rule

The trapezoidal rule uses a first-order polynomial (i.e., the equation of a line) to estimate the

function f ( ) x in the incremental integral,

−

i

i

x

x

Ii f xdx

1

Thus, f ( ) x ≅ y 1 = a 0 + a 1 x. To avoid confusion, the subscript 1 on y 1 (indicating that the

polynomial is first-order) will be dropped in the derivation that follows.

With a bit of algebraic trickery, the solution to the incremental integral is,

1 1

1 1

1 0 1 0 1 1

1 0 1 1

1 0 1 1

0 1 1 1 1

0 1 1 1 1

2 1

2 0 1 1

2 0 1

0 1

1

1

− −

− −

− −

− −

− −

− − −

− − −

− −

−

−

i i i i

i i i i

i i i i

i i i i

i i i i

i i i i i i

i i i i i i

i i i i

x

x

x

x

i

x x y y

x x y y

x x a ax a ax

x x a a x x

x x a a x x

a x x a x x x x

a x x a x x x x

a x x a x x

ax ax

I a axdx

i

i

i

i

This result yields the general trapezoidal rule, which works for unequally-sized increments,

∑ ∑^ (^ )(^ )

=

− −

n

i

i i i i

n

i

I Ii x x y y 1

1 1 1 2

In the case were the increments, ( xi − xi − 1 )are of equal size, ∆ x , the trapezoidal rule becomes,

D. Haugli, Lecturer Aer E 161 Aerospace Engineering

[( ) ( ) ( ) ( ) ( )]

∑

∑

∑

−

=

− − −

=

=

=

− −

n

n

i

i

n n n n

n

i

i i

n

i

i i i i

y y y

x

y y y y y y y y y y

x

y y

x

I x x y y

1

1

0

0 1 1 2 2 3 2 1 1

1

1

1

1 1

l

which is the form commonly seen in calculus books.

To use either equation (general or equal-increment) with experimental data, ( X i , Y i ), replace xi

with X (^) i and y (^) i with Yi.

Example FORTRAN Code.

! This program computes the area under a curve via the general trapezoidal

! rule for arbitrary grid spacing.

PROGRAM trapezoidal_rule

IMPLICIT NONE

INTEGER :: i, n, p

REAL (kind=8) :: area

REAL (kind=8), ALLOCATABLE :: x(:), y(:)

! Open the input file and determine the number of data pairs.

OPEN (unit=12, file="input.dat")

READ (12,*) p! p is the number of data pairs (lines) in the file.

! The number if increments, which the trapezoidal rule is based on,

! is one less than the number of data pairs.

n = p - 1

ALLOCATE (x(0:n), y(0:n))

! Read the input data and compute the area (integral).

READ (12,*) x(0), y(0)

area = 0.d

DO i = 1, n

READ (12,) x(i), y(i) area = area + (x(i) - x(i-1))(y(i) + y(i-1))

END DO

area = area/2.d

! Write out the result.

WRITE (,) "The area under the curve is approximately ", area

STOP

END PROGRAM trapezoidal_rule