"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!
Python program to evaluate a Riemann sum?
using python to evaluate a Riemann sum for the function f(x) = x^3
Page 1 of 11 Replies  7730 Views  Last Post: 04 September 2007  09:13 PM
Replies To: Python program to evaluate a Riemann sum?
#2
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, midpoint, last point (usually the "Riemann sum" refers to a point inside the interval so the midpoint 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.
How many intervals will you use?
Where will you choose your x* from (first point in interval, midpoint, last point (usually the "Riemann sum" refers to a point inside the interval so the midpoint 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
