Mathematica Help with Right and Left Riemann Sums

1. Jan 28, 2009

jcharles513

1. The problem statement, all variables and given/known data
I am given a left riemann sum program module in Mathematica and need to convert it into the right riemann sum. The program takes values for x and f/x and the partition and graphs on a certain interval provided.

leftRiemannGraph[f_, a_, b_, n_] := Module[{expr},
expr[1] =
Table[{{x, f[x]}, {x + (b - a)/n, f[x]}}, {x, a, b, (b - a)/n}];
expr[2] = Flatten[expr[1], 1];
expr[3] = Drop[expr[2], -2];
plt[1] = ListLinePlot[expr[3], Filling -> Axis];
plt[2] = Plot[f[x], {x, a, b}];
Show[plt[1], plt[2]]]

2. Relevant equations
Knowledge about right and left riemann sums is necessary. Also partitions of the rectangles is (b-a/n).

3. The attempt at a solution
I attempted this problem for several hours. The only thing I really figured out is that expr[3]=Drop[expr[2],-2]; needs to be changed to expr[3]=Drop[expr[2],2]; to drop the first 2 not the last two. Also I know that the 3rd line is the one that needs changed. I'm just not sure what needs to be changed on it, in order to graph the right riemann sum. This has been racking my brain for the last week. Please help.

2. Jan 28, 2009

CompuChip

The part where expr[1] is set creates a table of line segments. Letting x run through $x_i = a + i \times (b - a)/n$, a line segment is created from $(x_i, f(x_i))$ to $(x_{i+1}, f(x_i))$. How would this change for a right Riemann sum?

3. Jan 28, 2009

jcharles513

It would be {o, f[x]} for the beginning I'm just not sure how to get this to work I tried taking out the x but that wasn't right.

4. Jan 28, 2009

CompuChip

OK maybe you should start by describing what should change in the graph. Try to be precise.

5. Jan 28, 2009

jcharles513

I know what should change the right uppermost point of the bar should be on the line and an overestimate should occur. This would cause a shift leftward in the graph. I'm just not sure how to implement it and its stressing me out, because this is due tomorrow and I can't figure it out.

6. Jan 29, 2009

CompuChip

So let's consider the i'th segment, which runs from $a + i * (b - a) / n$ to $a + (i + 1) * (b - a) / n$.
In a left (or lower) Riemann sum, the segment would be at height f(a + i (b - a) / n). So if we let x run through (a, a + (b - a)/n, a + 2(b - a)/n, ..., a + (n - 1)(b - a) / n) then the segment would be at a height f(x).
Now where would it be for an upper Riemann sum?

7. Jan 29, 2009

jcharles513

It would be instead of i+ just start at 0

8. Jan 29, 2009

CompuChip

Huh? What do you mean?

I am starting at x = a, then each time adding (b - a) / n so in the n'th step I will be at x = b.

So suppose I am at some x and have to draw a line segment at height y which extends to the right for one step (so for length (b - a) / n, i.e. from x to x + (b - a) / n). Then what would y have to be for left and right Riemann sums?