1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica Help with Right and Left Riemann Sums

  1. Jan 28, 2009 #1
    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. jcsd
  3. Jan 28, 2009 #2

    CompuChip

    User Avatar
    Science Advisor
    Homework Helper

    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?
     
  4. Jan 28, 2009 #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.
     
  5. Jan 28, 2009 #4

    CompuChip

    User Avatar
    Science Advisor
    Homework Helper

    OK maybe you should start by describing what should change in the graph. Try to be precise.
     
  6. Jan 28, 2009 #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.
     
  7. Jan 29, 2009 #6

    CompuChip

    User Avatar
    Science Advisor
    Homework Helper

    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?
     
  8. Jan 29, 2009 #7
    It would be instead of i+ just start at 0
     
  9. Jan 29, 2009 #8

    CompuChip

    User Avatar
    Science Advisor
    Homework Helper

    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?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Mathematica Help with Right and Left Riemann Sums
  1. Riemann sum help (Replies: 1)

  2. Riemann Sums - Help! (Replies: 0)

Loading...