# 8 – Approximating The Integral

In the next notebook, you’re going to learn a technique that will let you integrate any function of a single variable and all it’s going to take is a loop. Before you jump into this code, let me briefly explain the theory behind what you’re going to be doing. So, let’s say you want to integrate velocity with respect to time but your velocity is given by some pretty complicated function, as is often the case in the real world. And let’s say you want to use this velocity data to calculate your displacement from T equals one to T equals five. How do you calculate the area when the shape isn’t a rectangle? The trick is this, you just don’t. Instead, you approximate. So, let’s start by making a really bad approximation, where we just pretend the speed at the beginning is the speed throughout the entire four-second time interval. Well then, our area, it’s just the height times the width. And in this case, the height would be the value of the velocity function evaluated T equals one, and the width. Well, that’s just the time interval Delta T, which in this case is four seconds, but clearly, this is a really bad approximation. It fails to account for all of this area above the line. But no problem, let’s improve our approximation. One way to do that is by breaking the single interval with a Delta T of four seconds into four time intervals with Delta T of one second. And then, for this first time interval, from T equals one to two, we just draw a rectangle, and then we use the velocity T equals one as the velocity for the whole interval. And then, we just repeat this procedure for two to three, three to four, and for T equals four to five and this will give a better approximation of the actual area under the curve. But you probably notice it isn’t perfect. In addition to underestimating in the first two segments, it actually overestimates in this last segment. So, while this is an improvement, it’s still just not good enough. Had we solved the problem? Well, we chop our graph up into smaller rectangles. For example, we could use a time interval of half-a-second, and this is definitely getting better, but we could go even smaller. As we reduce the width of these time intervals closer and closer to zero, we’re going to get closer and closer to the true area under the curve. Okay, sorry. That’s enough talking from me. I get very excited about the class. Why don’t you go ahead and do this yourself?