SME
Calculus II
Numerical integration (trapezoid and Simpson's rules)
Use this for “Estimate the integral of 1/x from 1 to 2 with n = 4 by the trapezoid rule and by Simpson’s rule, and compare with ln 2.”
Chart
Trapezoid rule, n = 4, h = 0.25 from x = 1 to 2: T = 0.697
This is an example. Type your own values to start a new problem.
∫
1
x
dx
=
I
T
=
Tₙ
S
=
Sₙ
h
Panel width
worked out (not typed)
m
Panel pairs for Simpson, n ÷ 2
worked out (not typed)
ET
Error of the trapezoid estimate, Tₙ − I
worked out (not typed)
ES
Error of Simpson’s estimate, Sₙ − I
worked out (not typed)
Formulas
h
=
b
−
a
n
0.25
=
2 − 1
4
m
=
n
2
2
=
4
2
Tₙ
=
h
×
(
n
Σ
i
=0
(
1
a
+
i
×
h
)
−
1 ÷
a
+ 1 ÷
b
2
)
0.6970238
=
0.25
×
(
4
Σ
i
=0
(
1
1 +
i
× 0.25
)
−
1 ÷ 1 + 1 ÷ 2
2
)
Sₙ
=
2
3
×
(Tₙ
+
h
×
m
Σ
k
=1
(
1
a
+ 2
k
×
h
−
h
)
)
0.6932540
=
2
3
×
(0.6970238
+
0.25
×
2
Σ
k
=1
(
1
1 + 2
k
× 0.25 − 0.25
)
)
I
=
ln(
b
a
)
0.6931472
=
ln(
2
1
)
ET
=
Tₙ
−
I
0.003877 = 0.6970238 − 0.6931472
ES
=
Sₙ
−
I
1.0679 ×
10
-4
=
0.6932540
−
0.6931472
Assumptions
•
f(x) = 1/x on [a, b] with 0 < a < b, cut into n panels of width h = (b − a) ÷ n at x₀ = a, x₁, …, xₙ = b.
•
The trapezoid rule joins neighbouring heights fᵢ = 1/xᵢ with straight lines; Simpson’s rule fits a parabola over each pair of panels, so n must be even.
•
1/x bends up (f″ > 0), so each trapezoid’s top lies above the curve and T overestimates. Simpson’s error shrinks far faster as n grows.
Step-by-step
WE KNOW
a = 1, b = 2, n = 4
FIND
panel width (h), panel pairs for Simpson, n ÷ 2 (m), trapezoid estimate (Tₙ), Simpson’s estimate (Sₙ), exact value ln(b ÷ a) (I), error of the trapezoid estimate, Tₙ − I (ET), error of Simpson’s estimate, Sₙ − I (ES)
Step 1 · Find panel width (h)
Use h = (b − a) ÷ n
Share
the
length
of
[
a
,
b
]
equally
among
the
n
panels.
h
=
2 − 1
4
h
=
1
4
h
=
0.25
Step 2 · Find panel pairs for Simpson, n ÷ 2 (m)
Use m = n ÷ 2
Simpson’s rule takes the panels two at a time.
m
=
4
2
m
=
2
Step 3 · Find trapezoid estimate (Tₙ)
Use Tₙ = h × (Σ from i = 0 to n of (1 ÷ (a + i × h)) − (1 ÷ a + 1 ÷ b) ÷ 2)
Each
panel
is
a
trapezoid
of
width
h
whose
height
is
the
average
of
its
two
ends.
Adding
them
counts
every
inside
height
once
and
each
end
height
half.
Tₙ
=
0.25
×
(
4
Σ
i
=0
(
1
1 +
i
× 0.25
)
−
1 ÷ 1 + 1 ÷ 2
2
)
x = 1, 1.25, 1.5, 1.75, 2
f
(x)
=
1
x
=
1,
0.8,
0.666667,
0.571429,
0.5
Tₙ
=
0.25
2
×
(1
+
2
×
0.8
+
2
×
0.666667
+
2
×
0.571429
+
0.5)
=
0.697024
Tₙ = 0.6970238
Step 4 · Find Simpson’s estimate (Sₙ)
Use Sₙ = 2 ÷ 3 × (Tₙ + h × Σ from k = 1 to m of (1 ÷ (a + 2k × h − h)))
Simpson
weights
the
heights
1,
4,
2,
4,
…,
4,
1
and
multiplies
by
h
3
.
That
equals
two
thirds
of
T
plus
two
thirds
of
h
times
the
odd-numbered
heights.
Sₙ
=
2
3
×
(0.6970238
+
0.25
×
2
Σ
k
=1
(
1
1 + 2
k
× 0.25 − 0.25
)
)
Sₙ
=
0.25
3
×
(1
+
4
×
0.8
+
2
×
0.666667
+
4
×
0.571429
+
0.5)
=
0.693254
Sₙ = 0.6932540
Step 5 · Find exact value ln(b ÷ a): I
Use I = ln(b ÷ a)
An
antiderivative
of
1
x
is
ln
x,
so
the
exact
integral
is
ln
b
−
ln
a
.
I
=
ln(
2
1
)
I
=
0.6931472
Step 6 · Find error of the trapezoid estimate, Tₙ − I (ET)
Use ET = Tₙ − I
Take
the
exact
value
from
the
estimate.
It
comes
out
above
0,
since
1
x
bends
up
and
each
trapezoid
sits
over
the
curve.
ET = 0.6970238 − 0.6931472
ET = 0.003877
Step 7 · Find error of Simpson’s estimate, Sₙ − I (ES)
Use ES = Sₙ − I
Take
the
exact
value
from
Simpson’s
estimate.
Its
error
falls
about
16
times
each
time
n
doubles,
the
trapezoid’s
only
about
4
times.
ES = 0.6932540 − 0.6931472
ES
=
1.0679 ×
10
-4
Check
Put the numbers back in. Both sides should match.
0.25
=
2 − 1
4
✓
2
=
4
2
✓
0.6970238
=
0.25
×
(
4
Σ
i
=0
(
1
1 +
i
× 0.25
)
−
1 ÷ 1 + 1 ÷ 2
2
)
✓
0.6932540
=
2
3
×
(0.6970238
+
0.25
×
2
Σ
k
=1
(
1
1 + 2
k
× 0.25 − 0.25
)
)
✓
0.6931472
=
ln(
2
1
)
✓
0.003877 = 0.6970238 − 0.6931472 ✓
1.0679 ×
10
-4
=
0.6932540
−
0.6931472
✓
Topic check
See what you know: 5 questions on this topic
New questions each time. Pass to mark it complete.