# Is there a flat (projected) version of \addplot3[surf]?

This relates to problem 5.7 from "Riley, Hobson and Bence - Mathematical Methods for Physics and Engineering".

I would like to have a 2D projected (looking down from z) version of the surface shown, keeping the color gradient. I would also like to add a family of parabolic curves (black) for different values of a', as given in the problem. Thanks much.

\documentclass{memoir}

% __________ AMS ________________________
\usepackage{amsmath}
% __________ PGF TikZ ___________________
\usepackage{pgfplots}
% \usepackage{tikz}
\usepackage{tikz-3dplot}

% __________ Differentials _____________________________________________________
% Single
\newcommand{\diff}{d}           % If you want an upright d', change it here
\newcommand{\p}{\partial#1}
% ___________________ Derivatives ______________________________________________
% 1st derivative:
\newcommand{\dod}{\dfrac{\diff{#1}}{\diff{#2}}}  % 'differential over differential'
\newcommand{\pop}{\dfrac{\p#1}{\p#2}}            % 'partial over partial'
\newcommand{\lpop}{\p#1/\p#2}            % A 'layed down' version

\setlength{\parindent}{0cm}
\begin{document}

\textbf{Problem 5.7}\par
\centering
\textbf{The Chain Rule and Stationary Points}\$3mm] \flushleft \fbox{\parbox{4.25in}{ The function G(t) is defined by  G(t) = F(x,y) = x^2 + y^2 + 3xy  where x(t) = at^2 and y(t) = 2at. Use the chain rule to find the values of (x,y) at which G(t) has stationary values as a function of t. Do any of them correspond to the stationary points of F(x,y) as a function of x and y? }} \flushleft \vspace{3mm} \noindent\emph{Solution:}\\[1mm] (To be terse, the derivation has been omitted.)\\[2mm] The Stationary points occur at \lpop Ft = 0, in which case \[ 2a^2t(2t + 1)(t + 4) = 0$
So,
$t\in \{ -4,\ -1/2,\ 0 \}$
This corresponds to the stationary points
$(16a,\ -8a)\ ,\quad (a/4,\ -a)\ ,\quad (0,\ 0)$
To answer the second part of the question, we differentiate $F(x,y)$ with respect to $x$, and $y$, and set these to zero;
$\pop Fx = 2x + 3y = 0$
$\pop Fy = 3x + 2y = 0$
The only solution is $(0,\ 0)$.

\centering
\begin{figure}
\tdplotsetmaincoords{0}{0}
\begin{tikzpicture}[tdplot_main_coords,scale=1.5,rotate=0]
\begin{axis}[domain=-6:6,y domain=-6:6]
\addplot3[surf] {x^2 + y^2 + 3*x*y};
\end{axis}
\end{tikzpicture}
\caption{$z = x^2 + y^2 + 3xy$}
\end{figure}
\flushleft

The other two solutions for $t$, are the stationary points for the parabolic sheet (not shown) $(at^2, 2at, t)$ that intersects with the surface shown. There is also the two-dimensional version realized by looking down from $z$ (i.e. the projection onto the $z$-plane). The blue to orange colors could then be interpreted, for example, as a scalar field for temperature.

\end{document}

• Hi, welcome. Do you mean the output you get if you add view={0}{90} to the axis options? Jan 18, 2019 at 21:11
• Off-topic: $$...$$ is deprecated LaTeX syntax for almost 25 years by now. Use $...$ or an environment dedicated to math display
– user31729
Jan 18, 2019 at 21:32

For the question in the title, you can add view={0}{90} to the axis options.

To plot f(x) = 2*sqrt(a*x), do something like \addplot [black] {2*sqrt(2*x)};, if a=2. You'll need a second plot for the negative part of the parabola.

In the example below I used a loop like this:

  \pgfplotsinvokeforeach{0.25,1}{% values of a, represented by #1 in the loop code
\addplot [black, samples at={0,0.01,...,1,1.6}] {2*sqrt(#1*x)} node[above left] {$a=#1$};
}


The samples at stuff is to make the plot smoother.

Some other changes:

• As Christian mentioned in a comment, don't use $$...$$ for display math, better stick to $...$. (See Why is $…$ preferable to ?.)
• I added \nonzeroparskip to the preamble, removed all \$<some length>], and added some paragraph breaks (empty lines). • Instead of the various \centering ... \flushleft, I added the title inside a center environment, and moved the one \centering to inside the figure environment. • I removed the tikz-3dplot stuff, you're not using it. • I removed the scale=1.5 and added a width=... in the axis options. \documentclass{memoir} % __________ AMS ________________________ \usepackage{amsmath} % __________ PGF TikZ ___________________ \usepackage{pgfplots} % __________ Differentials _____________________________________________________ % Single \newcommand{\diff}{d} % If you want an upright d', change it here \newcommand{\p}{\partial#1} % ___________________ Derivatives ______________________________________________ % 1st derivative: \newcommand{\dod}{\dfrac{\diff{#1}}{\diff{#2}}} % 'differential over differential' \newcommand{\pop}{\dfrac{\p#1}{\p#2}} % 'partial over partial' \newcommand{\lpop}{\p#1/\p#2} % A 'layed down' version \setlength{\parindent}{0pt} \nonzeroparskip % <--- added \begin{document} \textbf{Problem 5.7} \begin{center} \textbf{The Chain Rule and Stationary Points} \end{center} \fbox{\parbox{4.25in}{ The function G(t) is defined by \[ G(t) = F(x,y) = x^2 + y^2 + 3xy$
where $x(t) = at^2$ and $y(t) = 2at$. Use the chain rule to find the values of $(x,y)$ at which $G(t)$ has stationary values as a function of $t$. Do any of them correspond to the stationary points of $F(x,y)$ as a function of $x$ and $y$?
}}

\medskip
\emph{Solution:}

(To be terse, the derivation has been omitted.)

The Stationary points occur at $\lpop Ft = 0$, in which case
$2a^2t(2t + 1)(t + 4) = 0$
So,
$t\in \{ -4,\ -1/2,\ 0 \}$
This corresponds to the stationary points
$(16a,\ -8a)\ ,\quad (a/4,\ -a)\ ,\quad (0,\ 0)$
To answer the second part of the question, we differentiate $F(x,y)$ with respect to $x$, and $y$, and set these to zero;
\begin{align*}
\pop Fx &= 2x + 3y = 0 \\
\pop Fy &= 3x + 2y = 0
\end{align*}
The only solution is $(0,\ 0)$.

\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
width=0.8\linewidth, % <-- instead of scale
domain=-6:6,
y domain=-6:6,
view={0}{90}
]
\addplot3[surf] {x^2 + y^2 + 3*x*y};

\pgfplotsinvokeforeach{0.25,1}{% values of a, represented by #1 in the loop code
\addplot [black, smooth, samples at={0,0.01,...,6}] {2*sqrt(#1*x)} node[above left] {$a=#1$};
\addplot [black, smooth, samples at={0,0.01,...,6}] {-2*sqrt(#1*x)};
}

\end{axis}
\end{tikzpicture}
\caption{$z = x^2 + y^2 + 3xy$}
\end{figure}

The other two solutions for $t$, are the stationary points for the parabolic sheet (not shown) $(at^2, 2at, t)$ that intersects with the surface shown. There is also the two-dimensional version realized by looking down from $z$ (i.e. the projection onto the $z$-plane). The blue to orange colors could then be interpreted, for example, as a scalar field for temperature.

\end{document}

• The curves that I would like to add are of the form x = y^2/(4a), so the curve x = y^2/2, and another x = y^2/4 would be nice. If it's better to have y on the left, then y = \sqrt{x}, and y = 2\sqt{x}, would be ok. Thanks. Jan 19, 2019 at 21:51
• @ScotParker How's that? If you don't want the a=.. in the plot, remove node[above left] {$a=#1$}` in the loop. Jan 19, 2019 at 22:12