Plot f(x,y)=2-x^2-y^2, extrema value

plottikz-3dplot

It's easy show that f(x,y)=2-x^2-y^2 has a maximun value in (x,y)=(0,0), I need a plot show this result. I tried this:

\documentclass{article}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}

  \begin{axis}[domain=-2:2,y domain=-4:4]

    \addplot3[surf] {2-x^2-y^2)};

  \end{axis}

\end{tikzpicture}

\end{document}

But it was horrible and $z$ axis don't show value 2 .
Can you help me?

Best Answer

If you use the correct viewing angle, you can see that the max z is in fact at 2.

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{tikz-3dplot}

\begin{document}

\begin{tikzpicture}
  \begin{axis}[domain=-2:2,y domain=-4:4, view={60}{0},
  extra z ticks={2}]
    \addplot3[surf] {2-x*x-y*y)};
  \end{axis}
\end{tikzpicture}
\end{document}

demo

Related Question