# 3D plot of z = (Matlab)

• Jul 14th 2011, 02:08 AM
SyNtHeSiS
3D plot of z = (Matlab)
I tried drawing an elliptic paraboloid (\$\displaystyle z = x^2 + y^2\$) in Matlab with the following code:

>> [x y] = meshgrid(0 : 5);
>> z = x.^2 + y.^2;
>> surf(z);

However the surface which it produced does not look like an elliptic paraboloid (please refer to the attachment). (Speechless)
• Jul 14th 2011, 04:22 AM
corsica
Re: 3D plot of z = (Matlab)
Quote:

Originally Posted by SyNtHeSiS
However the surface which it produced does not look like an elliptic paraboloid (please refer to the attachment). (Speechless)

It does show an elliptic paraboloid. However you've only plotted a single quadrant of it. Create a meshgrid that spans from -5 to 5 and you'll get the picture that you're looking for.
• Jul 14th 2011, 05:14 AM
SyNtHeSiS
Re: 3D plot of z = x^2 + y^2 (Matlab)
Thanks. Why is it that the elliptic paraboloid in Matlab is different to the standard one? (please refer to the attachments).
• Jul 14th 2011, 11:00 AM
corsica
Re: 3D plot of z = x^2 + y^2 (Matlab)
Quote:

Originally Posted by SyNtHeSiS
Thanks. Why is it that the elliptic paraboloid in Matlab is different to the standard one? (please refer to the attachments).

Could you elaborate? Which difference do you mean?
• Jul 14th 2011, 08:22 PM
CaptainBlack
Re: 3D plot of z = x^2 + y^2 (Matlab)
Quote:

Originally Posted by corsica
Could you elaborate? Which difference do you mean?

I think he is petrubed by the square in the x-y plane that the surface is plotted above giving the plotted part of the surface peaks at the corners rather than the circular form of the top edge of the plotted part of the surface in the second plot.

try something like:

Code:

```>> [r,the]=meshgrid([0:0.1:5],[0:pi/10:2*pi]); >> x=r.*cos(the); >> y=r.*sin(the); >> z=x.^2+y.^2; >> surf(x,y,z);```
CB