'Plotting a 3d-function fails
I try to plot the function f(x,y)=(100-(x^2*y^2))^0.5 in Matlab using
x = 0:0.1:10;
y = 0:0.1:5;
[X,Y] = meshgrid(x,y)
Z = (100-(X.^2.*Y.^2)).^(0.5)
surf(X,Y,Z)
I managed to do so with the following online-plotter: https://math24.pro and get this result plot
How can I do that in Matlab? Here I get an error which says that Z is complex instead of real. But I don't get why.
Solution 1:[1]
Real-Component of a Matrix
Try taking the real() component of z. The imaginary components are a result of 100-(X.^2.*Y.^2) computing to a negative value at various X, Y values. The exponent 0.5 (square root) of a negative number results in imaginary/complex components causing MATLAB to display an error.
x = 0:0.1:10;
y = 0:0.1:5;
[X,Y] = meshgrid(x,y);
Z = real((100-(X.^2.*Y.^2)).^(0.5));
surf(X,Y,Z);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | designmycompass |

