Let $\psi(x)=\begin{cases}0:& 0<x<1\\ 1:& 1<x<3 \end{cases}$
a) Compute the first 4 terms of its Fourier cosine series explicitly.
b) For each $x (0\le x\le 3)$, whats is the sum of this series?
a) We have that $\phi(x)=\begin{cases}0:& 0<x<1\\ \frac{2}{3}+\sum_{m=1}^{\infty}\frac{-2\sin(m\pi/3)}{m\pi}\cos(\frac{m\pi x}{3}):& 1<x<3 \end{cases}$
Thus the fisrt four terms are $\frac{2}{3}-\frac{2}{\pi}\sin(\frac{\pi}{3})\cos(\frac{\pi x}{3})-\frac{1}{\pi}\sin(\frac{2\pi}{3})\cos(\frac{2\pi x}{3})-\frac{1}{2\pi}\sin(\frac{4\pi}{3})\cos(\frac{4\pi x}{3})$
b) Note that by the interval definition of $x$ we cannot consider $0$ nor $3$ thus in $(0,1),\phi=0$. And now I wonder how will I calculate the sum of the series in $(1,3)?$
I don't think brute force is a solution
Can somebody help me?
edit: I had a typo in the definition of Fourier series, it's 2/3 instead of 4/3. Sorry.
edit 2: According to H.Gutsche's comment, the sum of the series in the interval $0\le x\le 3$ is $\phi(x)=\begin{cases}1/2:& 0\\0:& 0<x<1\\1/2:& 1\\ 1:& 1<x<3\\1/2:& 3 \end{cases}$ by Dirichlet Theorem. I don't know what exactly states that Theorem nor how was applied to get $\phi$. I found this
https://en.wikipedia.org/wiki/Convergence_of_Fourier_series which mention Dirichlet but it says something about an integral and I don't see how that would help.
Please shed some light here, I'm not understanding.
Well, definitely, there has been some confusion around.
Let me try to put some order. I will deal the case "enginering-wise", although rigorously enough.
1) Periodicity
If you are using (asked to use) the Fourier series, that implicitely means that you are considering your function $\phi(x)$ periodic, and that the definition you are reporting is describing just one period of it (as it is normal practice).
Explicitly, it shall be written as $$ \bbox[lightyellow] { \varphi (x) = \varphi (x\bmod 3) = \left\{ {\matrix{ {\,0} \hfill & {\left| {\;0 < x < 1\,} \right.} \hfill \cr {\,1} \hfill & {\left| {\,1 < x < 3} \right.} \hfill \cr } } \right. }$$
So your function looks like in the following sketch
and it is a square pulse wave, of period $T=3$, and with duty-cycle $2/3$.
2) Points of non-definition / discontinuity
The fact that $\phi(x)$ is mathematically undefined at $x=0,1$, but has there finite left and right limits, is somehow irrelevant to the Fourier series, which being continuous will (intuitively speaking) provide and "fill the gaps". It is in fact well known that the Fourier series at the discontinuity points (if "finitely many") takes on the average value between the left and right limit: that is the Dirichlet Theorem already mentioned. Have a look at the reference for a rigorous definition.
Thus in our case the Fourier series (the complete one, with infinite terms) will converge at $1/2$ for $x=0$ and $x=1$.
(the first four terms, for $x=0$ return $\phi(x)=0.5288..$).
3) The Series
$\phi(x)$, when periodically continued, is symmetric (even) around $x=1/2$, as well around $x=-1$. So you can express it in terms of only cosines (the even components) of $x-1/2$, or $x+1$.
Thus your expression shall be corrected as: $$ \bbox[lightyellow] { \eqalign{ & \varphi (x) = {2 \over 3} - \sum\limits_{1\, \le \,k} {{2 \over {k\pi }}\sin \left( {{{k\pi } \over 3}} \right)\cos \left( {{{2k\pi } \over 3}\left( {x - {1 \over 2}} \right)} \right)} = \cr & = {2 \over 3} + \sum\limits_{1\, \le \,k} {{2 \over {k\pi }}\sin \left( {{{2k\pi } \over 3}} \right)\cos \left( {{{2k\pi } \over 3}\left( {x + 1} \right)} \right)} \cr} }$$ The following sketch shows the sum up to the eleventh term.
4) the Sum
Coming to your question b), it is a known property of sinusoidal signals that, if you divide the period into $2 \le n$ equal parts and take $n$ samples of the signal (at the beginning or at the end of each interval), the samples' average will be equal to the continuous mean of the signal: thus $0$, unless the frequency is null.
In mathematical terms: $$ \sum\limits_{0\, \le \,k\, \le \;n - 1} {\cos \left( {\alpha + 2\pi {k \over n}} \right)} = 0\quad \left| {\;2 \le n} \right. $$ which is easy to demonstrate by converting into $e^{ix}$.
Now, if you keep the division of the base period into $n$ parts, and increase the frequency by multiples of the fundamental one, and sum the samples, you get $$ \bbox[lightyellow] { \sum\limits_{0\, \le \,k\, \le \;n - 1} {\cos \left( {\alpha + 2\pi m{k \over n}} \right)} = \left\{ {\matrix{ 0 & {n\rlap{--} \backslash m} \cr {n\cos \alpha } & {n\backslash m} \cr } } \right. }$$ which is the Frequency Aliasing effect, famous in the western movies for the wagon wheel effect.
In our case, we are dividing the period by $3$ and taking three samples at $x=1,2,3$. That would be the same if we take them at $(2,3,4)$ or at $(1/2,3/2,5/2)$, ..., so we can forget about the shift of $-1/2$ or $+1$ attached to $x$ in the formula above.
And for what told above we shall just consider the frequencies multiple of $3$.
But because the amplitudes (for $0<k$) contain the factor $\sin(k \pi /3)$, they are all null.
Therefore the sum of the series for $x=1,2,3$ (same as for $(0,1,2)$ or $(1/2,3/2,5/2)$, ...), independently of how many terms of it you consider, will always be $3 \times mean$, i.e. $$ \bbox[lightyellow] { 3 \cdot 2/3 = 2 }$$ and since it is valid for whichever number of terms, thus also for the complete series, then it is as well equal to $ 1/2+1+1/2$.