Mathematica Help with Right and Left Riemann Sums

Click For Summary
SUMMARY

The discussion focuses on converting a left Riemann sum program in Mathematica to a right Riemann sum. The original code uses the function leftRiemannGraph to create a graphical representation of the left Riemann sum. Key modifications include changing the line expr[3]=Drop[expr[2],-2]; to expr[3]=Drop[expr[2],2]; to correctly drop the first two elements. The main challenge lies in adjusting the height of the segments to reflect the right endpoint of each partition, requiring a shift in the indexing of the function evaluations.

PREREQUISITES
  • Understanding of Riemann sums (left and right)
  • Familiarity with Mathematica programming
  • Knowledge of function plotting in Mathematica
  • Basic calculus concepts related to integration and area under curves
NEXT STEPS
  • Learn how to implement right Riemann sums in Mathematica
  • Explore the use of ListLinePlot for graphical representation of data
  • Study the differences between left and right Riemann sums in calculus
  • Investigate the implications of partitioning in numerical integration
USEFUL FOR

Students and educators in mathematics, particularly those studying calculus and numerical methods, as well as Mathematica users looking to enhance their programming skills for graphical data representation.

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