Sunday, February 28, 2010

 

How do you do an integration in Excel?

I got the following question from two students and decided to make up an example spreadsheet showing how to do integration in Excel to share with all of you. (Sunday@4:42 PM - I just posted this to a new server that should work better. Monday at 11:09 AM - I changed it to make it easier to read and to match better with the midpoint definition in Wikipedia.)

Suppose we want to integrate x2 from 0 to 2. Analytically, know the solution is 2 2/3. Even if we couldn't solve it analytically, we could solve it numerically using the rectangle method.  This is done in the example spreadsheet, with dx set to 0.1. I'm using the "midpoint" approximation instead of the top-left or top-right corner approximation.

You'll notice that I don't bother to calculate the midpoint between x=0 and x=-dx since we won't be using that in the calculations. Very often when doing numerical integrals or derivatives in a spreadsheet, you end up with a column with one extra or one fewer row.

If you try changing dx to 1.0, you see that the solution comes out to 3.0, which is pretty close to correct. If you try changing it to 0.01 and scroll down, you'll see that you get a closer answer.


Comments: Post a Comment





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]