How to plot surface on matlab on domain?

49 Views Asked by At

How would I plot the surface S z=(1+x^2)/(1+y^2) over the region |x|+|y|<=2 ?

I've tried numerous things, but I cannot get it so that the surface is constrained to the rhombus/square-shaped region.

1

There are 1 best solutions below

0
On

The NaN values are not normally plotted, thus

x=-2:0.01:2;
y=-2:0.012:2;
[X,Y]=meshgrid(x,y);

Z = (1+X.^2)./(1+Y.^2);

region = abs(X)+abs(Y)<2;

Z(~region) = NaN;
mesh(X,Y,Z);