extrema of functions of two variables An experiment was conducted by a group of students to analyze the performance of a subject if stimulus A and stimulus B are used. It was found that if $x$ units of stimulus A and $y$ units of stimulus B were applied, the performance  of the subject can be measured using the following equation:   
$$
f(x,y) = C + xy e^{1-x^2 -y^2}
$$
where C is a positive constant. How many units of each stimuli yield the maximum performance?
 A: Hint
First look for critical points, i.e. points $(x,y)$ for which both partial derivatives, with respect to $x$ and $y$, are equal to $0$:
$$\left\{ \begin{array}{l}
f_x = 0 \\
f_y = 0
\end{array}\right. \Leftrightarrow \ldots$$
A: Since you haven't mentioned it, I am assuming that stimuli A and B both take values in ${\rm I\!R}$.
Let's compute the gradient of the function we want to maximize:
$$
\nabla f (x, y) = \begin{pmatrix}
\frac{\partial f}{\partial x} (x, y)
\\
\frac{\partial f}{\partial y} (x, y)
\end{pmatrix}
= \begin{pmatrix}
(1-2x^2)ye^{1-x^2-y^2}
\\
(1-2y^2)xe^{1-x^2-y^2}
\end{pmatrix}
$$
We need to find critical points, i.e. points where the gradient is equal to the zero vector. In this case:
$$
1-2x^2 = 0 \implies x^2 = \frac{1}{2} \implies x = \pm \frac{\sqrt{2}}{2}
$$
$$
1-2y^2 = 0 \implies y^2 = \frac{1}{2} \implies y = \pm \frac{\sqrt{2}}{2}
$$
So we have four critical points:
$(\frac{\sqrt{2}}{2}, \frac{\sqrt{2}}{2})$,
$(-\frac{\sqrt{2}}{2}, \frac{\sqrt{2}}{2})$,
$(\frac{\sqrt{2}}{2}, -\frac{\sqrt{2}}{2})$ and
$(-\frac{\sqrt{2}}{2}, -\frac{\sqrt{2}}{2})$. Out of these, we need to identify which are the maxima (if any), so we compute the Hessian matrix:
$$
H(f(x, y)) = \begin{pmatrix}
\frac{\partial^2 f}{\partial x ^2} (x, y)
&
\frac{\partial^2 f}{\partial x \partial y} (x, y)
\\
\frac{\partial^2 f}{\partial y \partial x} (x, y)
&
\frac{\partial^2 f}{\partial y ^2} (x, y)
\end{pmatrix}
= \begin{pmatrix}
(4x^2-6)xye^{1-x^2-y^2}
&
(4x^2y^2-2x^2-2y^2+1)e^{1-x^2-y^2}
\\
(4x^2y^2-2x^2-2y^2+1)e^{1-x^2-y^2}
&
(4y^2-6)xye^{1-x^2-y^2}
\end{pmatrix}
$$
Note that for $x = \pm \frac{\sqrt{2}}{2}$ and $y = \pm \frac{\sqrt{2}}{2}$:
$$
x^2 = y^2 = \frac{1}{2}
$$
$$
e^{1-x^2-y^2} = e^{1-\frac{1}{2}-\frac{1}{2}} = 1
$$
Therefore, only for working with these four points, the Hessian matrix can be reduced to the following:
$$
H(f(x, y)) = \begin{pmatrix}
-4xy & 0
\\
0 & -4xy
\end{pmatrix}
$$
and the determinant is:
$$
det(H(f(x, y))) = 16x^2y^2
$$
which means that all of these four points are extrema (not saddle points), and only those which satisfy $-4xy < 0$ are maxima. This last condition is satisfied only when $x$ and $y$ have the same sign.
Therefore, our function is maximized for $(x, y) = (-\frac{\sqrt{2}}{2}, -\frac{\sqrt{2}}{2})$ and $(x, y) = (\frac{\sqrt{2}}{2}, \frac{\sqrt{2}}{2})$.
Plotting the function, we can see the two maxima:

Note that in this case, I plotted the function for $C = 1$, but the value of $C$ does not affect the result in any way as its effect can be seen as a simple displacement of the image of the function in the codomain.
