Let $f(x,y,z)=x-2y+z^2$ over the contraint $x^2+y^2+z^2=9$.
By Lagrange multipliers I can consider the following function
$$ \begin{split} L(x,y,x \lambda) &= x-2y+z^2+ \lambda(x^2+y^2+z^2-9)\\ &=x-2y+z^2+ \lambda x^2+ \lambda y^2+ \lambda z^2-9 \lambda). \end{split}$$
So
$$ \begin{split} 0 &= \frac{\partial L}{\partial x} &= 1+2 \lambda x\\ 0 &= \frac{\partial L}{\partial y} &= -2+2 \lambda y\\ 0 &= \frac{\partial L}{\partial z} &= 2z+ 2 \lambda z\\ 0 &= \frac{\partial L}{\partial \lambda} &= x^2+y^2+z^2. \end{split} $$
From the first 2 equations $\lambda, x, y \neq 0$, so I conclude that $$ x = \frac{-1}{2 \lambda} \quad \mbox{and} \quad y = \frac{1}{ \lambda}. $$
I have trouble trying to calculate $z$ in terms of $\lambda$ substituting in $x^2+y^2+z^2-9$. the values obtained for $x$ and $y$ I obtain $$z= \pm \sqrt{9-\frac{3}{4\lambda ^2}}.$$ But I cannot proceed anymore from here :(
How can I end up computing the extreme values over these conditions?
$$x = -\frac{1}{2\lambda} \ , y = \frac{1}{\lambda},2z(1+\lambda) = 0$$ $$\implies x = -\frac{1}{2\lambda} \ , y = \frac{1}{\lambda} \ and \ (\ z = 0 \ or \lambda = -1)$$
CASE $1$: $\lambda =-1\implies x = \frac{1}{2} \ , \ y= -1 $
So, $x^2+y^2+z^2 = 9\implies \frac{1}{4}+1+z^2 = 9 \implies z^2=9-\frac{5}{4} = \frac{31}{4}$
Thus from case $1$
CASE $2$: $z=0$
So, $ x = -\frac{1}{2\lambda} \ , y = \frac{1}{\lambda}\implies \frac{1}{4\lambda^2}+\frac{1}{\lambda^2}+0 = 9 \implies \frac{5}{4\lambda^2} = 9\implies\lambda = \pm\frac{\sqrt5}{6}$
So,
or
Use these three sets of values and find which corresponds to maximum or minimum.