Plotting function with 2 variables within constraints I have a function of two variables:

With some values

Now I have to plot this, so that tha values of U are between -5 and 0. How do I do this? (Note: It's not the values of x and y that need to be between -5 and 0.)
Thanks!
 A: A nice smooth surface can be obtained simply by using the plot3d command along with your operator U as given.
restart:

U:=(x,y)->-M1/sqrt(x^2+y^2)-M2/sqrt((x-a)^2+y^2)-.5*omega^2*((x-M2*a/(M1+M2))^2+y^2):

M1:=1: M2:=1: a:=5: omega:=0.2:

The view option will restrict the z-range displayed. So it is easy to constrain it to z=-5..0.
plot3d(U, -20..20, -20..20, view=-5..0, labels=[x,y,z]);


But you could also compute the x- and y-ranges for the plot3d call so that they are tightly constrained by the lower value of z=-5. (There are various ways to compute those tight bounds.)
xlo:=Optimization:-Minimize(x,{U(x,y)>=-5,U(x,y)<=0,x<=-10,x>=-20},y=-10..10)[1];

                     xlo := -13.1019759104502107

xhi:=Optimization:-Maximize(x,{U(x,y)>=-5,U(x,y)<=0,x>=10,x<=20},y=-10..10)[1];

                     xhi := 18.1019759104502107

ylo:=Optimization:-Minimize(y,{U(x,y)>=-5,U(x,y)<=0,y<=-10,y>=-20},x=-10..10)[1];

                     ylo := -15.6100765315323216

yhi:=Optimization:-Maximize(y,{U(x,y)>=-5,U(x,y)<=0,y>=10,y<=20},x=-10..10)[1];

                     yhi := 15.6100765315323216

plot3d(U, xlo..xhi, ylo..yhi, view=-5..0,labels=[x,y,z]);


A: Here are the required codes in Maple:
 [> f := (m1, m2, w, a)-> -m1/sqrt(x^2+y^2)-m2/sqrt((x-a)^2+y^2)-.5*w^2*((x-m2*a/(m1+m2))^2+y^2):
 [> g:=(x,y)-> f(1,2,0.2,5):
    with(plots): implicitplot3d(z=g(x,y),x=-10..10,y=-10..10,z=-5..0);


