Trapezoidal Rule for numerical integration

Click For Summary

Discussion Overview

The discussion revolves around the trapezoidal rule for numerical integration, particularly its application to functions that take on both positive and negative values. Participants explore the implications of using this method in such cases, including potential sources of error and the nature of the approximations involved.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant notes that the trapezoidal rule is typically illustrated with strictly positive functions and questions its effectiveness when applied to functions that are both positive and negative, suggesting that the area calculated may not represent a trapezoid in some cases.
  • Another participant argues that the trapezoidal rule can still yield valid results even when one endpoint of a subinterval is zero, as it effectively calculates the area of a triangle in such scenarios.
  • Some participants highlight that having a root within an interval can lead to inaccuracies in area approximation, advocating for smaller intervals to mitigate this issue.
  • There is a discussion about the inherent error in the trapezoidal method, with one participant suggesting that this error is covered in standard error analysis of the method.
  • Another participant emphasizes the need to treat positive and negative regions of a function separately when applying numerical integration, acknowledging the practical challenges in identifying these regions beforehand.
  • One participant presents a formula for error in numerical integration, linking it to the second derivative of the function and suggesting that maximum error occurs where the second derivative is largest.
  • There is a mention of the importance of not blindly applying numerical methods without understanding their behavior and potential pitfalls.
  • Several participants discuss the theoretical underpinnings of error analysis, with one providing an explanation of how maximum error can be derived from the properties of piecewise parabolas.

Areas of Agreement / Disagreement

Participants express differing views on the effectiveness of the trapezoidal rule for functions with both positive and negative values, with some agreeing on the need for careful application and error consideration, while others maintain that the method can still be valid under certain conditions. The discussion remains unresolved regarding the best practices for applying the trapezoidal rule in these contexts.

Contextual Notes

Participants acknowledge that the trapezoidal rule's effectiveness can vary based on the function's characteristics, particularly its continuity and the behavior of its derivatives. There is also recognition of the limitations in identifying regions of positivity and negativity in advance, which complicates the application of numerical integration methods.

Who May Find This Useful

This discussion may be useful for students and practitioners in numerical analysis, particularly those interested in the application of numerical integration methods and the associated error analysis.

xaenn
Messages
16
Reaction score
0
The trapezoidal rule for numerical integration is based on the idea that when we partition our larger interval into subintervals, we can approximate the area over each subinterval by calculating the area of the trapezoid formed by connecting the value of the function at the left and right endpoints of the subinterval with a straight line.

In all of the calculus textbooks I was looking through, this is only illustrated using a strictly positive function. When you start looking at a function that is positive and negative, there is no guarantee that over a given subinterval you even get a trapezoid (see the attached image). In that image there are 5 subintervals, and the middle one certainly doesn't yield a trapezoid. If we calculate the actual area over that subinterval it is going to be two triangles, and yield something quite different from what the area of a trapezoid would have been.

I don't know a whole lot about numerical analysis, but I'm guessing this would be one additional source of error in this method? Although you are calculating the area for a trapezoid over each subinterval, in some cases the actual (approximated) area you're dealing with isn't even a trapezoid. I don't know if there's much more to say about this other than that I found it very curious, but I would love to hear the perspective of someone with a stronger numerical analysis background on this issue.

Regards,
-Xaenn
 

Attachments

Physics news on Phys.org
I don't see a problem.

Let h be the step size. The area of your trapezoid is given by:

A_n = h \frac {f(x_n) + f(x_{n+1})} 2

Now if you have either f(x_n) =0 or f(x_{n+1})=0

you get :

A_n = h \frac {f(x)} 2 where f(x) is the non zero side.

this is the area of a triangle. Looks like it works just fine to me.

Edit:

I just looked at your graph again. I now see where a potential problem lies. Not in the triangles, but having a root in the middle of a interval, the trapezoid method does not give a good area in this case, this is why smaller intervals are better. I think you will find that this sort of error is covered in the usual error analysis of this method. By this I mean that you know from the start that there is an inherent error in the method, so this is not unexpected.

Edit yet agian.

Your graph is NOT x + sin(x) perhaps just sin(x).
 
Last edited:
Integral said:
I just looked at your graph again. I now see where a potential problem lies. Not in the triangles, but having a root in the middle of a interval, the trapezoid method does not give a good area in this case, this is why smaller intervals are better. I think you will find that this sort of error is covered in the usual error analysis of this method. By this I mean that you know from the start that there is an inherent error in the method, so this is not unexpected.
You're probably right; I am sure this type of error probably is covered in the error analysis. I just found it curious because the thought that the trapezoidal rule would give you a shape other than a trapezoid never crossed my mind.
Your graph is NOT x + sin(x) perhaps just sin(x).
This was pure laziness on my part. The original function I was dealing with was x + sin(x), which of course didn't have this problem. I just forgot to change the label when I was playing around with it. ; ) Thanks for your response.

If anyone could suggest any good numerical analysis references I could look at for an in-detail error analysis that would be excellent.
 
The idea of the integral as an area is only valid where the function has positive values. In order to apply any kind of numerical integration, you need to do regions where the function values are positive and regions where the function values are negative separately.
 
If you notice, the error is biggest where the function has the largest second derivative (in magnitude). This is no coincidence - you can show that the error, E, is given by
E = k h^2 f''(w)

where h is the step width, w is some point in the domain, and k is a constant.
 
As a addition to Halls post, you simply cannot blindly apply a numerical method. You need to keep a careful eye on what it is doing and how it is working. If you blindly apply the trapezoid rule to your example you get that the integral of sin from 0 to 2pi= zero. Which is exact. What error?
 
HallsofIvy said:
The idea of the integral as an area is only valid where the function has positive values. In order to apply any kind of numerical integration, you need to do regions where the function values are positive and regions where the function values are negative separately.
Or rather in an ideal world we can look at a function, break it into regions where it is positive and negative, and then consider them separately as signed areas. The only problem being that a priori you don't know where those areas are going to be. Thus, there is something of a jump between the theoretical and practical. As long as we recognize that, and that there may be resulting error because of that, I don't see it as a problem.

maze said:
If you notice, the error is biggest where the function has the largest second derivative (in magnitude). This is no coincidence - you can show that the error, E, is given by
E = k h^2 f''(w)
Would you care to elaborate on why this is no coincidence (without me actually working out all of the calculations as to why this is the maximum error)?

Integral said:
As a addition to Halls post, you simply cannot blindly apply a numerical method. You need to keep a careful eye on what it is doing and how it is working. If you blindly apply the trapezoid rule to your example you get that the integral of sin from 0 to 2pi= zero. Which is exact. What error?
Of course. I wouldn't propose to just blindly apply such a method. When we're talking about error we're talking about maximum possible error anyway. It's just too easy to trick all of the first year students with an amazing Riemann sum that uses 1 interval and gets the exact answer. : )

Thanks for the book suggestion as well. I'll look into it.

Thanks again to everyone for their responses.
 
xaenn said:
Would you care to elaborate on why this is no coincidence (without me actually working out all of the calculations as to why this is the maximum error)?

Ahh certainly. Let's consider all functions that have second derivative less than or equal to a certain constant. If you try to find the function that generates the absolute maximum error possible under this constraint, you will find that the error can be no greater than a series of piecewise parabolas, one parabola over each section of the approximation (In fact, it will be less except under extremely contrived circumstances since the derivatives and second derivatives must match at the joint). The maximum error for a single piece is then just the area between a parabola and a line, which you can find, and then multiply by the number of pieces to find a bound on the total error.

http://img413.imageshack.us/img413/1505/trapezoiderrorqv5.png
 
Last edited by a moderator:
  • #10
maze said:
Ahh certainly. Let's consider all functions that have second derivative less than or equal to a certain constant. If you try to find the function that generates the absolute maximum error possible under this constraint, you will find that the error can be no greater than a series of piecewise parabolas, one parabola over each section of the approximation (In fact, it will be less except under extremely contrived circumstances since the derivatives and second derivatives must match at the joint). The maximum error for a single piece is then just the area between a parabola and a line, which you can find, and then multiply by the number of pieces to find a bound on the total error.

http://img413.imageshack.us/img413/1505/trapezoiderrorqv5.png
Thank you very much for the explanation and image. Extremely insightful.
 
Last edited by a moderator:
  • #11
I don't see how a sign change is relevant? The "trapezoid" in this case consists of a positive triangle and a negative triangle. The mathematics still give the correct signed area.

If you are trying to calculate unsigned areas, then what you are doing is not strictly integration. No matter what numerical method you use, in that case you will have to find where the function crosses the x-axis and integrate each region separately.
 
  • #12
Integral said:

Now that I've gotten a chance to pick up this book and go through it I just wanted to say it is a very nice introduction to numerical analysis. The presentation is clear and reading through the book has been extremely insightful. It's also piqued my interest to the point where I'd really like to study more numerical analysis. Thanks again for the recommendation.

I now feel like I have a good understanding of (basic) numerical integration, whereas before I really was clueless. I was looking at the picture pained by Thomas' calculus, which had little to do with what numerical integration actually is.
Ben Niehoff said:
I don't see how a sign change is relevant? The "trapezoid" in this case consists of a positive triangle and a negative triangle. The mathematics still give the correct signed area.

You are right that a sign change isn't really relevant. I thought it was because I mistakenly understood that the trapezoid rule came from finding the area of a trapezoid, rather than being named that way simply because the area coincides with that of a trapezoid in the case where the function of interest is one-signed.
 
Last edited by a moderator:

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 24 ·
Replies
24
Views
4K
  • · Replies 16 ·
Replies
16
Views
4K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 11 ·
Replies
11
Views
2K
Replies
1
Views
8K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K