How to plot a 3D graph?
Afficher commentaires plus anciens
Hi, I'm new to matlab.
I'm trying to plot the 3D graph of this equation
for (-1 <= x <= 1), (-1 <= y <= 1.5), and (1 <= z <= 6) but I get errors:
Error using surf (line 71)
X, Y, Z, and C cannot be complex.
Error in heart (line 8)
surf(X,Y,Z);
Here is my code:
x = linspace(-1,1,20);
y = linspace(-1,1.5,30);
[X,Y] = meshgrid(x,y);
Z = 5 - sqrt(1 - X.^2 - (Y - abs(X)).^2).*cos(30.*(1 - X.^2 - (Y - abs(X)).^2));
surf(X,Y,Z);
zlim([1 6]);
xlim([-1 1]);
ylim([-1 1.5]);
Please help me fix this code, thank you.
Réponse acceptée
Plus de réponses (1)
KSSV
le 2 Juin 2021
Z matrix is complex number. Try plotting real, imag or abs.
surf(X,Y,real(Z)) % real value
surf(X,Y,imag(Z)) % imaginary value
surf(X,Y,abs(Z)) % absolute value
Catégories
En savoir plus sur Surface and Mesh Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
