You are on page 1of 4

2.

4 Integrating with a Spreadsheet


We have not yet defined functions so this section is way ahead of us. If you
encounter something that bothers you here, stop, go on to the next chapter
and come back here later. If what you see below makes sense, then keep going.

Integration has a geometric meaning. Given a positive function ff, the Definite


Integral of ff between AA and BB means the area between the plot of of the
function f(x)f(x), and the x-axis, from a fixed starting value of x, Ax,A, to
another value BB with B > AB>A.

If the function is constant, that area just the product of (B-A)(B−A) (the length of
the interval) with the constant value of ff, because the figure whose are we are
computing is a rectangle, with sides at x = Ax=A and x = Bx=B, top at y = fy=f,
and bottom at y = 0y=0.

Otherwise, we can divide the interval from AA to BB into slivers of


length dd and calculate the area by the sum of the areas in each sliver. (We
count area below the x axis as negative when the function is negative and
when B &lt; AB<A positive becomes negative and vice versa.) We will
choose slivers all of length dd, and approximate the area in each sliver.

There is an interesting question here: what do you do to approximate the area in


a sliver?

A sliver has width dd, and we chose an approximate height, so this question


becomes what height should we assign to the area between say ss and s +
ds+d?

There are three very simple ways to do this. One way is to use f(s)f(s), and another
to use f(s+d)f(s+d) and another is to use their average.

These ways of estimating have names! They are, the left hand rule, the right
hand rule and the trapezoid rule. The contribution to area from each sliver will
be this estimate multiplied by dd.

Happily, the only difference between these in the answer you get for the area in
question comes from the contributions f(A)df(A)d and f(B)df(B)d. All other
intermediate points contribute the same amount no matter which of these "rules" is
used.

This happens because the end of one sliver is the beginning of the next, and the
contribution to the sum from point ss is f(s)df(s)d no matter which of these
methods is used. If you use the value of ff on the left side of intervals, then you
get f(s)df(s)d from the interval starting at xx; if you use the right side value
of ff you get the same thing coming from the interval ending at xx; and if you use
their average, you get half from either interval.

This means the only difference comes from the first and last intervals. With the
"left rule", you get f(A)df(A)d but not f(B)df(B)d vice versa for the "right rule",
and \frac{(f(A)+f(B))d}{2}2(f(A)+f(B))d from the average or "Trapezoid Rule". In
other words, in the trapezoid rule you get f(s)df(s)d for every interior sliver except
the end ones, and only \frac{f(A)d}{2}2f(A)d and \frac{f(B)d}{2}2f(B)d at the
endpoints AA and BB. The trapezoid rule turns out to be the best of the three.

So we will estimate the sum using f(s)df(s)d for values s between A and


B inclusive, and subtract \frac{(f(A)+f(B))d}{2}2(f(A)+f(B))d from the total, and
that will give us the answer supplied by the trapezoid rule. Later on we will see
that this is much better than either of the others, because its error is proportional
to d^2d2 while the others each differ from the actual area by a linear term \frac{|
f(A)-f(B)|d}{2}2∣f(A)−f(B)∣d as well.
Calculating the sum of the contents of consecutive boxes in a column is what you
did in column D with Fibonacci numbers. To get in column C the sum of what is in
column B from 5 on you enter =B5+C4 into C5 and copy it down that column.

This will compute the left hand rule estimate for areas in column C. By putting
=C5-(B$5+B5)/2 in D5, we convert the left hand rule to the trapezoid rule which
will be displayed at each intermediate point by what is in column D. The -B$5/2
takes away half of the contribution at x = Ax=A, and the other subtraction takes
away the contribution at the other end.

We start by putting the choice for d in B2; putting the starting value for xx, AA, in
B3.

We do this so we can easily change these when we want to.


Column A will contain the values of xx from A on.

Entry Bk will contain the values of your function for x = \text{Ak}x=Ak.

As an illustration we will estimate the integral of the function \sin xsinx.

You can set this up starting at the fifth row by putting =B3 in A5. Then set A6 to
=A5+B$2, and copy A6 down column A. That will be the value of your variable.

In B5 put =B$2*sin(A5) and copy this down column B.

In C5 put =B5+C4 and copy that down column C.

In D5 put =C5-(B$5+B5)/2 and copy down column D.

If you do this, you can change d just by inserting a different value for it in B2.
You can change the starting point by entering the new one in B3. You can
change the function you want to integrate by replacing sin(A5) by your new
f(A5) and copying =B$2*f(A5) down column B.

The estimate of the area starting at A5 and ending at at x=A5+kd using the Left
Hand Rule will appear in column C at row whose a value is B5+(k-1)d. (This box
will have the sum of kk terms of the form \sin(x)dsin(x)d.)

The entries in column D convert the left hand rule to the Trapezoid rule. Thus what
appears in the row with A value B4+kd will be the trapezoid rule estimate of the
area between the x-axis, the sine curve and the lines x=B4 and x=B4+kd.

This is an estimate to the area; we can do better and will, later on.

This is what the spreadsheet should look like with d = 0.01d=0.01 and A =


1A=1.
Show table 

Now select columns A and B from A5 to B105, and insert an xy scatter chart.
What do you see?

How can we do better?


If you add a column E which is like C except jumps by 22, that is in E5 put
=2*B5+E3 and copy down, and correct this to the trapezoid rule in column F by
putting in F5 =E5-(B$5+B5) and copying down, and finally putting =(4*D5-F5)/3
in column G you will get the Simpson’s rule estimate to the area in question in the
odd entries of column G. (like rows 55, 77, 99, etc.) The even entries will be
useless junk.

What the devil is this?

The odd entries in E and F repeat the previous calculation with dd replaced


by 2d2d. The error in the trapezoid rule behaves as d^{-2}d−2; the term in that
error that behaves as d^{-2}d−2 will cancel out if you take 44 times
the dd computation and subtract the 2d2d one. The result will be
roughly 33 times the actual result. Thus dividing 4D5-F5 by 3 gives a rule for the
area whose error actually goes as d^4d4. It is called Simpson's rule.

This will be discussed in detail in Chapter 14.

You might also like