Welcome to our lesson on approximate integration, sometimes called numerical integration. This is the idea where you have an integral that you want to solve but the methods that you know do not work to solve this integral or the table doesn't appear in the back of the book. This is the theory behind what goes on. There's plenty of websites that you can throw an integral in and locate back a decimal, but like this goes on what happens, how to interpret the number, what's going on behind the scenes. The idea is just as follows. It's so brilliant, it's dumb, but you have some curve defined by a function f(x), and you want to know some integral from A to B. Maybe it means something, and you're after the meeting of this integral here. You want to find the area of the shape or the net accumulation. I guess I drew a really nice curve here, but let's just say with something horrible thing like a stock market curve or some lab results or something bad. Remember the idea of Riemann sums. Riemann said, hey, why don't we put some rectangles underneath the attached to this curve. Maybe the left-hand point is on it or maybe the right endpoint is on it. I don't know but this is the idea and you get a nice, easy, albeit annoying way to find or approximate the area. Let's just say that we have N rectangles. The N for Riemann sum was an approximation to the area. Now the rectangles were chosen. You have a bunch of ways that choose it. Like how do you want to place the rectangles? No matter how are you going to do it. You can already see from the picture, you're going to get errors, so it's an approximation, but you can choose any way to draw the rectangle, and you can choose any number of rectangles you want. There's a couple choices that come up that are pretty standard. We've seen these before. You can pick the left end point to go on the curve, and then you draw a bunch of rectangles. There's nothing stopping you from picking the right end point on the curve. The none's going to stop you there. You can also imagine picking the mid point on the curve. The shape doesn't change, but the method you use to approximate it does. That's the idea. Let's just put the mid point on the curve will draw big rectangles. Hopefully you can see it a little more obvious. But if you take the midpoint of an interval and you place that part on the curve and then you start breaking things up. You just get different errors back. The main theory that we're after is that if you choose infinitely many rectangles, if you take the number of rectangles go to infinity, you take the partition smaller and smaller, then the left becomes the right becomes the midpoint. It doesn't matter. None of this matters as the limit of N goes to infinity. Why, if you're a rectangle and you're getting smaller, your left becomes your right becomes your middle. It just doesn't matter. However, if you don't have, the theory or an integral to get a definite integral and you have to approximate, well then it does because it's going to mess up how much error you have. There's other ways to do it of course, there's something we're going to talk about here called Trapezoid Rule. There's another one called Simpson's rule, not after the cartoon. There's a whole bunch of ways to do it, but this is the idea. Then you find the Riemann sum by summing all over your rectangles. Let's just say I equals zero to N of your formula, f(x) whatever your sample point is, times the length of the partition. Length and partition could also vary. You just have so many options here. Normally this is best left to a computer to do. You don't want to be sitting here adding fifty, hundred things, but in this section we're just going to try to introduce you to the idea and the theory, and we're going to pick one of these we've seen left, right, and you can imagine midpoint but let's just talk about Trapezoid Rule for a minute. We'll just do it like a specific example of this. The theory that we talked about in Trapezoid Rule is going to apply to the rest of them. Let's start off with some curve, so we have some graph and we don't know the function for it. We don't know the actual function, it's doing its thing, strategy. I will draw a nice swooping graph here and we care about what's going on from, let's say A to B. We are after the area under this curve, I don't have a function to do it. If I were to draw rectangles, if I were to draw rectangles, there's a lot of error, I guess, and you can see that pretty quickly from just a basic sketch. Let's do a right-side on the graph. The right side on the graph, you get a lot of error terms. This one's going to be over. You get a lot of errors. This is the observation to make, that rectangles tend to have more error. That's not great if you're approximating, if you're taking the limit and doing an actual fundamental theorem calculus question, then who cares? But we're not doing that here. Rectangles have more errors. Instead what I want to do, let's actually erase this. Let's do it on the same picture. Is, I want to notice that if I drew trapezoids, so I'll put the first side on the graph and then we'll feel like the second side of the graph as well. If I did trapezoids, which by their nature, sort of have that nice diagonal roof. They will fit a curve a little better. You can draw your own picture to see this. But if you place trapezoids above or below the curve, you have less error. Trapezoids, is what we're going to talk about today. Trapezoids. Remember these things from high school geometry, they have less error. If you're trying to approximate, then this is good. Now we need to remember how do we use trapezoids to approximate area. Maybe you remember this, but the area of a trapezoid is equal to the base. You're going to mention thing on the side here. It's the base times the average of its two heights. Let's write out, I'll just say heights here in a second. It's the average of the heights times the base. Now the question is, where is this going to come from? Well, the heights come from the function. Suppose that we have some curve bounded in the interval A to B, and we need to approximate the area. We need to first decide how many partitions. I want to find. Some partitions are the things that are good. Tell me how many x values, how many trapezoids I actually care about. Let's just call the left side of the first trapezoid x_1 and then you have x_2 and x_3, and so on. When you work this out, you're going to get second to last one and then the last one, which we call x_n plus 1. I'll just focus on this very, very first trapezoid here, the height of the first trapezoid is one half the average of the two heights. F of x_1 plus f of x_2. Then the height of the second trapezoid, you'll see a pattern here in a second, is one-half parenthesis f of x_2 plus f of x_3. These are my heights here and so on. You work those out. Then the area of the total area, is going to be the base. Now how do I find the base that doesn't change? The area of my base, which we call Delta X, is b minus a over n. N is the number of rectangles. The true area under this curve will be approximated by b minus a over n, and then each term is going to have a half. Let's write it as one-half, just factor it out of all the terms. Then there's f of x_1. Now pay attention here because there's a f of x_2, but then there's another f of x_2 plus f of x_3. Then there's another f of x_3. Because each term gets doubled up there. If you're not the first one, you're not the last one. The pattern continues until you get to f of x_n plus of f of x_n plus 1. Throughout the other, clean it up and again, you should see the formula for trapezoids emotion here, the first trapezoid is represented by the first two terms, half the height times the base. Then the next two terms is the next trapezoid and so on and so forth. When you clean this up you get what's called the trapezoid rule. They combine the n, the two to get 2_n over here just for the fraction stuff out front. Then just be careful you have f of x_1 plus, and remember there's two of these f of x_2s. You get 2f of x_2 plus 2f of x_3. It goes on for awhile, as many rectangles as you have, 2f of x_n. Then there's only one last term at the very end. Just one f of x_n plus 1. Close it up. This is called the trapezoidal rule. This is the trapezoidal rule. This is the formula to approximate area using trapezoids, using n trapezoid. All the other formulas of Z formulas for the midpoint rule and all the other stuff. They follow the same idea. They follow from the same. To give you an example of just putting this thing and use, let's do one or we know and then we can compare the approximation. Let's do the integral. We can from to 1-3 of one over x d_x. Now, we know what this answer is going to be. This is the natural log of the absolute value of x evaluated from 1-3, which turns out to be ln of 3 minus ln of 1, ln of 1 of course is just zero, so this is natural log of 3. Now, natural log of 3 is a very nice closed form. But what if I wanted you to round this to a couple of decimals? You would have to go to the calculator. I doubt many of us know what this is, but now how's the calculator getting the numbers behind it? What's the theory? How's it working? Well, obviously it's approximating this number somehow, but obviously it's using calculus. I don't know if it's using the trapezoid rule or not, but we can certainly use the trapezoid rule to follow this. Let's see now. Let's draw a picture to motivate what we're about to do. The function 1 over x, which is the one we want since we're only focusing on 1-3, we'll pick it up. Let's draw a picture not drawn to scale, but something at 1, and we'll say 2, and we'll say 3. These are my values here. This is the function y equals 1 over x. I have 1 and then a third here. We're after this area, which we already know from our theory that we've established that the area underneath is in fact natural log. But let's approximate this numbers. Let's try to get decimal to it. For no good reason just to keep the calculations relatively manageable, let's break this up into four equally spaced regions. We'll partition this thing in four so we have two before two and two after two. Here's one, one and a half, let's write it as 3 over 2, two and then two and a half, or 5 over 2, and three. Equally spaced spaces. This allows me to compute my base. Delta x would be b minus a over n. In this case it's 3 minus 1 over 4, which is 2 over 4, which is a half. Very nice. Now, I am going to approximate these shapes with trapezoids. The roofs of these shapes are all linear, they are lines. Now I want to find, after I found the partition, what x values correspond to together after the trapezoid rule. The area will be approximated by remember it was the base, so here's one-half and I got another one-half floating around. Be careful here. It's going to be the first value, so f of 1 plus 2, f of 3 over 2, plus 2, f of 2, and then plus 2, f of 5 over 2, and then the last one does not get a double dot. Now, this function is my reciprocal function, so this is going to equal, we're going to have one-fourth in front from combining the two one-halves, so just take the reciprocal of all these numbers. This becomes 1 plus 2 times two-thirds plus 2 times a half plus 2 times reciprocal of 5 over 2 is two-fifths plus, and then f of 3 is just a third. Now we have a lot of numbers to basically add up. It's not terrible, you can definitely put them over a common denominator just by the choice of this here. But obviously this can get nasty the more numbers you have, and if you're going to run to a calculator, you probably could have done it anyway, but natural log of 3 and 4 is not the greatest approximation anyway. For this example though, if you want to practice 15 would be a nice common denominator. If you put them over, you can check 67 over 15. You get 67 over 15 and you can check that this is about 1.1167, give or take. Now, with four rectangles, not the best approximation, you obviously want more, but the true value of natural log of 3, and you can check this with your calculator, is 1.0986 then it goes on forever. But you can tell that it gets close. We're not way out of the ballpark to get this number, so it's close. Obviously if you want to make it better, we would take more rectangles if we cared about precision and that sort of thing. Anyway, this is just the idea of trapezoid rule. Other ones would be the same, midpoint rule and the other. They are calculator dependent. They usually are found in more real life examples, they're used to bound errors and this kind of thing. Best case scenario, we know the function, we know the exact value. Real life doesn't always happen, so we approximate. Good job on this video and I'll see you next time.