Find the continuous least squares trigonometric polynomial $S_{2}(x)$
for $f(x) = 2x - 1$ on $[-\pi , \pi]$
I know $S_{2}(x) = \frac{a_{0}}{2} + a_{1}cos(x) + a_{2}cos(x) + b_{1}sin(x)$
but for solving for the $a_{i}$ and $b_{i}$, I don't think I am getting the correct numbers.
$a_{0} = \frac{1}{\pi}\int_{-\pi}^{\pi}(2x-1)cos(0x)dx = -2$
$a_{1} = \frac{1}{\pi}\int_{-\pi}^{\pi}(2x-1)cos(1x)dx = 3.6*10^{-14}$
$a_{2} = \frac{1}{\pi}\int_{-\pi}^{\pi}(2x-1)cos(2x)dx = -2.2*10^{-13}$
$b_{1} = \frac{1}{\pi}\int_{-\pi}^{\pi}(2x-1)sin(1x)dx = 4$
Which would make it $S_{2}(x) = -1 + 3.6*10^{-14}cos(x) + -2.2*10^{-13}cos(x) + 4sin(x)$
That doesn't seem right to me
If those tiny values are calculated numerically, they are almost certainly exactly zero. This means that your first approximation is $4\sin(x)-1$.
Get some additional terms, plot the results, and see how close that is to $2x-1$.
You should also be able to analytically evaluate the integrals for $a_n$ and $b_n$ once you have $a_1$ and $b_1$.