With $x_1^2+3x_2^2+2x_1x_2=32$, find max value of $|x_1-x_2|$ 
With $x_1^2+3x_2^2+2x_1x_2=32$, find the maximum of $|x_1-x_2|$.


I have tried with AM-GM, but can't solve it. With $d = |x_1-x_2|$ and $d^2 = 2x_1^2 + 4x_2^2 - 32$, then I wonder how to do next.
Thank a lot for helping!

 A: $(x_1+x_2)^2+2(x_2)^2=32.$
We are finding the value of $\max(|x_1-x_2|)=\max(|x_1+x_2-2x_2|)$.
Let $x_1+x_2=X, x_2=Y.$
Then, we can rewrite the problem:

If $X^2+2Y^2=32$, Find the maximum of $|X-2Y|$.

Let $\sin(A)=\dfrac{X}{4\sqrt{2}}.$
Then, $\cos(A)=\dfrac{Y}{4}.$
So, the problem changes:

Find the maximum of $|4\sqrt{2}\sin{A}-8\cos{A}|.$

Let $\sin(B)=-\dfrac{\sqrt{2}}{\sqrt{3}}, \cos(B)=\dfrac{1}{\sqrt{3}}$.
Then, $|4\sqrt{2}\sin{A}-8\cos{A}| = |4\sqrt{6}(\cos{B}\sin{A}+\sin{B}\cos{A})| =|4\sqrt{6}\sin(A+B)| \leq 4\sqrt{6}.$
So, the answer will be $4\sqrt{6}.$
A: CS inequality is useful in bounding linear terms with quadratic ones, like so:
$$32 \cdot 3 = \left((x_1+x_2)^2+x_2^2+x_2^2 \right)\cdot (1+1+1)\geqslant (x_1+x_2-x_2-x_2)^2$$
A: \begin{align}
|x_1-x_2|^2 
&= x_1^2 - 2x_1 x_2 + x_2^2 \\
&= 3(x_1^2 + 2x_1 x_2 + 3 x_2^2) - 2 (x_1^2 + 4 x_1 x_2 + 4 x_2^2) \\
&= 96 - 2(x_1+2x_2)^2 \\
&\le 96,
\end{align}
with equality if and only if $x_1+2x_2=0$, yielding
$(x_1,x_2)=(\pm 8\sqrt{2/3}, \mp 4\sqrt{2/3})$.

A: We have to find the maximum of the function
$$\mathbb{R}^2 \backslash \{0,0\} \ni x \mapsto \frac{\langle B x, x\rangle}{\langle A x, x \rangle}$$
for positive definite  $A=\left(\begin{matrix} 1&1\\1&3\end{matrix}\right)$ and $B= \left(\begin{matrix} 1&-1\\-1&1\end{matrix}\right)$
The maximum equals the largest root of the polynomial
$$\det (\lambda A - B) = 2\lambda(\lambda-3)$$
A: Let $\,d = |x_1-x_2|\,$, then $\,x_2 = x_1 \pm d\,$ and writing the constraint in terms of $\,x_1,d\,$ gives:
$$
0 = x_1^2 + 3(x_1 \pm d)^2 + 2x_1(x_1 \pm d)-32 ​= 6 x_1^2 \pm 8 d x_1 + 3d^2 - 32
$$
For the quadratic in $\,x_1\,$ to have real roots, the reduced discriminant must be non-nonegative:
$$
0 \le \frac{1}{4}\Delta = (\pm 4d)^2 - 6 \cdot (3d^2 - 32) = -2d^2 + 192 \quad\iff\quad d^2 \le 96
$$
Therefore, the maximum is $\,d = \sqrt{96} = 4 \sqrt{6}\,$.
A: Generalizing, we have an instance of the following equality-constrained QCQP
$$ \begin{array}{ll} \underset{{\bf x} \in \Bbb R^n}{\text{maximize}} & {\bf x}^\top {\bf P} \, {\bf x}\\ \text{subject to} & {\bf x}^\top {\bf Q} \, {\bf x} = r \end{array} $$
We define the Lagrangian
$$ \mathcal L ({\bf x}, \mu) := {\bf x}^\top {\bf P} \, {\bf x} - \mu \left( {\bf x}^\top {\bf Q} \, {\bf x} - r \right) $$
Taking the gradient of $\mathcal L$ with respect to $\bf x$ and the partial derivative of $\mathcal L$ with respect to $\mu$, and finding where they vanish, we obtain
$$ \begin{aligned} \left( {\bf P} - \mu {\bf Q} \right) {\bf x} &= {\bf 0}_n \\  {\bf x}^\top {\bf Q} \, {\bf x} &= r \end{aligned} $$
Since we are not interested in the solution ${\bf x} = {\bf 0}_n$, we impose
$$\det \left( {\bf P} - \mu {\bf Q} \right) = 0$$

Instance of interest
Let $n = 2$ and
$$ {\bf P} = \begin{bmatrix} 1 & -1 \\ -1 & 1 \end{bmatrix}, \qquad {\bf Q} = \begin{bmatrix} 1 & 1 \\ 1 & 3 \end{bmatrix}, \qquad r = 32$$
For which $\det \left( {\bf P} - \mu {\bf Q} \right) = \cdots = 2 \mu ( \mu - 3 )$. For root $\mu = 3$, we have the generalized eigenvector ${\bf x} = \gamma \, {\bf v}$, where ${\bf v} := \begin{bmatrix} 2 & -1 \end{bmatrix}^\top$. Intersecting the line spanned by $\bf v$ with the given ellipse, we obtain the quadratic equation
$$ \gamma^2 = \frac{r}{{\bf v}^\top {\bf Q} \, {\bf v}} = \frac{32}{3} = 4^2 \cdot \frac{2}{3} $$
Hence, the maximum is attained at
$$ {\bf x} = \color{blue}{\pm 4 \sqrt{\frac23}  \begin{bmatrix} 2 \\ -1 \end{bmatrix}} $$

optimization qcqp lagrange-multiplier
