1
votes

I want to plot a surface in MATLAB using surf. I have this equation: x = y^2 +4z^2.

What I am doing is the following:

[x,y] = meshgrid(-4:.1:4, -4:.1:4);

z = sqrt((x - y.^2)./4);              % Basically I'm just clearing for z

surf(x,y,z)

But with this I am getting the error: Error using surf X,Y,Z and C cannot be complex. I know there is a complex number because of the values that x and y have, plus the square root. Is there another way to plot a surface in MATLAB? because I really don't know what to do, and my skills are very basics.

1
If you're just interested in the real part of z, you can write z = real(sqrt(...)). The following surf command then will execute without problems.HansHirse

1 Answers

0
votes

Why do you feel that you need to grid x and y, and not use the form of the original equation itself?

This seems to work perfectly fine

[y,z] = meshgrid(-4:.1:4, -4:.1:4);
x = y.^2 + 4*z.^2;
surf(x,y,z)

to produce

enter image description here