Search code examples
maple

Shade Bounded Region along y-axis


I plotted a line but want to shade the area between 2 and 4 along the y axis to illustrate area under the curve but cannot figure out how to do that, can anyone help? This is the code, which is rather simple

>y:=(2*x);

>plot(y,x=0..3);

Unshaded plot


Solution

  • I find it difficult to understand just what region you have in mind.

    Is it this?

    restart;
    
    y := 2*x:
    
    plots:-display(
      plot(2*x, x=0..3),
      plots:-inequal([Y>=y, Y>=2, Y<=4], x=0..3, Y=0..6,
                     'nolines', 'color'="Burgundy")
    );
    

    enter image description here

    Of course you could omit the curve (line) y=2*x by removing the call to plot above.

    If you have some other region in mind then you should be able to adjust the call to plots:-inequal accordingly.

    There are other ways to accomplish such things, such as calling plot with its filled option. You can also use plottools:-reflect, or use the parametric calling sequence of plot, to flip x and y axes.

    I figure that you might be wanting to avoid having to "solve for x", to get x values corresponding to y=2 and y=4 (even though in this example of y=2*x you can do that in your head).

    These are reasons why I think you'd likley find it easiest to just use plots:-inequal.

    [edit: for followup comment about 8 rectangles]

    First, a slightly different example, hopefully for more clarity.

    restart;
    
    x:=arcsin(y/6):
    
    P := plots:-display(
      plot(x, y=2..5),
      plots:-inequal([X<=x], y=2..5, X=0..1.2,
                     'nolines', 'color'=pink)
    ):
    
    plots:-display(
      plot(2, color=black, linestyle=dot),
      plot(5, color=black, linestyle=dot),
      plot([x, y, y=0..6]),
      plottools:-transform((x,y)->[y,x])(P),
      view=[0..1.2,0..6],
      labels=["x","y"],
      size=[500,300]
    );
    

    enter image description here

    The upper of lower sums (using rectangles) can be visualized using the RiemannSum command from the Student:-Calculus1 package. (Or you could use the seq command and construct them all by formulas for their corners -- but that just seems like a lot of awkward bookkeeping.)

    You can of course remove any of the parts passed below to the plots:-display command.

    restart;
    
    with(Student:-Calculus1):
    
    x:=arcsin(y/6):
    
    P:=RiemannSum(x, y=2..5, method = upper, output = plot,
                  partition=8,
                  boxoptions=[filled=[color=pink,transparency=.5]],
                  caption=""):
    
    rP:=plottools:-transform((x,y)->[y,x])(P):
    
    plots:-display(
      plot(2, color=black, linestyle=dot),
      plot(5, color=black, linestyle=dot),
      plot([x, y, y=0..6]),
      rP,
      view=[0..1.2,0..6],
      labels=["x","y"],
      size=[500,300]
    );
    

    enter image description here Or,

    restart;
    
    with(Student:-Calculus1):
    
    x:=arcsin(y/6):
    
    P:=RiemannSum(x, y=2..5, method = lower, output = plot,
                  partition=8,
                  boxoptions=[filled=[color=pink,transparency=.5]],
                  caption=""):
    
    rP:=plottools:-transform((x,y)->[y,x])(P):
    
    plots:-display(
      plot(2, color=black, linestyle=dot),
      plot(5, color=black, linestyle=dot),
      plot([x, y, y=0..6]),
      rP,
      view=[0..1.2,0..6],
      labels=["x","y"],
      size=[500,300]
    );
    

    enter image description here

    All these examples would be a little less complicated if you wanted the area between the curve and the x-axis instead.