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.
z
, you can writez = real(sqrt(...))
. The followingsurf
command then will execute without problems. – HansHirse