Ліві, праві, серединні Риманові суми

Before this, knowЩо таке Ріманові суми?

Video · + 2 min read

(Video) Approximating Definite Integrals Using Rectangles

by PatrickJMT

Here's a video by patrickJMT where he shows you how to approximate a definite integral using rectangles.

It is important to know that there are three types of rectangles we can take when approximating: left, right, and midpoint. As you will see in the following examples, they do give different results.

The left rectangle approximation is when you make the left hand points of the pieces the height of the rectangles.

Build a rectangle where the top left intersects the curve

The right rectangle approximation is when you make the right hand points of the pieces the height of the rectangles.

Build a rectangle where the top right intersects the curve

Finally, a midpoint rectangle approximation is when you make the midpoints of the pieces the height of the rectangles.

Build a rectangle where the midpoint intersects the curve, and the left and right top corners need not hit the curve

The first problem he looks at is:

Approximate ∫02(16−x2)dx\int_0^2(16-x^2)dx using n=4n=4 rectangles and left endpoints.

To start, we should draw the graph on the interval [0,2][0,2].

just draw the graph on the interval [0, 2], ignore the rest of it for now

Next, it tells us to use n=4n=4 rectangles. To determine the spacing we can use the formula: Δx=b−anΔx=2−04=12\begin{align} \Delta x&=\frac{b-a}{n}\\ \Delta x&=\frac{2-0}{4}\\ &=\frac12 \end{align}

Label the x-axis in 1/2-unit increments

Finally, it wants the rectangles to be left endpoints. This means the rectangles' height is based off the left point.

Draw rectangles within each 1/2-unit interval with the top left corner intersecting the curve

Left Endpoints

Finally we just sum up the area of each rectangle. A≈R1+R2+R3+R4A≈0.5f(0)+0.5f(0.5)+0.5f(1)+0.5f(1.5)A≈0.5[f(0)+f(0.5)+f(1)+f(1.5)]A≈0.5[(16−02)+(16−0.52)+(16−12)+(16−1.52)]A≈0.5[16+15.75+15+13.75]A≈30.25\begin{align} A&\approx\color{blue}{R_1}+\color{green}{R_2}+\color{orange}{R_3}+\color{red}{R_4}\\ A&\approx\color{blue}{0.5f(0)}+\color{green}{0.5f(0.5)}+\color{orange}{0.5f(1)}+\color{red}{0.5f(1.5)}\\ A&\approx0.5[\color{blue}{f(0)}+\color{green}{f(0.5)}+\color{orange}{f(1)}+\color{red}{f(1.5)}]\\ A&\approx0.5[\color{blue}{(16-0^2)}+\color{green}{(16-0.5^2)}+\color{orange}{(16-1^2)}+\color{red}{(16-1.5^2)}]\\ A&\approx0.5[\color{blue}{16}+\color{green}{15.75}+\color{orange}{15}+\color{red}{13.75}]\\ A&\approx30.25 \end{align}

Because our rectangles are containing area above the curve, we know that our answer is an overestimate.

This part is not in the video but let's see what happens when we use right endpoints.

Approximate ∫02(16−x2)dx\int_0^2(16-x^2)dx using n=4n=4 rectangles and right endpoints.

Since everything else is staying the same, the graph and the pieces will be the same as before.

Draw rectangles within each 1/2-unit interval with the top right corner intersecting the curve

Right Endpoints

Because these rectangles leave out some area under the graph, we expect this approximation to be less than the one above. A≈R1+R2+R3+R4A≈0.5f(0.5)+0.5f(1)+0.5f(1.5)+0.5f(2)A≈0.5[f(0.5)+f(1)+f(1.5)+f(2)]A≈0.5[(16−0.52)+(16−12)+(16−1.52)+(16−22)]A≈0.5[15.75+15+13.75+12]A≈28.25\begin{align} A&\approx\color{blue}{R_1}+\color{green}{R_2}+\color{orange}{R_3}+\color{red}{R_4}\\ A&\approx\color{blue}{0.5f(0.5)}+\color{green}{0.5f(1)}+\color{orange}{0.5f(1.5)}+\color{red}{0.5f(2)}\\ A&\approx0.5[\color{blue}{f(0.5)}+\color{green}{f(1)}+\color{orange}{f(1.5)}+\color{red}{f(2)}]\\ A&\approx0.5[\color{blue}{(16-0.5^2)}+\color{green}{(16-1^2)}+\color{orange}{(16-1.5^2)}+\color{red}{(16-2^2)}]\\ A&\approx0.5[\color{blue}{15.75}+\color{green}{15}+\color{orange}{13.75}+\color{red}{12}]\\ A&\approx28.25 \end{align}

Now let's take the same problem but use the midpoints. Do you expect this approximation to be the most accurate?

Approximate ∫02(16−x2)dx\int_0^2(16-x^2)dx using n=4n=4 rectangles and right endpoints.

Draw rectangles within each 1/2-unit interval with the midpoint of the top of the rectangle intersecting the curve

Midpoints

The left side is missing area under the curve but the right side has area above the curve. Because of this, we expect the two to balance each other, giving us an approximation somewhere in-between the left endpoint and right endpoint. A≈R1+R2+R3+R4A≈0.5f(0.25)+0.5f(0.75)+0.5f(1.25)+0.5f(1.75)A≈0.5[f(0.25)+f(0.75)+f(1.25)+f(1.75)]A≈0.5[(16−0.252)+(16−0.752)+(16−1.252)+(16−1.752)]A≈0.5[15.9375+15.4375+14.4375+12.9375]A≈29.375\begin{align} A&\approx\color{blue}{R_1}+\color{green}{R_2}+\color{orange}{R_3}+\color{red}{R_4}\\ A&\approx\color{blue}{0.5f(0.25)}+\color{green}{0.5f(0.75)}+\color{orange}{0.5f(1.25)}+\color{red}{0.5f(1.75)}\\ A&\approx0.5[\color{blue}{f(0.25)}+\color{green}{f(0.75)}+\color{orange}{f(1.25)}+\color{red}{f(1.75)}]\\ A&\approx0.5[\color{blue}{(16-0.25^2)}+\color{green}{(16-0.75^2)}+\color{orange}{(16-1.25^2)}+\color{red}{(16-1.75^2)}]\\ A&\approx0.5[\color{blue}{15.9375}+\color{green}{15.4375}+\color{orange}{14.4375}+\color{red}{12.9375}]\\ A&\approx29.375 \end{align}

Accuracy

The smaller the error, the better the approximation of the actual value of the integral (which can't always be computed explicitly) TypeValueErrorAccuracyActual29.3ˉLeft30.250.916ˉ96.88%Right28.251.083ˉ96.31%Midpoint29.3750.0416ˉ99.86%\begin{array}{|c|c|c|c|} \hline \text{Type}&\text{Value}&\text{Error}&\text{Accuracy}\\ \hline \text{Actual}&29.\bar{3}&\\ \text{Left}&30.25&0.91\bar{6}&96.88\%\\ \text{Right}&28.25&1.08\bar{3}&96.31\%\\ \text{Midpoint}&29.375&0.041\bar{6}&99.86\%\\ \hline \end{array}

Read · 8 min

Before Diving In

Now that we've covered extrema, let's move on to a more complex topic.

Before diving into this lesson, you may want to review how to find the derivative of a function, using a derivative test, and using integrals. If you haven't covered these topics yet, no worries! You have plenty of time before you will learn this complicated stuff.

Riemann Sums and Convexity

In this explanation, we're going to unite the concepts of Riemann Sums and Convexity. The reason we do this is because convexity helps us understand how powerful Riemann Sums are. But we're not going to assume knowledge of anything about Riemann Sums, so let's begin with some definitions, and we'll talk about convexity later.

A Riemann Sum is an approximation of an integral based on evaluating the function you're integrating at particular points.

There are different types of Riemann Sums but constructing any of them follows roughly the same pattern:

i) Pick an interval over which you're integrating your function

ii) Break that interval into (equally-sized) sub-intervals; for example, we can break [0,4][0, 4] into [0,1],[1,2],[2,3],[0, 1], [1, 2], [2, 3], and [3,4].[3, 4].

iii) Make a rectangle with one side on the x-axis and the opposite parallel to the x-axis, while the other two sides are parallel to the y-axis. The height of this rectangle will be determined on which type of Riemann Sum we use, so we'll get back to this later. The widths of the rectangles are the intervals we constructed in part ii).

iv) Calculate the areas of all the rectangles made in step iii) and add them.

This answer will be our "guess" as to the value of the integral. Sometimes our guess is close, and sometimes it's not; it depends on certain characteristics of the function. It also, of course, depends, on which type of Riemann Sum we use, and how many rectangles we use.

I'm going to introduce all three types of Riemann Sums and do a bunch of calculations with the same function so we can compare how all three types of sums work.

I'm going to first talk about the Midpoint Riemann Sum. The Midpoint Riemann Sum is one for which we evaluate the function we're integrating at the midpoint of each interval, and use those values to determine the heights of the rectangles.

Our example function is going to be f(x)=x2+1,f(x) = x^2 + 1, where we integrate over the interval [0,3].[0, 3]. We also get to choose the sizes of the rectangles, so for now we'll have each one be 11 unit, for a total of three rectangles.

The midpoints of our mini-intervals are 12,\frac{1}{2}, 32,\frac{3}{2}, and 52.\frac{5}{2}. This means our key step is to evaluate the function at these three points:

f(12)=(12)2+1=54f(32)=(32)2+1=134f(52)=(52)2+1=294.\begin{align} f\left(\frac{1}{2}\right) &= \left(\frac{1}{2}\right)^2 + 1 = \frac{5}{4} \\ f\left(\frac{3}{2}\right) &= \left(\frac{3}{2}\right)^2 + 1 = \frac{13}{4} \\ f\left(\frac{5}{2}\right) &= \left(\frac{5}{2}\right)^2 + 1 = \frac{29}{4}. \end{align}

Now, these are the heights of the three rectangles. We know they all have length 11 because we know their "horizontal" side lengths are along the intervals [0,1],[0, 1], [1,2],[1, 2], and [2,3].[2, 3]. Therefore, the total area is

54⋅1+134⋅1+294⋅1=474.\frac{5}{4} \cdot 1 + \frac{13}{4} \cdot 1 + \frac{29}{4} \cdot 1 = \frac{47}{4}.

Mentally take note of this value as we'll look to compare it to the values of the other Riemann Sums. Speaking of which, let's define them.

The Left Riemann Sum uses the left-endpoints of the mini-intervals we construct and evaluates the function at THOSE points to determine the heights of our rectangles. Let's calculate the Left Riemann Sum for the same function. The left endpoints of the intervals are 0,1,0, 1, and 2.2. So we evaluate ff there:

f(0)=(0)2+1=1f(1)=(1)2+1=2f(2)=(2)2+1=5.\begin{align} f(0) &= (0)^2 + 1 = 1 \\ f(1) &= (1)^2 + 1 = 2 \\ f(2) &= (2)^2 + 1 = 5. \end{align}

So the heights of our rectangles are 1,2,1, 2, and 5.5. The widths of the rectangles are still 11 unit each because we didn't change our intervals. Then the area is

1⋅1+2⋅1+5⋅1=8.1 \cdot 1 + 2 \cdot 1 + 5 \cdot 1 = 8.

Finally, the Right Riemann Sum uses the right-endpoints of the mini-intervals we construct and evaluates the function at THOSE points to determine the heights of our rectangles. For our particular example, the right endpoints are 1,2,1, 2, and 3.3. We already computed f(1)f(1) and f(2),f(2), while f(3)=32+1=10.f(3) = 3^2 + 1 = 10. Then the total area is

2⋅1+5⋅1+10⋅1=17.2 \cdot 1 + 5 \cdot 1 + 10 \cdot 1 = 17.

So in summary, the Left Riemann Sum has value 8,8, the Middle Riemann Sum has value 474,\frac{47}{4}, and the Right Riemann Sum has value 17.17.

Congratulations! You've now computed some simple Riemann Sums, of each of the three main types we want to talk about here. But this leaves a few questions unanswered.

The first is, why do we care about Riemann Sums? Couldn't we just have easily calculated

∫03(x2+1)dx?\int^{3}_{0}(x^2 + 1)dx?

Well in this case, yes, but let's say you instead are asked to integrate

∫17−44xex2+xarctan⁡(x2−2)+3dx.\int^{-44}_{17}xe^{x^2 + x}\arctan(x^2 - 2) + 3dx.

Yikes! That's not going to be fun. And I doubt it's possible to compute exactly. But you can use the same Riemann Integral Technique to get an ESTIMATE of what the value is. Oftentimes in industry an exact value isn't necessary, and an approximation is enough, so one can do a calculation like the ones we just showed you. It's also worth noting that especially if you have big numbers or a lot of rectangles, these calculations are usually done on a computer.

Here's another question you might think about: how many rectangles do we need? We can use as many as we want, but as we add more, the widths of them will be smaller, and we will have to sum more areas. If we get to using so many, we will get very close to the exact value of the integral. This is exactly why we care about limits, and it so turns out that the integral will equal the exact same thing as any of the Riemann Sums if we approach infinitely many rectangles (and of course, the individual area of each rectangle will go to zero, but we gain more and more rectangles, so these effects essentially cancel each other out).

If you're looking for a big fancy formula, you won't have to use one in practice for this, but it's helpful for understanding what's going on. Here's a formula for using Left Riemann Sums to find the value of the integral for a function f:f:

∫abf(x)dx=lim⁡n→∞∑k=0n−1b−an⋅f(a⋅kn+b⋅n−kn)\int^{b}_{a}f(x)dx = \lim_{n \rightarrow \infty}\sum^{n - 1}_{k = 0}\frac{b - a}{n} \cdot f\left(a \cdot \frac{k}{n} + b \cdot \frac{n - k}{n}\right)

The important things are this: b−ab - a is the total length of the interval you're integrating over, and we evaluate ff at the beginning of each mini-interval. The exact locations are determined as a weighted average between the two endpoints of the big interval, aa and b.b.

The last thing I want to talk about is how good our approximations are. That is, how close can we get to the actual value of an integral using a Riemann Sum? There are so many functions that it ultimately depends. I'm going to explore this from two different dimensions.

The first goes back to the formula we just talked about:

∫abf(x)dx=lim⁡n→∞∑k=0n−1b−an⋅f(a⋅kn+b⋅n−kn)\int^{b}_{a}f(x)dx = \lim_{n \rightarrow \infty}\sum^{n - 1}_{k = 0}\frac{b - a}{n} \cdot f\left(a \cdot \frac{k}{n} + b \cdot \frac{n - k}{n}\right)

Well, there is a near-identical one for the Right Riemann Sum:

∫abf(x)dx=lim⁡n→∞∑k=1nb−an⋅f(a⋅kn+b⋅n−kn)\int^{b}_{a}f(x)dx = \lim_{n \rightarrow \infty}\sum^{n}_{k = 1}\frac{b - a}{n} \cdot f\left(a \cdot \frac{k}{n} + b \cdot \frac{n - k}{n}\right)

Both formulas involve limits, which eventually equal the same value: ∫abf(x)dx.\int^{b}_{a}f(x)dx. But the expressions inside the limits are different, so what gives?

What this means we should expect is that, as we get closer to the exact value of ∫abf(x)dx,\int^{b}_{a}f(x)dx, the values of the Riemann sums we use to estimate this value should get close to EACH OTHER. If two Riemann sums have values close to that of ∫abf(x)dx,\int^{b}_{a}f(x)dx, then their values are close to each other as well. How close?

We do a quick calculation to help answer this question. Pick a large n,n, representing a Riemann Sum with many rectangles. Then we ask about the difference between the values of the Left and Right Riemann Sums. The formulas for the Left and the Right Riemann Sums are

L=∑k=0n−1b−an⋅f(a⋅kn+b⋅n−kn)L = \sum^{n - 1}_{k = 0}\frac{b - a}{n} \cdot f\left(a \cdot \frac{k}{n} + b \cdot \frac{n - k}{n}\right) R=∑k=1nb−an⋅f(a⋅kn+b⋅n−kn)R = \sum^{n}_{k = 1}\frac{b - a}{n} \cdot f\left(a \cdot \frac{k}{n} + b \cdot \frac{n - k}{n}\right)

and to get them we just pull the expressions out of the limits from the formulas for the exact value of the integral ∫abf(x)dx.\int^{b}_{a}f(x)dx. To find how the two estimates of this integral differ, we subtract one from the other and take an absolute value (think of the difference as a distance, perhaps between two points on the number line; distances are always regarded as nonnegative numbers by convention). So we define this distance to be ∣L−R∣,|L - R|, and we plug in the values of LL and RR to get

∣∑k=0n−1b−an⋅f(a⋅kn+b⋅n−kn)−∑k=1nb−an⋅f(a⋅kn+b⋅n−kn)∣\left|\sum^{n - 1}_{k = 0}\frac{b - a}{n} \cdot f\left(a \cdot \frac{k}{n} + b \cdot \frac{n - k}{n}\right) - \sum^{n}_{k = 1}\frac{b - a}{n} \cdot f\left(a \cdot \frac{k}{n} + b \cdot \frac{n - k}{n}\right)\right|

What do we do now? Well this is something called a telescoping series, because most of the terms cancel out between the two sums. The only terms that are left are

∣b−anf(0)−b−anf(n)∣=b−an∣f(a)−f(b)∣.\left|\frac{b - a}{n}f(0) - \frac{b - a}{n}f(n)\right| = \frac{b - a}{n}\left|f(a) - f(b)\right|.

If nn is large, then this number is going to be quite small. It says that if nn is large, the Left and Right Riemann Sums have almost the same value.

Finally, I want to do another calculation that is specific to when we integrate convex functions. A convex function is one defined so that for any x,y∈Rx, y \in \mathbb{R} and any λ∈[0,1],\lambda \in [0, 1],

f(λx+(1−λ)y)≤λf(x)+(1−λ)f(y).f(\lambda x + (1 - \lambda) y) \leq \lambda f(x) + (1 - \lambda) f(y).

Colloquially, convex functions curve upward. ex,e^x, x2,x^2, x,x, and x4x^4 are examples of convex functions. They are plentiful and worth investigating a bit more in detail. We're going to show a nice inequality is true if ff is a convex function. Again we state the formula for the Right Riemann Sum used to estimate ∫abf(x)dx.\int^{b}_{a}f(x)dx.

R=∑k=1nb−an⋅f(a⋅kn+b⋅n−kn)R = \sum^{n}_{k = 1}\frac{b - a}{n} \cdot f\left(a \cdot \frac{k}{n} + b \cdot \frac{n - k}{n}\right)

Notice that kn\frac{k}{n} and n−kn\frac{n - k}{n} are both between 00 and 11 because kk and nn are positive and n≥k.n \geq k. This means if ff is convex we can do the following for each kk in the sum:

f(a⋅kn+b⋅n−kn)≤knf(a)+n−knf(b)f\left(a \cdot \frac{k}{n} + b \cdot \frac{n - k}{n}\right) \leq \frac{k}{n}f(a) + \frac{n - k}{n}f(b)

Essentially we're using the definition of convexity where λ=nk,\lambda = \frac{n}{k}, x=a,x = a, and y=b.y = b.

Now it's time for some algebra. Multiply both sides by b−an,\frac{b - a}{n}, which is also positive.

b−anf(a⋅kn+b⋅n−kn)≤k(b−a)n2f(a)+(n−k)(b−a)n2f(b)\frac{b - a}{n} f\left(a \cdot \frac{k}{n} + b \cdot \frac{n - k}{n}\right) \leq \frac{k(b - a)}{n^2}f(a) + \frac{(n - k)(b - a)}{n^2}f(b)

Now we sum both sides of this inequality over all kk between 11 and n.n. The lesser side is just the definition of R,R, so

R≤∑k=1n(k(b−a)n2f(a)+(n−k)(b−a)n2f(b)).R \leq \sum^{n}_{k = 1}\left(\frac{k(b - a)}{n^2}f(a) + \frac{(n - k)(b - a)}{n^2}f(b)\right).

Why is this helpful? Well, notice both terms in the sum have factors that don't depend on k:k:

R≤b−an2f(a)∑k=1nk+b−an2f(b)∑k=1n(n−k).R \leq \frac{b - a}{n^2}f(a)\sum^{n}_{k = 1}k + \frac{b - a}{n^2}f(b)\sum^{n}_{k = 1}(n - k).

If we evaluate both of the sums left, we get

R≤b−an2f(a)⋅n2+n2+b−an2f(b)⋅n2−n2.R \leq \frac{b - a}{n^2}f(a) \cdot \frac{n^2 + n}{2} + \frac{b - a}{n^2}f(b) \cdot \frac{n^2 - n}{2}.

Finally, we can factor and cancel out some factors of n:n:

R≤b−an(f(a)(n+1)2+f(b)(n−1)2).R \leq \frac{b - a}{n}\left(\frac{f(a)(n + 1)}{2} + \frac{f(b)(n - 1)}{2}\right).

Why is this helpful? Well, if we don't care about the exact value of the Riemann Sum and an estimate is good enough for us, this expression only involves evaluating ff twice, even if there were a lot of rectangles. In some sense, we are giving up some accuracy to save a lot of time.

In summary, if a math problem is hard, look for clever ways to make it easier. Once you unlock the tools of calculus it becomes more apparent how you can do this.

Type a concept, like “slope” or “photosynthesis”.

↑ ↓ to choose · Enter to openSearch explanations and problems