plotting surface z=x^2+y^2 in Mathematica

771 Views Asked by At

This should be an elementary exercise but I cannot find the solution in any books or notes. Could someone show me how to plot $z=x^2+y^2$ first in Mathematica? By hand?

And, how to outward normal to this surface, say at some point (-1, -2, 5)?

Many thanks!

2

There are 2 best solutions below

1
On

Something like this seems to work:

p1 = Plot3D[x^2 + y^2, {x, -3, 3}, {y, -3, 3},
   BoxRatios -> Automatic, Mesh -> False, 
   PlotStyle -> Opacity[0.4]];
f[x_, y_, z_] := z - x^2 - y^2;
grad[x_, y_, z_] = Grad[f[x, y, z], {x, y, z}];
normal[x_, y_, z_] = 
  Simplify[grad[x, y, z]/Sqrt[grad[x, y, z].grad[x, y, z]]];
MyPoint = {-1, -2, 5};
MyEndPoint = MyPoint + 5*normal[-1, -2, 5];
p2 = Graphics3D[Arrow[{MyPoint, MyEndPoint}]];
Show[p1, p2, ViewPoint -> {2.62, -1.78, 1.17}]

enter image description here

Not sure if you're wanting the arrow to go this way, or the opposite; if you want the opposite, then change

MyEndPoint=MyPoint+5*normal[-1,-2,5]

to

MyEndPoint=MyPoint-5*normal[-1,-2,5]

Might need to fiddle with viewpoint to get a good picture.

2
On

You can also plot this surface with the commands

f = z - x^2 - y^2; gr1 = ContourPlot3D[f == 0, {x, -4, 4}, {y, -4, 4}, {z, 0, 8}, Mesh -> None, ContourStyle -> Directive[Green, Opacity[0.5], Specularity[White, 30]]]; p0 = {-1, -2, 5}; p = {x, y, z}; n = Grad[f, p] /. Thread[p -> p0]; gr2 = Graphics3D[{Red, Arrow[{p0, p0 - 0.5 n}]}]; Show[gr1, gr2]

enter image description here

NOTE

The gradient vector was sign changed and scaled for display purposes.