# Python program to evaluate a Riemann sum?

Page 1 of 1

## 1 Replies - 12326 Views - Last Post: 04 September 2007 - 09:13 PMRate Topic:     //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=32678&amp;s=d6d6f9d0d24465102ae5c113f75ac6ec&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 FarmGirl Reputation: 0
• Posts: 5
• Joined: 03-September 07

# Python program to evaluate a Riemann sum?

Posted 03 September 2007 - 11:06 PM

"Create a python program that evaluates a Riemann sum for the function f(x) = x^3 and use this to approximate the integral from a to b of x^3 dx for a=1, b=2."

I don't know even how to begin to do this! Do I start with a range? Can I have a hint as to how to start? HELP!
Is This A Good Question/Topic? 0

## Replies To: Python program to evaluate a Riemann sum?

### #2 NickDMax Reputation: 2255
• Posts: 9,245
• Joined: 18-February 07

## Re: Python program to evaluate a Riemann sum?

Posted 04 September 2007 - 09:13 PM

Your teacher has actually asked you to do something a little abstract so you should start by making some decisions.
How many intervals will you use?
Where will you choose your x* from (first point in interval, mid-point, last point (usually the "Riemann sum" refers to a point inside the interval so the mid-point is often easiest)?
Break up the intervals evenly?

Once you have made such choices... choose the points in the interval (a, and then calculate y(xi) for each of these points. If you have made the intervals evenly broken up (so dx = (b - a)/n where n = number of intervals) then you can sum up the areas dx*y(xi).

I am no Python expert, so I would just use simple loops and linear interpolation myself.

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }