If $x$, $y$, and $z$ are real numbers such that $x+y+z=8$ and $x^2+y^2+z^2=32$, what is the largest possible value of $z$? I tried swapping $z$ from the first equation to the second, and got $$x^2 + x y - 8 x + y^2 - 8 y + 16=0$$ Not sure where to go from there, and if I'm on the right track at all.

$$\max z$$
subject to $$x+y+z=8$$
$$x^2+y^2+z^2=32$$
The Lagrangian is $$z-\lambda(8-x-y-z)-\mu(32-x^2-y^2-z^2)$$
Differentiating wrt x:
$$8\lambda+2\mu x=0\tag{1}$$
Differentiating wrt $y$:
$$8\lambda+2\mu y=0\tag{2}$$
Differentiating wrt $z$:
$$1+8\lambda+2\mu z=0\tag{3}$$
If $\mu=0$, equation $(1)$ and $(2)$ gives us $\lambda=0$ and we get a contradiction in equation $(3)$.
Hence $\mu \ne 0$. From equation $(1)$ and $(2)$, we get $x=y$.
$$2x+z=8$$
$$2x^2+z^2=32$$
$$2\left( \frac{8-z}2\right)^2+z^2=32$$
$$\left( 8-z\right)^2+2z^2=64$$
$$3z^2-16z=0$$
$$z(3z-16)=0$$
Hence maximum $z$ occurs at $\frac{16}3$
