\(M=sin^2x+cos^2x+2sinx.cosx+cos^2x-sin^2x\)
\(=\left(sinx+cosx\right)^2+\left(cosx-sinx\right)\left(cosx+sinx\right)\)
\(=\left(sinx+cosx\right)\left(sinx+cosx+cosx-sinx\right)\)
\(=2cosx\left(sinx+cosx\right)\)
\(=2\sqrt{2}cosx.cos\left(x-\frac{\pi}{4}\right)\)