Composite Trapezoidal Rule Motivation and Derivation
|
In this segment we'll talk about
the motivation behind the composite trapezoidal rule, as well as it’s
derivation. So, if we look at the single segment trapezoidal rule, we have
this as our area under the curve which we calculate. So, if we want to find
the integral of the function going from a to b, then we say it is simply this
quantity. Now, what can happen is that a
single application of the trapezoidal rule may not give a good estimate of
the integral. So, a good example of that is as follows. So, we have a
function here and let's suppose we call this 5x*e to the power -2x. Now, let's
suppose we are integrating from 0.1 to 1.3, then you're going to find out
that the trapezoid rule is going to give you this much area under the curve. And
what you're finding out here is going to be a huge error which is going to be
left over because one chose only one segment or one application, single
application, of the trapezoidal rule. So, if you look at this particular
integral 0.1 to 1.2 5x*e to the power -2x dx, this turns out to be
approximately equal to 0.53530 if you are using the single segment
trapezoidal rule or the single application trapezoidal rule. So, but the
exact value which you can get from integral calculus is 0.89387 and this is a
true error of approximately 40%. So, you can see there's a huge difference
between the two. Let's go and see that how we can maybe make it better. So, the way we can make it
better, we can say okay hey this is 5x e to the power -2x as a function of x.
We want to integrate from 0.1 to 1.3. So, what we can do is rather than just
using one trapezoid, we can break it up into two equal segments. So, this’ll
be 0.1 to 1.3, that is a distance of 1.2. That gives us 0.6 is the halfway
distance from here to here, so that gives us 0.7. So, what I can do now is to
draw this line and this line, so now I have this trapezoid, and I have this
trapezoid. So, I have two trapezoids now, and it so happens that the area of
this trapezoid (which you can calculate by applying the single application
trapezoidal rule) turns out to be this quantity. The area of this trapezoid
is 0.4377, and if you add the two, you're going to get about 0.78552. That’s
what you’re going to get as the value of the integral, now, which is quite
close to the exact value of 0.8937. So, in this case the absolute relative
true error is approximately about 12%. So, you can see that if I draw more
and more trapezoids like this, I will get a better and better approximation
of my integral. But this is not how we apply the composite trapezoidal rule
by drawing them, because we want to be able to program a composite
trapezoidal rule. So, the best thing to do is to derive a formula so that can
be programmed. And that's what we want to be doing now for the rest of this
segment. So, this is what we have what
we're going to do is we're going to have an integral which we want to
calculate from a to b so we want to find the area of
the curve from a to b and what we're going to do is we're going to break it
up into segments, equal segments. So, what's going to happen is that maybe
you'll have one segment like this, another segment like this, and then I’m
going to have several segments in between, and the last segment here between
the two. So, this is what's going to happen: so, if my width is b-a and if I
break it down into n segments then the width of this segment here will be b
minus a divided by n which will be denoted by h. So, this segment width is
same as this segment width, not drawn to scale here, and then we'll have this
segment width. They're all the same, and what we're going to do is we're
breaking the interval from a to b into n equal
segments. And what we're going to do, is we're going to apply the trapezoidal
rule on each of these segments, and that's what's called the composite
trapezoidal rule. So, what we're basically doing, is that we're taking this
integral which is going from a to b, and we are breaking it down into an
integral which goes from a to a plus h because this would be a h this will be
a plus 2h if you look at this last point it'll be a plus n minus 1h because
this one this b is nothing but a plus n times h, right, from here. And the
one segment back, the point will be on the x axis will be a plus n minus 1
times h. So, if we break this integral, we'll get this and then the next
integral is going from a plus h to a plus 2h, which is right here, and that
will be this. Then there are many, many integrals here and then I will get,
maybe, the second last integral will be like this. And the last integral I
will have is this one, so this is the last integral
right here shown here. So, I’ve basically broken up the
integral from a to b to n integrals and keep in mind that this is exactly
equal to, because all we have done is applied calculus. If you break the
integral interval, or the limits of integration, it's not going to change the
value of the integral. But what we're going to do now is that we're going to
apply the trapezoidal rule over this integral, the trapezoidal rule on this
integral, the trapezoidal rule in this integral, the single application
trapezoidal on this integral, and we're going to add them up. So, the first one is going to
give me as follows: upper limit minus lower limit times the value of the
function at the lower limit, upper limit function value, divided by 2. That's
the first one. The second one will be, hey, what is the upper limit? Which is
a plus 2h, the lower limit a plus h, and then the average of the value of the
functions at the lower limit, which is this, and the upper limit divided by
2. Then when we go to the last, second to last interval or integral we'll get
a plus n minus 1 h, that's the upper limit. The lower limit is this, and
it'll be the value of the function at the lower limit plus the value of the
function at the upper limit. And then the last integral will be the upper
limit minus the lower limit, and multiply with the average value of the
function at the lower limit and the upper limit, that's what you're going to
get. And what you're going to find out now is that what you're seeing here is
that this 2 is common in all these expressions, right? So, that can be taken
out as a common factor, but you also got to recognize that, hey, there's a
common factor here. Because when I simplify it, that's h. When I simplify
this, that's h. When I simplify this, that is h. When I simplify that is h
because, the segment, is the width of the segment. That's what you're going
to get on the outside here. So, it means that h divided by 2 is the common
factor, so let's go and take the h divided by 2 as a common factor and maybe
we can simplify the expression a little bit. So, what you're finding out is
that h divided by 2 is common amongst all the elements, and let's go and see
what is left behind. So, we'll have the value of the function at a, and the
value of the function a plus h from the first integral. From the second
integral, we'll have the value of the function a plus h and the function at a
plus 2h. Then of course, we'll have other terms in the summation, and the
second last integral will give us something like this. And the last integral
will give us the two function values at these points. So, what you're going
to see now is that these are the function values which you have to calculate at,
but let's see whether we can make it a little bit more compact. What you're
going to find out that this value of the function a plus h is not only in the
first integral, but also in the second one. The value of the function at this
point is not only there, but also in the previous one which is not shown. The
value of the function at this point is not only there but also in this
integral. The only one which is not in two integrals is the first one: f of a
and f of b. So, let's go and write it down with h by 2 times f of a plus 2
times the value of the function at a plus h, plus 2 times the value of the
function a plus 2h and plus 2 times the value of the function at n minus 2h,
plus 2 times the value of the function at n minus 1 h, plus the value of the
function at b. So that's the expression for the composite trapezoidal rule,
but what we can do is we can take all of these terms here and write them in a
summation form, and that way we will have a more compact formula. That's the
only difference. So, if you look at the compact
formula will be h divided by 2, times the value of the function at a. And if
we put those all those terms in the sum, we'll have f of a plus i h. And you can see the first term has a plus h in it,
so i will go from 1, and if we were the last term
in that, in those expressions which have 2 in front of them it's n minus 1,
so plus f of b. And that is your expression for the integral. We can also,
what we can do is we can substitute b minus a divided by n back in there for
h. And so, the integral of a to b, f of x dx and the composite trapezoidal
rule is approximately equal to b minus a divided by 2n times the value of the
function at a, plus this summation, plus the value of the function b. So,
what you are finding out here, is that this is the composite trapezoidal rule
formula, and all goes back to again the average values. Look at this. This is,
this part right here is the average value of the function between a and b-some
average, not the exact but some average value of the function because you can
see that this function is calculated at one point. This function, this n
minus 1 is calculated n minus 1 points, right? It's
calculated n minus 1 points but it's counted twice. And
this is calculated at one point and you can very
well see the number of function evaluations you have is 1 plus 2 n minus 1
plus 1 which is 2n, and then what you're doing is dividing by 2n here and
that gives you the average value of the, some approximate average value of
the function. And then you're multiplying by the width of the interval to get
the value of the integral. So that's the composite episode rule for you guys,
thank you, and that's the end of this segment. |