# MAT128A: Project One: The (n + 1)-point Trapezoidal Rule

\$30.00

## Description

1. Project description
The integral
Z b
a
f(x) dx (1)
can be (crudely) estimated by approximating the area under the graph of f(x) by a trapezoid. In
other words, by approximating the integrand f via the affine function
g(x) = f(b) − f(a)
b − a
x +
f(a)b − f(b)a
b − a
whose graph passes through points (a, f(a)) and (b, f(b)). This procedure gives us the (crude)
approximation
Z b
a
f(x) dx ≈
Z b
a
g(x) dx = pf(a) + f(b)q
b − a
2
.
We now suppose that n > 1 is an integer, and let {x0, x1, x2, . . . , xn} be the sequence of (n + 1)
points defined by
xj = a +
b − a
n
· j.
If we decompose the integral (1) as
Z b
a
f(x) dx =
nX−1
j=0
Z xj+1
xj
f(x) dx (2)
and use the preceding approximation to estimate each of the integrals in (2), then we obtain the
estimate
Z b
a
f(x) dx =
nX−1
j=0
Z xj+1
xj
f(x) dx

nX−1
j=0
pf(xj ) + f(xj+1)q
b − a
2n
= pf(x0) + 2f(x1) + 2f(x2) + · · · + 2f(xn−1) + f(xn)q ·
b − a
2n
.
(3)
We call (3) the (n+1)-point trapezoidal quadrature rule on the interval [a, b]. The points x0, x1, . . . , xn
are called the nodes of the (n+ 1)-point trapezoidal rule on [a, b], and the quantities w0, w1, . . . , wn
defined by
wj =
b − a
2n
λj ,
1
where
λj =
(
1 if j = 0, n
2 otherwise,
are called the weights of the (n + 1)-point trapezoidal rule. Note that using this notation, (3) can
be rewritten as
Z b
a
f(x) dx ≈
Xn
j=0
f(xj )wj . (4)
Project one consists of writing a function called “traprule” which calculates the (n + 1)-point
trapezoidal rule. More specifically, your routine will take as input an integer n > 0 and double