Skip to content
All apps

Numerical integration

About this app

Approximate the area under f(x) with rectangles, trapezoids or Simpson parabolas. Slide n and see in the log–log diagram how the order of convergence (slope) determines the method: O(h) vs. O(h²) vs. O(h⁴).

The idea

Numerical integration approximates a definite integral ∫ₐᵇ f(x) dx by splitting the interval into n subintervals of width h = (b − a)/n and using a simple shape on each. Left and right sums use rectangles with the height at an edge; their error falls like O(h). The midpoint rule takes the height at the centre, and the trapezoidal rule joins f(xᵢ) and f(xᵢ₊₁) with a straight line; both have error O(h²). Simpson’s rule fits parabolas through three points and reaches O(h⁴). Halving h therefore cuts the error to roughly ½, ¼ or 1/16.

What the app shows

The top view shows the area under f(x) with the rectangles, trapezoids or parabolic arcs of the chosen method. You can pick left, right and midpoint sums, trapezoidal and Simpson’s rule, and the functions sin x, eˣ, 1/(1 + x²) and e^(−x²). The values panel lists the interval, n, h, the approximation Iₙ, the exact value, the error |I − Iₙ| and the observed order. Below, a log-log plot shows the error against n with reference lines for O(hᵏ).

Try it yourself

Increase n step by step and compare the slopes in the log-log plot: each method’s line runs parallel to one of the reference lines, and its slope is the order. Simpson drops the fastest. Switch between functions and check whether the order stays the same. The slider runs from n = 1 to n = 40.

Frequently asked questions

What is the difference between the trapezoidal rule and Simpson’s rule?
The trapezoidal rule replaces f on each subinterval with a straight line, Simpson’s rule with a parabola through three points. For smooth functions Simpson’s error is of order O(h⁴), the trapezoidal rule’s only O(h²). With the same n, Simpson is usually much more accurate.
What does order of convergence mean in numerical integration?
The order p describes how the error shrinks with step size h: error ≈ C·hᵖ. With order 2, halving h divides the error by four. On a log-log plot this appears as a straight line with slope p.
Why is the midpoint rule more accurate than left or right sums?
The rectangle height is taken at the centre of the subinterval. Over- and underestimates on either side largely cancel for smooth functions. That gives order 2, while left and right sums only reach order 1.
Which functions and methods can I choose in the app?
The functions sin x, eˣ, 1/(1 + x²) and e^(−x²), and the left, right, midpoint, trapezoidal and Simpson rules. A slider sets the number of subintervals n.

Subject: Numerics

More from Numerics

A VisuApp by heyprof: interactive, free in your browser, no sign-up. What is a VisuApp? · All apps