## Lesson goal: Doing integrals numerically

Previous: Testing the derivative | Home | Next: Introduction

You might remember integration from calculus as being interpreted as the "area under the curve." This is a true, albiet short-sighted idea, but we'll go with it here. You may have learned to do definite integrals like $\int_0^1 x^2 dx=\frac{1}{3}x^3|_0^3$. This would be simplified to $\frac{1}{3}[1^3-0^3]=0.333$.

In this lesson, we'll learn how to have the computer do such integrals for us. The integrals we'll do here are definite integrals (with upper and lower limits), and with the typical functions found in a first-term calculus class.

The plan here is one found in your elementary calculus book: panel a bunch of small rectangles under the curve-to-integrate, find the area of each rectangle, add up the areas of all of these rectanlges, and this will be our total "area under the curve" (and answer to your integral).

#### Now you try. Fix the function $f(x)$ to return the function you wish to integrate. Then, fix the N= line to reflect the number of rectanges you want under your curve. Next fix the upper and lower limits, $a$ and $b$. Lastly, the sum=sum+ line to add the area of the current rectangle to the running sum of areas.

Type your code here:

See your results here: