How can i graph these two equations in Matlab? Below is the image:
I tried myself to plot them but the error is: "X,Y,Z,C can't be complex"
%Ecuación: x^2 + y^2 - z^2 - 4 = 0
x = 0:2:6;
y = 0:1:6;
[X,Y] = meshgrid(x,y);
Z = sqrt(X.^2 + Y.^2 - 4);
surf(X,Y,Z)
%Second one
x = 0:2:6;
y = 0:1:6;
[X,Y] = meshgrid(x,y);
Z = 1/2*(sqrt(X.^2 + Y.^2 - 8));
surf(X,Y,Z)

답변 (2개)

John D'Errico
John D'Errico 2022년 3월 15일
편집: John D'Errico 2022년 3월 15일

0 개 추천

None of the solutions you tried are correct, because they try to treat these functions as single valued relations. That is not the case. They are better described as implicit functions, so fimplicit3 is correct.
fimplicit3(@(x,y,z) x.^2 + y.^2 - z.^2 - 4,[-4 4 -4 4 -4 4])
axis equal
fimplicit3(@(x,y,z) x.^2 + y + 4*z.^2 - 8,[-4 4 -4 4 -4 4])
Note that the viewpoint is different for the latter plot. It seems sort of a strange perspective as shown in your plot. But this latter figure can be interpreted as a simple paraboloid, though not a rotationally symmetric one, of the form
y = 8 - x^2 - 4*z^2
So still a simple conic form where the axes are rotated from what you might normally expect.

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

릴리스

R2021a

편집:

2022년 3월 15일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by