Building a certain kind of a multivariable function-max/min I want to build a function $f(x,y)$ that has the following properties:


*

*$f(x,y)$ is a polynomial of degree 2.

*$\nabla f(3,-2)\neq 0 $ .

*The maximum of $f$ under the constraint $x+y=1$ is in the point $(3,-2)$

*$f$ is not constant on the line $ x+y=1$ . 
Will someone help me understand how to take care of parts 3 and 4? Is there any short and elegant solution to this?
Thanks in advance
 A: I think the easiest way to approach this problem is to solve a related problem where the constraints are easier. In particular, let's solve the problem of finding a function $g(x,y)$ which satisfies the following constraints:


*

*$g(x,y)$ is a second order polynomial of degree 2.

*$(\nabla g)(0,0) \neq 0$

*The maximum of $g$ under the constraint $y=0$ is at the point $\langle 0,0\rangle$.

*$g$ is not constant on the line $y = 0$.


Note that if we can solve this problem, all we have to do is translate the function so that $\langle 0,0\rangle$ moves to $\langle 3, -2\rangle$, then rotate it so that the line $y=0$ becomes the line $x+y=1$.

Consider the candidate function $$g(x,y) = -x^2.$$
If you visualize this function, it's a "parabolic cylinder", made of rows of inverted parabolas. 
I've chosen the function to satisfy the third constraint— it's the easiest function I could think of that has a real maximum.
Note that the restriction of $g(x,y)$ to the line $y=0$ is just the function $g(x,0) = -x^2$. 
This restricted function is not constant, so $g$ satisfies constraint #4. And its maximum evidently occurs at the top of the inverted parabola $-x^2$, where $x=0\; y=0$ so $g$ satisfies constraint #3.
The gradient of $g$ is $(\nabla g) = \langle -2x, 0\rangle$. Unfortunately, this means that $(\nabla g)(0,0) = \langle 0, 0\rangle$, so this function violates constraint #2. But we can modify the function slightly to repair this problem:
$$g_*(x,y) = -x^2 + y$$ 
Geometrically, this is a function which is made of a bunch of inverted parabolas, but the maximum of the parabola increases steadily with $y$.  I added this term so that the restriction of $g(x,y)$ to the line $y=0$ is still just $g_*(x,0) = -x^2$ so the function still satisfies constraints #3 and #4. But now if we take derivatives, we find that
$$(\nabla g_*)(x,y) = \langle -2x + y, 1\rangle$$
which has $(\nabla g)(0,0) = \langle 0, 1\rangle \neq \langle 0,0\rangle$.  The trick was to add on an amount like $y$ so that the partial derivative of $y$ is nonzero when $x=y=0$. (Note that you couldn't have repaired $g$ by adding a term like $y^2$ or $xy$.)
This function now satisfies all four of our constraints!

Now our task is to transform the solution to the easier problem
$$g(x,y) = y - x^2$$
into a solution to our original problem. 
If we're given a point $\langle x,y\rangle$, let's first translate it so that $\langle 3, -2\rangle$  becomes $\langle 0,0\rangle$.
That transformation is 
$$T_1(a,b) = \langle a-3, b+2\rangle$$
As a result of this transformation, the line $x+y=1$ becomes the line $x+y = 0$ (because this transformation sends points of the form $\langle a, 1-a\rangle$ to points of the form $\langle a-3, 3-a\rangle$). 
We would like to apply another transformation so that the line $x+y=0$ instead becomes the line $y=0$. To do so, it's enough to slide it over by an amount $x$: we want to send points of the form $\langle -b, b\rangle$ to points of the form $\langle c, 0\rangle$. The function
$$T_2(a,b) = \langle b, a+b\rangle$$
does exactly that.
By applying these transformations, we solve our original problem— if $g(x,y)$ solves the simpler problem for $\langle 0,0\rangle$ and the line $y=0$, then
$$f(x,y) = g(T_2(T_1(x,y))$$
solves it for the point $\langle 3,-2\rangle$ and the line $x+y=1$.

As a finishing touch, we can find a simplified way of expressing $f$.
$$\begin{align*}
f(x,y) &= g(T_2(T_1(x,y))\\
&= g(T_2(x-3, y+2)) \\
&= g(y+2, x+y-1)\\
&= (x+y-1) - (y+2)^2
\end{align*}$$ 
So one solution to the original problem is:
$$f(x,y) \equiv -(y+2)^2 + x + y - 1$$
