MATLAB: Matrix is singular to working precision.

3derrorfunctiongraphicsmatlab functionmeshmeshgrid

Hi
I entered some code to produce to 3d graphs side by side.
When running, the graphs are shown with one of them not having anything on them. "Matrix is singular to working precision." is shown in the command window. If anyone could help with this problem, this is my code.
Thanks
x = -10:0.5:10;
y = -10:0.5:10;
[xx,yy] = meshgrid(x,y);
subplot(1,2,1)
zz = xx.^2 - yy.^2;
mesh(xx,yy,zz);
subplot(1,2,2)
zz = (xx * yy)*(xx.^2 - yy.^2 / xx.^2 + yy.^2);
mesh(xx,yy,zz);

Best Answer

The matrix xx.^2 is indeed singular by its very nature, since its rows are all alike. When you write yy.^2 / xx.^2 you are asking for the inverse of xx.^2, and hence get the error message. I believe you meant to have a dot in the division rather than matrix division, and perhaps a dot in the multiplication:
zz = (xx .* yy) .* (xx.^2 - yy.^2 ./ xx.^2 + yy.^2);
or perhaps you meant this:
zz = (xx .* yy) .* (xx.^2 - yy.^2) ./ (xx.^2 + yy.^2);