I am trying to find maxima of a linear combination of functions $\text{trig}(x)\text{trig}(y)\text{trig}(z)$, where $\text{trig}$ is $\sin$ or $\cos$ (which of course gives 8 such terms):
$$ f(x,y,z) = A\cos{x}\cos{y}\cos{z} +B\cos{x}\cos{y}\sin{z} +C\cos{x}\sin{y}\cos{z} +D\cos{x}\sin{y}\sin{z}\\ +E\sin{x}\cos{y}\cos{z} +F\sin{x}\cos{y}\sin{z} +G\sin{x}\sin{y}\cos{z} +H\sin{x}\sin{y}\sin{z} $$
Coefficients of this linear combination are arbitrary. After a series of substitutions, I was able to reduce it to maximizing the following function:
$$ g(u,v,w)=K\cos(u+v+w+e) + L\cos u + M\cos v + N\cos w. $$
Equating its gradient to 0, we are presented with a set of equations:
$$ \begin{cases} K\sin(u+v+w+e) + L\sin u = 0, \\ K\sin(u+v+w+e) + M\sin v = 0, \\ K\sin(u+v+w+e) + N\sin w = 0. \end{cases} $$
Unfortunately I am not able to proceed further. Do you have any ideas how to find a solution?
Analytical solution would be great, however in the end it is used in computer calculations, so numerical solutions are also accepted, however they should be stable and work for arbitrary coefficients. For some specific values of free parameters maxima can be lines or planes, so these cases have to be detected (I am probably able to figure it out myself).
Thanks.
$\def\c{{\rm c}}\def\s{{\rm s}}$
Hint ($c_x=\cos(x),s_x=\sin(x)$ and so on):
One can approach the problem in the following way. Write: $$ \begin{align} f(x,y,z) &=[A\,c_xc_y+C\,c_xs_y+E\,s_xc_y+G\,s_xs_y]\cos(z)\\ &+[B\,c_xc_y+D\,c_xs_y+F\,s_xc_y+H\,s_xs_y]\sin(z)\\ &=g(x,y) \cos(z-\phi(x,y))\tag1 \end{align} $$ with $$ \begin{align} g^2(x,y) &=[A\,c_xc_y+C\,c_xs_y+E\,s_xc_y+G\,s_xs_y]^2\\ &+[B\,c_xc_y+D\,c_xs_y+F\,s_xc_y+H\,s_xs_y]^2\tag2 \end{align} $$ Clearly the function (1) has maximum value $g(x,y)$ at $z=\phi(x,y)$. Therefore we need to maximize $g^2(x,y)$. This can be dealt exactly as we have done with $f(x,y,z)$ expanding in (2) the squares and using $$\cos^2y=\frac{1+\cos2y}2,\quad \sin^2y=\frac{1-\cos2y}2,\quad \cos y\sin y=\frac{\sin2y}2.\tag3$$
After doing this you will obtain an expression $$ \lambda(x)+h(x)\cos(2y-2\psi(x)), $$ which after setting $y=\psi(x)$ reduces to a simple problem of maximizing $\lambda(x)+h(x)$.
PS. By my calculation $$\begin{align} \lambda(x)&=\frac12\Big[(A^2+B^2+C^2+D^2)c_x^2+(E^2+F^2+G^2+H^2)s_x^2 +2(AE+BF+CG+DH)c_xs_x\Big]\\ h^2(x)&=\frac14\Big[(A^2+B^2-C^2-D^2)c_x^2+(E^2+F^2-G^2-H^2)s_x^2 +2(AE+BF-CG-DH)c_xs_x\Big]^2\\ &+\quad\Big[(AC+BD)c_x^2+(EG+FH)s_x^2+2(AG+BH+CE+DF)c_xs_x\Big]^2 \end{align}$$ but I could make a mistake.