Mathematica Help with Right and Left Riemann Sums

In summary: For a left Riemann sum, y would have to be (b - a)/n. For a right Riemann sum, y would have to be 2(b - a)/n.
  • #1
jcharles513
22
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
  • #2
The part where expr[1] is set creates a table of line segments. Letting x run through [itex]x_i = a + i \times (b - a)/n[/itex], a line segment is created from [itex](x_i, f(x_i))[/itex] to [itex](x_{i+1}, f(x_i))[/itex]. How would this change for a right Riemann sum?
 
  • #3
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
OK maybe you should start by describing what should change in the graph. Try to be precise.
 
  • #5
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
So let's consider the i'th segment, which runs from [itex]a + i * (b - a) / n[/itex] to [itex]a + (i + 1) * (b - a) / n[/itex].
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
It would be instead of i+ just start at 0
 
  • #8
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?
 

Related to Mathematica Help with Right and Left Riemann Sums

1. What is the purpose of using Riemann Sums in Mathematica?

The purpose of using Riemann Sums in Mathematica is to approximate the area under a curve by dividing it into smaller rectangles and summing up their areas. This can help in visualizing and understanding the behavior of a function and can also be used to solve real-life problems in fields such as physics, economics, and engineering.

2. How can I calculate the Riemann Sum for a specific function in Mathematica?

To calculate the Riemann Sum for a specific function in Mathematica, you can use the Sum function with the Limit option. First, define the function using Function and then use the Sum function with the appropriate limits and number of subintervals. For example, Sum[Function[{x}, x^2], {x, a, b}, Limit -> n] will calculate the Riemann Sum for x^2 from a to b with n subintervals.

3. Can I change the placement of the rectangles in a Riemann Sum in Mathematica?

Yes, you can change the placement of the rectangles in a Riemann Sum in Mathematica by using the Partition function to divide the interval into unequal subintervals. This will result in a non-uniform partition and the placement of the rectangles in the Riemann Sum will be based on the values of the function at the endpoints of each subinterval.

4. Is there a way to visualize Riemann Sums in Mathematica?

Yes, you can visualize Riemann Sums in Mathematica by using the RegionPlot or Plot functions. These functions can plot the rectangles used in the Riemann Sum and shade the area under the curve to provide a visual representation of the approximation. You can also adjust the number of subintervals to see how the approximation changes.

5. Can Riemann Sums be used to find the exact value of the area under a curve?

No, Riemann Sums provide an approximation of the area under a curve. The accuracy of the approximation depends on the number of subintervals used. However, as the number of subintervals approaches infinity, the Riemann Sum approaches the exact value of the area. To find the exact value, you can use the Integrate function in Mathematica.

Similar threads

  • Calculus and Beyond Homework Help
Replies
14
Views
534
  • Calculus and Beyond Homework Help
Replies
2
Views
672
  • Calculus and Beyond Homework Help
Replies
6
Views
1K
  • Calculus and Beyond Homework Help
Replies
4
Views
721
  • Calculus and Beyond Homework Help
Replies
12
Views
1K
  • Calculus and Beyond Homework Help
Replies
5
Views
2K
Replies
2
Views
1K
  • Topology and Analysis
Replies
14
Views
2K
  • Calculus and Beyond Homework Help
Replies
4
Views
2K
  • Calculus and Beyond Homework Help
Replies
4
Views
531
Back
Top