Mathematica Help with Right and Left Riemann Sums

Click For Summary

Homework Help Overview

The discussion revolves around converting a left Riemann sum program module in Mathematica into a right Riemann sum. Participants are exploring the necessary adjustments to the code and the conceptual differences between left and right Riemann sums.

Discussion Character

  • Exploratory, Conceptual clarification, Mathematical reasoning

Approaches and Questions Raised

  • Participants discuss the structure of the existing left Riemann sum code and consider how to modify it for the right Riemann sum. Questions arise regarding the specific changes needed in the table of line segments and the height of the segments.

Discussion Status

Several participants are actively engaging with the problem, suggesting potential changes to the code and questioning how the graphical representation should differ for the right Riemann sum. There is a focus on understanding the implications of these changes, although no consensus has been reached on the exact implementation.

Contextual Notes

Participants express urgency due to a deadline, indicating that the problem is part of a homework assignment. There is mention of specific constraints regarding the graphing of the Riemann sums and the need for clarity in the code adjustments.

jcharles513
Messages
21
Reaction score
0

Homework Statement


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]]]

Homework Equations


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



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.
 
Physics news on Phys.org
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?
 
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.
 
OK maybe you should start by describing what should change in the graph. Try to be precise.
 
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.
 
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?
 
It would be instead of i+ just start at 0
 
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?
 

Similar threads

  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 26 ·
Replies
26
Views
3K
  • · Replies 21 ·
Replies
21
Views
3K