Python program to evaluate a Riemann sum?

using python to evaluate a Riemann sum for the function f(x) = x^3

Page 1 of 1

1 Replies - 6449 Views - Last Post: 04 September 2007 - 09:13 PM Rate Topic: -----

#1 FarmGirl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • 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, B) 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1