Processing math: 100%
Ask Your Question
1

3D Graph with Domain contours

asked 6 years ago

ortollj gravatar image

updated 6 years ago

Hi

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

f_{X,Y}(x,y) = x2,if 1x2 and 0yx, 0,otherwise. .

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()
Preview: (hide)

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 ( 6 years ago )

1 Answer

Sort by » oldest newest most voted
4

answered 6 years ago

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 x2 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')
Preview: (hide)
link

Comments

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

ortollj gravatar imageortollj ( 6 years ago )

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: 6 years ago

Seen: 824 times

Last updated: Oct 19 '18