[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Making a 3D graph with highlighted area
From: |
Ben Abbott |
Subject: |
Re: Making a 3D graph with highlighted area |
Date: |
Thu, 24 Apr 2014 20:33:28 -0400 |
On Apr 24, 2014, at 3:18 AM, Alice Ander <address@hidden> wrote:
> I’m trying to make a 3D graph of y=1+x^3, highlighting the
> area under the function curve where x is between 1 and 2.
>
> Is this possible?
>
> This is a 2D graph I created in octave with a highlighted area:
> <image[2][1].png>
>
> This are the my octave commands:
> # assign values to vector x from -5 to 5 step by .1
> x=-5:0.1:5;
> # calculate values of y
> y=1.+x.^3;
> #make 2d plot
> plot(x,y);
> # put formula in the graph title
> title('y=1+x^3');
> #redefine lo and hi points on the plot
> axis([-10 10 -10 10 0 1]);
> ### draw the filler space under the graph
> # keep old graph in place while drawing new graph
> hold on;
> # define fill area of x from 1 to 2
> x=1:0.1:2;
> #recalc given new x values
> y=1.+x.^3;
> # fill the selected area
> area(x,y);
> grid();
>
> My problem -- I have not been able to make the 2D graph into a 3D graph.
>
> This is a graph I made in 3D Grapher without the highlighted area.
> I would like to make a similar graph in octave, if possible, including
> a highlighted area under the graph where x is between 1 and 2.
>
> <image[8][1].png>
>
> Is this possible? Also, if this is really involved just let me know and
> I’ll come back to it after I’ve got more octave experience. Of course I’m
> hoping
> this might not be too involved.
>
> Thank you for any help you might be able to give.
You'll need to use either surf() or mesh() to get the same look. Below is a
simple example, without the high-lighted area.
x=-5:0.1:5;
y=1.+x.^3;
z = -2:2;
x = x(:);
y = y(:);
z = repmat (z, size (x))
x = repmat (x, [1, 5]);
y = repmat (y, [1, 5]);
surf (x, z, y)
Ben