Here is the problem. Find the function $f$ of the type $f(x) = a\cos x + b\sin x$ which best approximates the function $g$ in the points : $$ \begin{array}{ c | c | c | c | c | c | c } x & -3\frac{\pi}{4} & -\frac{\pi}{2} & -\frac{\pi}{4} & \frac{\pi}{4} & \frac{\pi}{2} & 3\frac{\pi}{4} \\ \hline g(x) & -1 & -1 & -1 & 1 & 1 & 1 \end{array} $$
using the least squares method. This is how I'm doing it. $g \in V$ - the linear space of all the functions defined in the given points and $f$ should be a function contained in the subspace $W$ of $V$ generated by $\sin x$ and $\cos x$. The norm of $V$ is $(s,t) = \sum_{i=1}^{6} s(x_i)t(x_i)$. So the conditions for $f$ should be $$(g - f, \cos) = 0 \text{ and } (g-f, \sin) = 0$$
From $(g-f, \cos) = 0$ I get $$\sum_{i = 1}^{6}(g(x_i)-a\cos x_i - b\sin x_i)\cos x_i = 0$$ from where substituting with the given data I conclude that $a = 0$. Similarly from $(g-f, \sin) = 0$ I get $b = \frac{1+\sqrt{2}}{2}$. So the answer has to be $$f(x) = \frac{1+\sqrt{2}}{2} \sin x$$ Is this the correct answer and is there any method I can verify it? Thanks in advance!
Since $g$ is clearly and odd function, and cosine is even and sine is odd, the coefficient of cosine will have to be $0$, and that's what you got. And you can check by subsitution whether your two linear equations are satisfied by the answer you got.