I have to get the extrema of function $f(x,y)=\cos^2(x)+\cos^2(y)$ restricted to $x+y=\frac{\pi}{2}$. So this is what I did:
$$g(x,y)=x+y=\frac{\pi}{2}$$
$$\nabla f(x,y)=\lambda.\nabla g(x,y)$$
So I got the gradients of both functions:
$$\nabla f(x,y)=<-2\cos(x)\sin(x); -2\cos(y)\sin(y)>$$
$$\nabla g(x,y)=<1;1>$$
From where I got the equation system where: $$ \begin{cases} -2\cos(x)\sin(x)=1 \\ -2\cos(y)\sin(y)=1 \\ x+y=\frac{\pi}{2} \end{cases} $$
I solved the first one as:
$$\sin(2x)=-1 \\ x=\frac{arcsin(-1)}{2} \\ x=-\frac{\pi}{4} $$ So, since the second equation is the same for $y$, then also $y=-\frac{\pi}{4}$
From all this, I get the extrema must be at $(-\frac{\pi}{4}; -\frac{\pi}{4})$. However, this contradicts my restriction of $x+y=\frac{\pi}{2}$ because of $x$ and $y$ signs.
So, where have I gone wrong?
Hint
From $\nabla f=\lambda \nabla g$ we get
\begin{cases}\sin 2x=-\lambda\\ \sin 2y=-\lambda\end{cases} Since $\sin t$ is $2\pi$-periodic we have that $\sin 2t$ is $\pi$-periodic. Thus we get that $2y=2x+k\pi,$ for some integer $k.$ That is, $y=x+\frac {k\pi}2.$ Using the constraint $x+y=\frac \pi2$ we get that $2x+\frac {k\pi}2=\frac \pi2.$ That is, $x=\frac{(1-k)\pi}{4}.$ Thus $y=\frac {(k+1)\pi}4.$