Riemann sums: left, right, midpoint and trapezoid, and the limit that defines the integral
Ten problems on Riemann sums: left and right sums for x² on [0, 2], the midpoint sum and its error, the trapezoid rule and Simpson's combination, over- and underestimates for 1/x, the limit of right sums for 2x + 1 and for x², a sum recognized as π/4, distance from a table of speeds, how many subintervals an error bound needs, and the area under an ROC curve with uneven steps, with worked solutions and the mistakes of using every point in a left sum, writing x_i = i/n on the wrong interval and assuming equal widths.
Before you start
A definite integral is defined as a limit of sums: cut the interval into thin strips, approximate each strip by a rectangle, add up the rectangles, and let the strips get thinner. Those sums are also how integrals are computed when there is no antiderivative, only a table of measurements or a curve known at a few points, as with the area under an ROC curve. The choice of where each rectangle touches the curve decides whether the sum is too big or too small, and how fast the error shrinks. The work goes wrong in a few places: a left sum that uses every point, xi written as if every interval were ,[0,1], the endpoint weights of the trapezoid rule forgotten, equal widths assumed for unequal data, and the belief that a left sum always underestimates. These ten problems cover each of them.
Partition. Split [a,b] into n equal pieces of width ,Δx=nb−a, with points xi=a+iΔx for .i=0,1,…,n. There are n strips and n+1 points.
Left, right, midpoint.,Ln=Δxi=0∑n−1f(xi),,Rn=Δxi=1∑nf(xi), and .Mn=Δxi=1∑nf(2xi−1+xi). Each uses exactly n heights.
Trapezoid and Simpson..Tn=2Δx(f(x0)+2f(x1)+⋯+2f(xn−1)+f(xn))=2Ln+Rn. With unequal widths, add 21(xi+1−xi)(f(xi)+f(xi+1)) strip by strip. 32Mn+Tn is Simpson's rule on 2n strips.
Over or under. If f is increasing, Ln is too small and Rn too big; if decreasing, the other way round. If f is concave up, Mn is too small and Tn too big.
The definition..∫abf(x)dx=n→∞limi=1∑nf(xi)Δx. Useful sums: i=1∑ni=2n(n+1) and .i=1∑ni2=6n(n+1)(2n+1).
Error bounds. If ∣f′′∣≤K on ,[a,b], then ∣EM∣≤24n2K(b−a)3 and .∣ET∣≤12n2K(b−a)3.
Find the left and right sums L4 and R4 for f(x)=x2 on ,[0,2], and compare them with the integral.
·
Find the midpoint sum M4 for x2 on ,[0,2], and its error.
··
Find the trapezoid sum T4 for x2 on [0,2] and its error, and then the combination .32M4+T4.
··
Find L4 and R4 for f(x)=x1 on .[1,2]. Which is an overestimate?
··
Write ∫03(2x+1)dx as a limit of right sums and evaluate the limit.
···
Use right sums to show that ,∫01x2dx=31, and find .R10.
··
Evaluate n→∞limi=1∑nn2+i2n by recognizing it as a Riemann sum.
··
A car's speed is recorded every 10 seconds: ,0,,8,,14,18 and 20 m/s at .t=0,10,20,30,40. Estimate the distance traveled with left, right and trapezoid sums.
···
How many subintervals guarantee an error below 10−4 for ∫12xdx with the midpoint rule, and with the trapezoid rule?
···
A classifier's ROC curve passes through the points (false positive rate, true positive rate) ,(0,0),,(0.1,0.5),,(0.3,0.8),(0.6,0.9) and ,(1,1), joined by straight lines. Find the area under the curve.
Answers
,L4=1.75,;R4=3.75; the integral 38 lies between them
,M4=2.625, an error of 38−821=241≈0.0417
T4=2.75 with error ;−121;32M4+T4=38 exactly
L4≈0.7595 is the overestimate and R4≈0.6345 the underestimate
12
;∫01x2dx=31;R10=60011⋅21=0.385
4π≈0.7854
L4=400 m, R4=600 m, T4=500 m
Midpoint: ;n=29; trapezoid: n=41
AUC =0.025+0.13+0.255+0.38=0.79
Worked solutions
Problem 1
Find the left and right sums L4 and R4 for f(x)=x2 on ,[0,2], and compare them with the integral.
;Δx=42−0=21; points ;0,21,1,23,2; heights 0,41,1,49,4Five points, four strips.
L4=21(0+41+1+49)=21⋅27=47The first four heights.
R4=21(41+1+49+4)=21⋅215=415The last four heights.
∫02x2dx=38≈2.667The exact value, for comparison.
,L4=1.75,;R4=3.75; the integral 38 lies between themx2 is increasing on ,[0,2], so left rectangles sit under the curve and right ones stick out above it. .R4−L4=Δx(f(2)−f(0))=2.
Problem 2
Find the midpoint sum M4 for x2 on ,[0,2], and its error.
Midpoints 41,43,45,47Halfway along each strip of width .21.
Heights ,161,169,1625,1649, which add to 1684=421Square each midpoint.
M4=21⋅421=821Times .Δx.
,M4=2.625, an error of 38−821=241≈0.0417With the same four heights' worth of work, it is much closer than L4 or ,R4, and slightly low because x2 is concave up.
Problem 3
Find the trapezoid sum T4 for x2 on [0,2] and its error, and then the combination .32M4+T4.
T4=2Δx(f(0)+2f(21)+2f(1)+2f(23)+f(2))=41(0+21+2+29+4)Interior points count twice, the ends once.
,T4=41⋅11=411=2.75, which is also 2L4+R4The average of 1.75 and .3.75.
Error 38−411=−121Too big, because the chords of a concave-up curve lie above it. It is −2 times the midpoint error .241.
32⋅821+411=3421+411=38The weights 2 and 1 cancel the two errors.
T4=2.75 with error ;−121;32M4+T4=38 exactlyThis combination is Simpson's rule, which is exact for every polynomial of degree 3 or less.
Problem 4
Find L4 and R4 for f(x)=x1 on .[1,2]. Which is an overestimate?
;Δx=41; points ;1,45,23,47,2; heights 1,54,32,74,21,5/41=54, and so on.
L4=41(1+54+32+74)≈41⋅3.0381≈0.7595The first four heights.
R4=L4−41(1−21)≈0.6345The same sum with f(1) swapped for .f(2).
∫12xdx=ln2≈0.6931The exact value.
L4≈0.7595 is the overestimate and R4≈0.6345 the underestimatex1 is decreasing, so each strip's left edge is its highest point.
Problem 5
Write ∫03(2x+1)dx as a limit of right sums and evaluate the limit.
Δx=n3 and xi=0+i⋅n3=n3iEqual widths on .[0,3].
Rn=i=1∑n(2⋅n3i+1)n3=n218i=1∑ni+n3i=1∑n1Split the sum and pull out what does not depend on .i.
=n218⋅2n(n+1)+3=n9(n+1)+3=12+n9.∑i=1n1=n.
12+n9→12Take the limit.
12Check with an antiderivative: .[x2+x]03=12. For an increasing function every Rn is above the integral, here by exactly .n9.
Problem 6
Use right sums to show that ,∫01x2dx=31, and find .R10.
,Δx=n1,,xi=ni, so Rn=i=1∑nn2i2⋅n1=n31i=1∑ni2Right endpoints on .[0,1].
Rn=n31⋅6n(n+1)(2n+1)=6n2(n+1)(2n+1)The sum of squares.
6n2(n+1)(2n+1)=6n22n2+3n+1→62=31Divide top and bottom by .n2.
;∫01x2dx=31;R10=60011⋅21=0.385This is the calculation Archimedes did for the parabola, with no antiderivative in sight. R10 is still 0.052 too high.
Problem 7
Evaluate n→∞limi=1∑nn2+i2n by recognizing it as a Riemann sum.
n2+i2n=n1⋅1+(i/n)21Divide top and bottom by n2 to expose ni and a factor .n1.
This is i=1∑nf(xi)Δx with ,f(x)=1+x21,,xi=ni,Δx=n1A right sum on .[0,1].
∫011+x2dx=arctan1−arctan0The limit of the sums is the integral.
4π≈0.7854At n=1000 the sum is about ,0.78515, slightly low because 1+x21 is decreasing.
Problem 8
A car's speed is recorded every 10 seconds: ,0,,8,,14,18 and 20 m/s at .t=0,10,20,30,40. Estimate the distance traveled with left, right and trapezoid sums.
Distance is ,∫040v(t)dt, and Δt=10Four strips of 10 s.
L4=10(0+8+14+18)=400 mThe speed at the start of each interval.
R4=10(8+14+18+20)=600 mThe speed at the end of each interval.
T4=210(0+2⋅8+2⋅14+2⋅18+20)=5⋅100=500 mThe average of L4 and .R4.
L4=400 m, R4=600 m, T4=500 mThe car speeds up throughout, so the true distance is between 400 and 600 m, and the trapezoid estimate is the best of the three.
Problem 9
How many subintervals guarantee an error below 10−4 for ∫12xdx with the midpoint rule, and with the trapezoid rule?
f′′(x)=x32≤2 on ,[1,2], so K=2f′′ is largest at the left end.
Midpoint: 24n22⋅13=12n21<10−4 needs n2>833.3282=784 is too small and 292=841 is enough.
Trapezoid: 12n22⋅13=6n21<10−4 needs n2>1666.7402=1600 is too small and 412=1681 is enough.
Midpoint: ;n=29; trapezoid: n=41The midpoint bound is half the trapezoid bound, so the trapezoid rule needs about 2 times as many strips. These are guarantees; the actual errors at these n are smaller still.
Problem 10
A classifier's ROC curve passes through the points (false positive rate, true positive rate) ,(0,0),,(0.1,0.5),,(0.3,0.8),(0.6,0.9) and ,(1,1), joined by straight lines. Find the area under the curve.
The widths are ,0.1,,0.2,0.3 and 0.4The steps in the false positive rate are not equal.
21⋅0.1⋅(0+0.5)=0.025 and 21⋅0.2⋅(0.5+0.8)=0.13One trapezoid per segment, each with its own width.
21⋅0.3⋅(0.8+0.9)=0.255 and 21⋅0.4⋅(0.9+1)=0.38The last two segments.
AUC =0.025+0.13+0.255+0.38=0.79With straight lines between the points the trapezoid rule is exact, not an estimate. A random classifier's diagonal has area 0.5 and a perfect one .1.
Where this goes wrong
1. Using every point in a left sum
The table of values has n+1 entries, and all of them go into the sum.
Δx=41 and heights 1,54,32,74,21 for x1 on [1,2]Right so far: Problem 4, step 1.
“Add the heights and multiply by .Δx.”The habit that causes the mistake: there are five points but only four strips.
L4=41(1+54+32+74+21)≈0.8845That counts a fifth rectangle, over ,[2,49], outside the interval. A left sum uses the first n heights, giving ;0.7595; a right sum uses the last .n. Only the trapezoid rule uses all ,n+1, and with the ends halved.
2. Writing x_i = i/n on the wrong interval
xi=ni is the most familiar form, and it gets used for every interval.
∫03(2x+1)dx with Δx=n3Right so far: Problem 5, step 1.
“.xi=ni.”The habit that causes the mistake: the formula for [0,1] used on .[0,3].
Rn=i=1∑n(n2i+1)n3=6+n3→6The points ni only reach ,1, so this is ,3∫01(2x+1)dx, not the integral over .[0,3]. With xi=a+iΔx=n3i the limit is .12.
3. Giving the endpoints full weight in the trapezoid rule
The trapezoid rule's pattern of 1,2,2,…,2,1 gets flattened to all ones, or the factor of 21 gets lost.
Speeds 0,8,14,18,20 every 10 sRight so far: Problem 8.
“The trapezoid rule adds the readings and multiplies by .Δt.”The habit that causes the mistake: every reading counted once, at full width.
T4=10(0+8+14+18+20)=600 mThat is five full rectangles over four intervals. Each end reading belongs to one trapezoid and each interior reading to two, each with half weight: 5(0+16+28+36+20)=500 m.
4. Assuming equal widths for unequal steps
Four trapezoids on [0,1] suggests a width of 41 each.
Points ,(0,0),,(0.1,0.5),,(0.3,0.8),,(0.6,0.9),(1,1)Right so far: Problem 10.
“Four strips on ,[0,1], so .Δx=0.25.”The habit that causes the mistake: the equal-width formula used on data that were not sampled evenly.
AUC =0.25(20+0.5+20.5+0.8+20.8+0.9+20.9+1)=0.25⋅2.7=0.675The steep first segment is only 0.1 wide and the flat last one is 0.4 wide, and equal widths get both wrong. Each trapezoid needs its own width: the area is .0.79.
5. Assuming a left sum always underestimates
In the usual picture, of an increasing curve, the left rectangles sit under it.
L4≈0.7595 for ∫12xdxRight so far: Problem 4, step 2.
“Left sums are too small.”The habit that causes the mistake: a rule for increasing functions applied to every function.
So ln2>0.7595x1 is decreasing, so each left edge is the strip's highest point and L4 is too big: .ln2≈0.6931. Decide over or under from whether f increases or decreases on the interval, and if it does both, the sum alone does not tell you.
Print this set: riemann-sums.pdf (problems, answers, and worked solutions on separate pages).