I'm trying to use matlab to create a surface plot of a function that has a limited domain [it's a square root, and the argument goes negative].
x = [-2:0.02:4]
y = [-6:0.1:6]
[X,Y] = meshgrid(x,y)
If I do
surf(X,Y,sqrt(9-(X-1).*(X-1)-Y.*Y/4))
I get an error message because the function is imaginary outside of an ellipse. So I could do
surf(X,Y,real(sqrt(9-(X-1).*(X-1)-Y.*Y/4)))
But then it's 0 outside of the domain. Really I'd like it to just not plot anything at all.
The only idea I have is to modify Y so that for each X, it's limited to the values where the function is defined. But I'd really like a way to say 'just don't plot those parts' so that I don't have to calculate the domain each time.

