WEBVTT
1
00:00:00.000 --> 00:00:08.000
numerical integration.
2
00:00:08.000 --> 00:00:12.500
The problem we want to address here is how to approximate a definite integral using
3
00:00:12.500 --> 00:00:17.500
only n plus 1 function values at equally space points in the interval.
4
00:00:17.500 --> 00:00:22.500
Of course, we can think in terms of approximating the area under the graph of a non-negative
5
00:00:22.500 --> 00:00:28.500
function between x equals a and x equals b, although what we will do will apply just as
6
00:00:28.500 --> 00:00:31.500
a non-negative function.
7
00:00:31.500 --> 00:00:36.500
Let's begin by describing the points in the interval where we will evaluate the function.
8
00:00:36.500 --> 00:00:45.000
Let x i equal a plus i times delta x for i equal to 0, 1, 2, and so on up to n, where
9
00:00:45.000 --> 00:00:52.500
delta x is b minus a divided by n. We can think of these numbers as n points of n sub-intervals
10
00:00:52.500 --> 00:01:00.500
each having width delta x. Note that x 0 is equal to a and x n is equal to b, and each x i
11
00:01:00.500 --> 00:01:07.500
corresponds to a point on the graph of f with y coordinate f of x i.
12
00:01:07.500 --> 00:01:12.500
We have already seen three ways of using a finite number of function values to approximate
13
00:01:12.500 --> 00:01:18.500
an integral. When we first defined the definite integral, we talked about rectangle approximations.
14
00:01:18.500 --> 00:01:25.500
In particular, a left endpoint approximation, where we sum from i equals 0 to n minus 1
15
00:01:25.500 --> 00:01:34.500
f of x i times delta x, a right endpoint approximation, where we sum from i equals 1 to n f of x i times
16
00:01:34.500 --> 00:01:41.500
delta x, and a midpoint approximation, where we sum from i equals 0 to n minus 1, f of the midpoint
17
00:01:41.500 --> 00:01:46.500
between x i and x i plus 1 times delta x.
18
00:01:46.500 --> 00:01:51.500
The left and right endpoint approximations are very crude in the sense that typically n must
19
00:01:51.500 --> 00:01:57.500
be very large in order to get a reasonably accurate approximation. Turns out that the midpoint
20
00:01:57.500 --> 00:02:01.500
approximation does a much better job, but it has the disadvantage of not fitting into our
21
00:02:01.500 --> 00:02:10.500
scheme of using a given set of function values at x 0 through x n.
22
00:02:10.500 --> 00:02:17.500
The trapezoid rule. Consider a typical sub-interval from x i to x i plus 1.
23
00:02:17.500 --> 00:02:22.500
We want to approximate the area under the graph of that interval using only function values
24
00:02:22.500 --> 00:02:28.500
f of x i and f of x i plus 1. The sensible thing to do is to use the area under the segment
25
00:02:28.500 --> 00:02:34.500
joining the points on the curve corresponding to x i and x i plus 1. That is the area of the
26
00:02:34.500 --> 00:02:39.500
trapezoid shaded in blue here. The area of that trapezoid is easy to write down.
27
00:02:39.500 --> 00:02:46.500
A simple way to think of it is that it is the ab-fridge height times width. So we have
28
00:02:46.500 --> 00:02:54.500
f of x i plus f of x i plus 1 divided by 2 times the width delta x. This is the two-point
29
00:02:54.500 --> 00:03:00.500
trapezoid rule, which amounts to integrating the linear interpolator between x i and x i plus
30
00:03:00.500 --> 00:03:07.500
1. Now to approximate the interval from a to b, we just sum up these trapezoid areas as i goes
31
00:03:07.500 --> 00:03:14.500
from 0 to n minus 1. Let's call the result t sub n for trapezoid rule within sub-intervales
32
00:03:14.500 --> 00:03:21.500
and that will provide an approximation to the integral from a to b of f of x dx.
33
00:03:21.500 --> 00:03:27.500
Now let's see if there is a simpler form for the sum. After we factor out delta x over 2,
34
00:03:27.500 --> 00:03:35.500
the i equals 0 term is f of x 0 plus f of x 1 and recall that x 0 is a, the i equals 1 term
35
00:03:35.500 --> 00:03:44.500
is f of x 1 plus f of x 2, the i equals 2 term is f of x 2 plus f of x 3 and so on until
36
00:03:44.500 --> 00:03:51.500
the n plus first term is f of x n minus 1 plus f of x n and x n is b. So notice that every
37
00:03:51.500 --> 00:03:58.500
function value except f of a and f of b appears twice in the sum. So we can rewrite this
38
00:03:58.500 --> 00:04:12.500
as delta x over 2 times f of a plus 2 times f of x 1 plus 2 times f of x 2 and so on up to 2 times f of x n minus 1 plus 1 times f of b.
39
00:04:12.500 --> 00:04:25.500
Using summation notation we can write this as delta x over 2 times f of a plus 2 times the sum from i equals 1 to n minus 1 of f of x i plus f of b.
40
00:04:25.500 --> 00:04:35.500
Now let's look at an example. Let's compute t5 for the integral from 0 to 1 of the square root of 1 plus x cube dx.
41
00:04:35.500 --> 00:04:45.500
Since n equals 5 we first compute delta x equal to 1 minus 0 divided by 5 or 1 fifth which is 0.2.
42
00:04:45.500 --> 00:05:12.500
So our function values will be computed at 0.2.4.6.81. So t5 equals 1 fifth divided by 2 times the function value at 0 plus 2 times the function value at each of the numbers 0.2.4.6 and 0.8 and finally plus 1 times the value at 1.
43
00:05:12.500 --> 00:05:21.500
Now with the help of the calculator we'll compute those function values and the value of t5 ends up being 1.115.
44
00:05:21.500 --> 00:05:36.500
Now it would be very nice to have some idea how accurate this approximation of the integral is fortunately it is possible to estimate the error and this is what we'll discuss next.
45
00:05:36.500 --> 00:05:44.500
Here are estimate for the trapezoid rule. A theorem whose proof will not give because it requires more calculus than we've learned up to now.
46
00:05:44.500 --> 00:06:05.500
Stay set if f is continuous on the closed interval a b and if f double prime of x exists for all x in the open interval a b then the integral from a to b of f of x dx is equal to the trapezoid rule approximation capital t sub n plus a remainder term of the form minus 1 over 12 in squared.
47
00:06:05.500 --> 00:06:34.500
Then f double prime of c for some number c between a and b. Therefore if the absolute value of f double prime of x is less than or equal to some number capital m for all x between a and b then the absolute value of the difference between the integral and the trapezoid rule approximation that is the absolute value of the error is less than or equal to 1 over 12 in squared times b minus b.
48
00:06:34.500 --> 00:06:41.500
So we can compute an estimate for the absolute value of the error provided that we can find such a number m.
49
00:06:41.500 --> 00:06:52.500
Now for example for the integral from 0 to 1 of the square root of 1 plus x cubed dx we just computed t5 equal to 1.115.
50
00:06:52.500 --> 00:07:10.500
Now let's estimate the error. We'll omit the details of the computation but the second derivative of the square root of 1 plus x cubed ends up being 3x times 4 plus x cubed divided by 4 times the 3 half's power of 1 plus x cubed.
51
00:07:10.500 --> 00:07:19.500
Now we're interested in the absolute value of this function and we'd like to estimate the maximum value of this over the integral 0 to 1.
52
00:07:19.500 --> 00:07:26.500
Now with the help of a graph and calculator we can easily plot the graph of that function on the integral 0 to 1.
53
00:07:26.500 --> 00:07:37.500
We don't necessarily need the exact maximum here, a fairly close upper estimate will do and the graph makes it clear that the maximum value on that interval is a little less than 1.5.
54
00:07:37.500 --> 00:07:45.500
So a perfectly good value of m here is 1.5. So now we can compute our estimate for the error.
55
00:07:45.500 --> 00:07:59.500
The absolute value of the error is now going to be less than or equal to 1 over 12 times n squared in is 5 times b minus a cubed that's 1 minus 0 cubed times our m 1.5.
56
00:07:59.500 --> 00:08:16.500
This number is exactly 0.005. So t5 which is 1.115 is guaranteed to be within 0.005 of the exact value of the integral.
57
00:08:16.500 --> 00:08:31.500
Another example. Find n so that t sub n is guaranteed to approximate the integral from 0 to 1 of the square root of 1 plus x cubed dx to within 0.005 or 5 times 10 to the minus 4.
58
00:08:31.500 --> 00:08:45.500
Recall that in the last example we determined that t5 was accurate to within 0.005. So we want to find out how much bigger n needs to be than 5 in order for the error estimate to be 1 tenth as big.
59
00:08:45.500 --> 00:08:55.500
Also from the last example we know that the absolute value of the second derivative is less than or equal to 1.5 for all x between 0 and m 1.
60
00:08:55.500 --> 00:09:10.500
So the trapezoid rule error estimate tells us that the absolute value of the error is going to be less than or equal to 1 over 12 n squared times the width of the interval cubed times 1.5 which is equal to 1 over 8 n squared.
61
00:09:10.500 --> 00:09:21.500
Therefore the absolute value of the error will be less than or equal to 5 times 10 to the minus 4 if 1 over 8 n squared is less than or equal to 5 times 10 to the minus 4.
62
00:09:21.500 --> 00:09:36.500
So now we just need to solve that inequality for n. Let's multiply both sides by n squared and also by 2000 and we have 2000 divided by 8 less than or equal to n squared which is equivalent to n squared greater than or equal to 250.
63
00:09:36.500 --> 00:09:43.500
Now take the square root of both sides and we have n greater than or equal to the square root of 250 which is about 15.8.
64
00:09:43.500 --> 00:09:50.500
So now we want to take n to be the next integer greater than or equal to 15.8 and that's 16.
65
00:09:50.500 --> 00:09:59.500
So by increasing n from 5 to 16 our error estimate decreases from 5 times 10 to the minus 3 to 5 times 10 to the minus 4.
66
00:09:59.500 --> 00:10:06.500
We can think of this as gaining one more decimal place of accuracy in the approximation of the integral by a little more than tripling n.
67
00:10:06.500 --> 00:10:11.500
What's happening here is all about the factor 1 over n squared in the error estimate.
68
00:10:11.500 --> 00:10:25.500
When we increase n by a factor of the square root of 10 a little more than tripling it the effect is to divide the error estimate by 10.
69
00:10:25.500 --> 00:10:32.500
Simpson's rule. Let's see what happens if we take sub-intervals 2 at a time or points 3 at a time.
70
00:10:32.500 --> 00:10:39.500
Just as two points determine a line three points determine a parabola assuming the points aren't collinear.
71
00:10:39.500 --> 00:10:44.500
Simpson's rule approximates the area under the curve with the area under the parabola.
72
00:10:44.500 --> 00:10:54.500
That is Simpson's rule integrates the quadratic interpolator whose equation we can write as y equals a times x minus xi squared
73
00:10:54.500 --> 00:11:03.500
plus b times x minus xi plus c. Where it turns out that a b and c are as follows.
74
00:11:03.500 --> 00:11:13.500
a is equal to f of x i minus 1 minus 2 times f of x i plus f of x i plus 1 all divided by 2 times the square of delta x.
75
00:11:13.500 --> 00:11:26.500
b turns out to be f of x i plus 1 minus f of x i minus 1 divided by 2 times delta x and c is just a value of the function at x i.
76
00:11:26.500 --> 00:11:40.500
These are the coefficients to guarantee that the value of y is f of x i minus 1 when x equals x i minus 1, f of x i when x equals x i and f of x i plus 1 when x equals x i plus 1.
77
00:11:40.500 --> 00:11:48.500
As is not difficult to check. Now let's integrate this from x i minus 1 to x i plus 1.
78
00:11:48.500 --> 00:12:00.500
To simplify we'll make the substitution u equals x minus x i for which du equals dx and the limits of integration become minus delta x to delta x.
79
00:12:00.500 --> 00:12:08.500
Since x i plus 1 minus x i equals delta x and x i minus 1 minus x i equals minus delta x.
80
00:12:08.500 --> 00:12:22.500
The a u squared term now gives us 1 third of a u cubed evaluated from minus delta x to delta x which equals 1 third times a times delta x cubed minus minus delta x cubed.
81
00:12:22.500 --> 00:12:36.500
The b u term gives us 1 half b times u squared evaluated from minus delta x to delta x which gives us 1 half of b times delta x squared minus delta x squared.
82
00:12:36.500 --> 00:12:46.500
The c term gives us c times u evaluated from minus delta x to delta x which is just c times delta x minus minus delta x.
83
00:12:46.500 --> 00:12:59.500
Now notice that the b term here is equal to 0. The a term is equal to 2 thirds a times delta x cubed and the c term is equal to 2 times c times delta x.
84
00:12:59.500 --> 00:13:20.500
Now let's put into this expression our values for a and c. When a is multiplied by 2 thirds and delta x cubed, 2's cancel and delta x squared cancels and we're left with delta x over 3 times the numerator f of x i minus 1 minus 2 f of x i plus f of x i plus 1.
85
00:13:20.500 --> 00:13:39.500
And c is simply f of x i so we have 2 times f of x i times delta x. Now notice that we can factor delta x from everything. Also notice that we have a minus 2 thirds f of x i plus 2 f of x i which ends up being 4 thirds of f of x i.
86
00:13:39.500 --> 00:13:54.500
So we can express this entire quantity as delta x over 3 times f of x i minus 1 plus 4 times f of x i plus f of x i plus 1.
87
00:13:54.500 --> 00:13:58.500
So we have what we can call the 3 point Simpson rule.
88
00:13:58.500 --> 00:14:08.500
Now we'd like to turn this into so-called composite Simpson rule by summing up the 3 point Simpson rule over pairs of subintervals across our interval.
89
00:14:08.500 --> 00:14:24.500
When i is equal to 1, that formula corresponds to the first two subintervals in our interval and the formula gives us delta x over 3 times f of x 0 or f of a plus 4 times f of x 1 plus f of x 2.
90
00:14:24.500 --> 00:14:38.500
Then we move over to the next pair of subintervals and for that we need to use i equals 3 in our formula that gives us delta x over 3 times f of x 2 plus 4 times f of x 3 plus f of x 4.
91
00:14:38.500 --> 00:14:48.500
Then we shift over to the next pair of subintervals and we pick up an f of x 4 plus 4 times f of x 5 plus f of x 6 and so on.
92
00:14:48.500 --> 00:14:58.500
Notice that with the exception of f of a and f of b, all the terms here which look like f of x i where i is even appear twice in the sum.
93
00:14:58.500 --> 00:15:16.500
So we can rewrite this as delta x over 3 times f of a plus 4 times f of x 1 plus 2 times f of x 2 plus 4 times f of x 3 plus 2 times f of x 4 and so forth until we get to 4 times f of x in minus 1 plus f of b.
94
00:15:16.500 --> 00:15:26.500
So what we have here is a coefficient pattern that looks like 1, 4, 2, 4, 2, 4 repeating until we get to 2, 4, 1 at the other end.
95
00:15:26.500 --> 00:15:32.500
Now let's name this approximation s sub n and express it using summation notation as follows.
96
00:15:32.500 --> 00:15:49.500
Delta x over 3 times f of a plus the sum from i equals 1 to n minus 1 of c sub i times f of x i and then plus f of b where the coefficient c sub i is 4 if i is odd and 2 if i is even.
97
00:15:49.500 --> 00:15:59.500
Now a simple formula for c sub i would be a handy thing to have. It turns out that we can write this as c sub i equals 3 minus minus 1 to the i's power.
98
00:15:59.500 --> 00:16:08.500
Notice if i is odd this is 3 minus minus 1 or 4 and when i is even this 3 minus 1 equals 2.
99
00:16:08.500 --> 00:16:18.500
Now another thing that needs to be emphasized here is that since the rule is constructed by taking consecutive pairs of sub intervals we must have an even number of sub intervals.
100
00:16:18.500 --> 00:16:30.500
In other words n must be even here in order for our coefficient pattern to work out correctly.
101
00:16:30.500 --> 00:16:38.500
Now let's look at an example. Let's compute s 4 for the integral from 1 to 3 of 1 over 1 plus the natural log of x dx.
102
00:16:38.500 --> 00:16:53.500
Since n is equal to 4 we will first compute delta x equal to 3 minus 1 divided by 4 or 1 half. So our function evaluations will take place at 1.5 to 2.5 and 3.
103
00:16:53.500 --> 00:17:10.500
Now s 4 will be 1 half that's delta x divided by 3 times f of the left end point 1 plus 4 times f of 1.5 plus 2 times f of 2 plus 4 times f of 2.5 plus 1 times f of 3.
104
00:17:10.500 --> 00:17:30.500
Now f of x is 1 over 1 plus natural log of x. So this turns into 1 6 times 1 over 1 plus the natural log of 1 plus 4 times 1 over 1 plus the natural log of 1.5 plus 2 times 1 over 1 plus the natural log of 2 and so forth.
105
00:17:30.500 --> 00:17:40.500
Now with the calculator we will compute each of those terms and then finish up the computation we end up with 1.26519.
106
00:17:40.500 --> 00:17:53.500
Now just as with the trapezoidal rule it's very desirable here to have some idea of how accurate this approximation is and that's what we will look into next.
107
00:17:53.500 --> 00:18:00.500
Air estimate for Simpson's rule. This is going to be similar in spirit to what we saw for the trapezoidal rule.
108
00:18:00.500 --> 00:18:22.500
If f is continuous on the closed end of a and if the fourth derivative of f of x exists for all x in the open end of a and the integral from a to b of f of x dx is equal to capital S sub n plus a remainder term of the form minus the 5th power of b minus a divided by 180 times end of the 4th.
109
00:18:22.500 --> 00:18:29.500
Times the fourth derivative of f evaluated at c where c is some number between a and b.
110
00:18:29.500 --> 00:18:49.500
Therefore if the absolute value of the fourth derivative is less than or equal to some number in m for all x between a and b then the absolute value of the difference between the integral and the Simpson's rule approximation is less than or equal to b minus a to the 5th over 180 times end of the 4th times the number in m.
111
00:18:49.500 --> 00:19:01.500
Probably the most important thing to notice here is that the estimate on the right hand side has entered the fourth in the denominator where the trapezoidal rule error estimate had an n squared in the denominator.
112
00:19:01.500 --> 00:19:14.500
Now for example for the integral from 1 to 3 of 1 over 1 plus log x dx we computed S 4 equal to 1.26519. Now let's compute a bound on the error.
113
00:19:14.500 --> 00:19:26.500
Now we'll skip the details again but after a considerable amount of work we find that this is the fourth derivative of f and it's the absolute value of that that we're actually interested in.
114
00:19:26.500 --> 00:19:39.500
Now again rather than trying to find the exact maximum value using calculus we'll just graph the function with a graphing utility which reveals that this function is actually always decreasing on the interval from 1 to 3.
115
00:19:39.500 --> 00:19:46.500
That tells us that the maximum value is the value at the left end point which actually turns out to be exactly 88.
116
00:19:46.500 --> 00:20:01.500
So now we're ready to compute the estimate. The absolute value of our error is less than or equal to the width of the interval which is 2 raised to the 5th power divided by 180 times the 4th power of n which is 4 times 88.
117
00:20:01.500 --> 00:20:14.500
This turns out to be 0.0611 rounded to 4 decimal places. So we now know that our computed S 4 is within 0.0611 of the exact value of the integral.
118
00:20:14.500 --> 00:20:29.500
We should point out here that this error estimate is likely to be quite conservative. That's because the absolute value of the value of the 4th derivative that appears in the exact formula for the error is likely to be considerably less than our upper bound of 88.
119
00:20:29.500 --> 00:20:46.500
Another example. Let's find the end so that S sub n is guaranteed to approximate the integral from 1 to 3 of 1 over 1 plus log x dx to within 5 times 10 to the minus 5.
120
00:20:46.500 --> 00:21:07.500
From the previous example we know that 88 is an upper bound for the absolute value of the 4th derivative of the F on the interval from 1 to 3. So using the formula for the error estimate we have that the absolute value of the error will be less than or equal to the interval width 2 to the 5th power divided by 180 times end of the 4th times 88.
121
00:21:07.500 --> 00:21:24.500
This turns out to be equal to 15.644 divided by end of the 4th. Therefore the absolute value of the error will be less than or equal to 5 times 10 to the minus 5 if 15.644 divided by end of the 4th is less than or equal to 5 times 10 to the minus 5.
122
00:21:24.500 --> 00:21:38.500
So now we just solve this inequality for n. We multiply through by end of the 4th and divide by 5 times 10 to the minus 5 and we get n to the 4th greater than or equal to 312880 roughly.
123
00:21:38.500 --> 00:21:52.500
Now we take the 4th root of both sides and we obtain n greater than or equal to 23.65. And finally we choose n to be the first even number greater than or equal to 23.65 which is 24.
124
00:21:52.500 --> 00:22:04.500
So we now know that s of 24 will estimate our integral to within 5 times 10 to the minus 5.
125
00:22:04.500 --> 00:22:12.500
Calculators in the trapezoid rule. Let's think about how we might implement this trapezoidal rule formula on a common calculator.
126
00:22:12.500 --> 00:22:22.500
One way of approaching this on a ti-de-3 or 84 calculator is to press the y equals button and then enter the formula as the function y2.
127
00:22:22.500 --> 00:22:30.500
Here we're using x as n and we'll assume that values of a and b have been entered on the home screen. Notice that the formula refers to the function y1.
128
00:22:30.500 --> 00:22:34.500
So that's where we'll put the function that we're interested in integrating.
129
00:22:34.500 --> 00:22:50.500
So if we want to integrate x cubed we'll make that y1 of x and then on the home screen we'll store 0 as a and store 1 as b and then enter y2 of 10 which will give us the trapezoidal rule approximation using n equals 10 subintervals.
130
00:22:50.500 --> 00:23:03.500
Now let's look at how we entered our formula. The sum from i equals 1 to n minus 1 of f of xi is here where we use the sum and sequence functions in the calculator which are found in the list menu.
131
00:23:03.500 --> 00:23:18.500
What sequence does is just create a list of values and then sum adds them up. On a ti-89 or 92 calculator we can essentially just enter the formula and store it as a function of a, b and n.
132
00:23:18.500 --> 00:23:41.500
Here we're storing it as a function called trapeze and now to use this we'll need to define the function f. So let's say we store x cubed as f of x and then we type trapeze of 0, 1, 10 with those commands separated by colon and we get the trapezoidal rule approximation to the integral from 0 to 1 of x cubed dx using 10 subintervals.
133
00:23:41.500 --> 00:23:55.500
Now let's compare this formula to what we did with the 83 and 84 calculator. Here we use the summation function represented by the capital sigma which does the work of both the sum and sequence functions on the 83 and 84.
134
00:23:55.500 --> 00:24:18.500
Now in both cases there are ways of doing things a little bit better, particularly with the 83 and 84 where it might be nice to write a program that prompts the user to input values of a, b and n. What we've given here are just simple ways of getting things done that don't require us to think about programming.
135
00:24:18.500 --> 00:24:29.500
Calculators and Simpson's rule. So now let's think about this formula. There really isn't much difference from what we just did with the trapezoidal rule. We just need to make a couple of changes.
136
00:24:29.500 --> 00:24:51.500
On the 83, 84, the function specified using x for n as y, 2 of x looks like this. Let's highlight the main differences here. Notice the coefficient 3 minus negative 1 to the i power inside of the sequence function, multiplying y, 1 of a plus i delta x.
137
00:24:51.500 --> 00:25:06.500
Notice that the 0.5 times b minus a over x or 0.5 delta x has been replaced by 1 third of delta x in the form of b minus a divided by 3 times x. Notice the necessary parentheses around the free x there.
138
00:25:06.500 --> 00:25:23.500
So now if we let y, 1 of x equal x cubed, back on the home screen again, we'll store 0 as a, 1 as b, and then enter y, 2 of 4. And this will give us the Simpson's rule approximation using n equals 4 to the integral from 0 to 1 of x cubed.
139
00:25:23.500 --> 00:25:31.500
And notice that we get the exact value 1 to 4th here. It turns out that Simpson's rule does in fact integrate cubic polynomials exactly.
140
00:25:31.500 --> 00:25:54.500
On an 89 or 92, we'll call this function Simpson as I am PSN. And again, let's highlight those same differences in the formula. You have your coefficient of 3 minus negative 1 to the i, multiplying the function values inside of the summation, and b minus a divided by 3 times n, which is 1 third of delta x out front.
141
00:25:54.500 --> 00:26:10.500
And now if we store x cubed as f of x, and then type Simpson of 0, 1, 4 with those commands separated by colon, we'll again get the Simpson's rule approximation using 4 subintervals, which again equals 0.25.