# 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!

• What are $x_1$ and $x_2$ ? How did you obtain the expression for $d^2$ ? Commented Jul 4, 2022 at 3:30
• After some changes, I get it. $d^2=x_1^2+x_2^2-2x_1x_2$ and get $x_1x_2$ from $x_1^2+3x_2^2+2x_1x_2=32$. @sadman-ncc Commented Jul 4, 2022 at 3:32
• Do you know the basic techniques for solving constraint extrema? Lagrange multipliers and such? They are a bit of overkill here, because you can use tricks, or implicit differentiation instead (the latter is just Lagrange multipliers without mentioning them explicitly). Anyway, I got $4\sqrt6$ as the answer using the fact that at the critical points the gradients $\nabla(x_1^2+3x_2^2+2x_1x_2)$ and $\nabla(x_1-x_2)$ must be parallel to each other. Commented Jul 4, 2022 at 4:05
• Just in case you haven't been referred to it yet, here is a link to our guide to new askers. If you askme, yours is a bit short of such context to decide what kind of an answer would benefit you. Commented Jul 4, 2022 at 4:16
• @ClaudeLeibovici Or simply finding the extremums of $x_1-x_2$. Makes for a lot simpler gradient. Commented Jul 4, 2022 at 4:20

\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})$$.

$$(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}.$$

• +) The equality is valid when $A+B\equiv 90 (\mod 180)$. WLOG, let $A+B=90.$ Then, we know that $\sin{A}=\pm\cos{B}$, which can be written: $$X=\pm\dfrac{4\sqrt{6}}{3}.$$ So, $$Y=\mp \dfrac{4\sqrt{6}}{3}$$. Therefore, $$(x_1, x_2)=\left( \pm \dfrac{8\sqrt{6}}{3}, \mp \dfrac{4\sqrt{6}}{3} \right)$$.
– RDK
Commented Jul 4, 2022 at 4:42

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$$

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)$$

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}\,$$.

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}}$$