Ask Your Question
1

3D Graph with Domain contours

asked 2018-10-19 12:40:34 +0100

ortollj gravatar image

updated 2018-10-19 14:15:42 +0100

Hi

I would like to visualize in 3D the function below:

f_{X,Y}(x,y) = \begin{array}{ll} x^2, & \mbox{if $1 \leq x \leq 2$ and $0 \leq y \leq x$}, \ 0, & \mbox{otherwise}. \end{array} .

I execute this code below, but it is not displaying good (what is wrong with the code ?), and how to display the axes labels ?

var("x y z")
region = implicit_plot3d(z, (x, -3, 3), (y, -3, 3), (z, -3, 3) , plot_points=100, region=lambda x,y,z: x^2  and 1<x and x<2 and y<x and y>0,axes=True)
region.show()
edit retag flag offensive close merge delete

Comments

I just edited the code, I just realized that I forgot y> 0 !. I added it now. it seems that only the contour of the x,y domain is displayed, but not the z contour.

ortollj gravatar imageortollj ( 2018-10-19 14:15:08 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
4

answered 2018-10-19 14:12:05 +0100

slelievre gravatar image

Here are two ways to get the plot you want, one with vertical walls, one without.

If you don't mind the walls, define a function that is $x^2$ where you want and $0$ elsewhere. Then plot it.

sage: f = lambda x, y: x^2 if 1 <= x <= 2 and 0 <= y <= x else 0
sage: p = plot3d(f, (-3, 3), (-3, 3), plot_points=100)
sage: p.show(aspect_ratio=1, viewer='threejs')

If you prefer without walls, use the fact that Sage's 3D plotting functions plot nothing if they get something that evaluates to "not a number".

sage: nan = float(NaN)
sage: f = lambda x, y: x^2 if 1 <= x <= 2 and 0 <= y <= x else nan
sage: g = lambda x, y: nan if 1 <= x <= 2 and 0 <= y <= x else 0
sage: qf = plot3d(f, (-3, 3), (-3, 3), plot_points=100)
sage: qg = plot3d(g, (-3, 3), (-3, 3), plot_points=100)
sage: q = qf+qg
sage: q.show(aspect_ratio=1, viewer='threejs')
edit flag offensive delete link more

Comments

thank you very much slelievre, the rendering of your second code is really superb !!

ortollj gravatar imageortollj ( 2018-10-19 14:27:27 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-10-19 12:40:34 +0100

Seen: 650 times

Last updated: Oct 19 '18