Matlab: How to Exclude Zero from Domain?

741 Views Asked by At

I want to plot the wireframe surface of $f(x,y)=\frac{x^2-y^2}{x^2+y^2}$ in Matlab. The code I typed is as follows.

x=-0.1:.001:0.1;
y=-0.1:.001:0.1;
[X,Y]= meshgrid(x,y);
Z=((X.^2)-(Y.^2))/((X.^2)+(Y.^2));
mesh(Z)

However, an empty graph appears, and a line says:

Warning: Matrix is singular to working precision.

I know this happens because the graph is not defined at $x=0$, $y=0$. Is there any way that I can change the domain of $x$ and $y$ so that it excludes $0$?

I did plot the solid surface with the following code, which works.

clear
syms x y
ezsurf(((x.^2)-(y.^2))/((x.^2)+(y.^2)))

Thank you for your time.

1

There are 1 best solutions below

3
On
x=-0.1:.001:0.1;
y=-0.1:.001:0.1;

% Add these lines
x = x(x~=0);
y = y(y~=0);

[X,Y]= meshgrid(x,y);
Z=((X.^2)-(Y.^2))/((X.^2)+(Y.^2));
mesh(Z)