Find the maximum of $f(x)=\sum_{i=1}^{4}x_ia_i^2$ under the constraints Find the maximum of $f(x)=\sum\limits_{i=1}^{4}x_ia_i^2$ under the constraints $|x|=1$ and $\langle x,a\rangle=0$.
My try
I set $$L(x,\lambda,\mu)=f(x)-\lambda\left(\sum x_i^2-1\right)-\mu\left(\sum x_ia_i\right)$$
I found that $$\lambda=\frac12\sum_{i=1}^{4}x_ia_i^2$$
I didn't manage to find $\mu$ any hints please?
 A: It can actually be found in a very similar method to how you find lambda. As a hint before I show how to do it, try multiplying $\frac{\partial L}{\partial x_i}$ by $a_i$ and then adding all these equations.
We know $\nabla L=0$. This gives the following equations. $$\frac{\partial L}{\partial x_i}=a_i^2-2\lambda x_i-\mu a_i=0\\ \frac{\partial L}{\partial \lambda}=\sum_{i=1}^4 x_i^2-1=0 \\ \frac{\partial L}{\partial \mu}=\sum_{i=1}^4 x_i a_i=0$$
Multiplying the first equation by $a_i$ and then using the third equation gives $$a_i^3 -2\lambda x_ia_i-\mu a_i^2=0 \\ \sum_{i=1}^4 (a_i^3 -2\lambda x_ia_i-\mu a_i^2)=0 \\ \sum_{i=1}^4 a_i^3 -\mu a_i^2 =0 \\ \mu=\frac{\sum_{i=1}^4 a_i^3}{\sum_{i=1}^4 a_i^2}$$
For the interest of anyone else reading I will include the working for lambda. $$a_i^2-2\lambda x_i-\mu a_i=0 \\ a_i^2x_i-2\lambda x_i^2-\mu a_i x_i=0 \\ \sum_{i=1}^4 a_i^2x_i-2\lambda x_i^2-\mu a_i x_i=0 \\ \sum_{i=1}^4 a_i^2x_i-2\lambda =0\\ \lambda = \frac 12 \sum_{i=1}^4 a_i^2x_i$$
A: Update
We are given two vectors $a=(a_1,\ldots, a_n)$ and $b:=(a_1^2,\ldots,a_n^2)$, and are told to maximize
$$f(x):=b\boldsymbol{\cdot} x$$
under the constraints
$$|x|=1,\qquad a\boldsymbol{\cdot} x=0\ .$$
When $a$ and $b$ are linearly dependent then $f(x)=0$ for all $x$. Discarding this case project $b$ orthogonally into the plane $a\boldsymbol{\cdot} x=0$. We then obtain a vector
$$u:=b-{a\boldsymbol{\cdot} b\over |a|^2}a\ne0\ .$$
This $u$ in the plane $a\boldsymbol{\cdot} x=0$ points in the direction that has the smallest angle with $b$. Letting
$$x_*:={u\over|u|}$$
then gives the maximal $f(x)$ under the given constraints.
You now can compute $x_*$ and $f(x_*)$ in terms of the $a_i$.
