This answer is mostly for students who used an algebra approach. I don't know if Fourier himself thought up the series this way, but it is common today. I left a lot of steps out and mainly showed ideas that I struggled with when I first tried to motivate the Fourier Series.
I'll start off by observing a trigonometric polynomial:
$T(x) = c_0 + c_1 \cos(x) + c_2 \cos(2x)+...+c_n \cos(n x) + d_1 \sin(x) + ... + d_n \sin(n x)$
where $c_n$ and $d_n$ are some non-zero value.
The goal is write the orthogonal basis, from there I can find the coefficients.
So, I need declare the inner product:
$<\textbf{f},\textbf{g}> = \int_0^{2\pi} f(x)g(x)dx$
Before I can obtain a orthogonal basis, I should first get the orthonormal basis by using the Gram–Schmidt process. Where $\|\textbf{g}_0\| = \|\textbf{g}_1\| =\|\textbf{g}_2\| = ... =\|\textbf{g}_n\| = 1$.
$\|\textbf{f}\|^2 = <\textbf{f}><\textbf{f}> = 2\pi$
Thus, $\|\textbf{f}\| = \sqrt{2\pi}$
and
$e_0 = \frac{\textbf{f}}{\|\textbf{f}\|}$
$\textbf{g}_0 = e_0 = \frac{1}{\sqrt{2\pi}}$
$\textbf{g}_1 = e_1 = \frac{1}{\sqrt{\pi}}\cos(x)$
...
$\textbf{g}_n = e_n = \frac{1}{\sqrt{\pi}}\cos(nx)$...
$\textbf{g}_{n+1} = e_{n+1} = \frac{1}{\sqrt{\pi}}\sin((n+1)x)$...
$\textbf{g}_{2n} = e_{2n} = \frac{1}{\sqrt{\pi}}\sin(nx)$
The orthogonal basis yields:
$a_0 = \frac{2}{\sqrt{2\pi}}<\textbf{f},\textbf{g}_0>$ (Use 2 because it makes generalizing the coefficients possible.)
$a_1 = \frac{1}{\sqrt{\pi}}<\textbf{f},\textbf{g}_1>$...
$a_n = \frac{1}{\sqrt{\pi}}<\textbf{f},\textbf{g}_n>$...
$b_n = \frac{1}{\sqrt{\pi}}<\textbf{f},\textbf{g}_{2n}>$
Now that everything is divided into sines and cosines I can get the coefficients:
$a_n = \frac{1}{\pi}\int_0^{2\pi} f(x)\cos(nx)dx $
and
$b_n = \frac{1}{\pi}\int_0^{2\pi} f(x)\sin(nx)dx $
Trigonometric Polynomials
First, let us acknowledge the idea of trigonometric polynomials. Say, I have a periodic function $f$ i.e. $$f(t+T)=f(t),\;\forall t\in\mathbb{R}$$
Define $\displaystyle e_{k}(t):=e^{2jk\pi\frac{t}{T}}$ where $j=\sqrt{-1}$ and $k\in\mathbb{Z}$. So this can be interepreted as follow :
$$
''e_{k}(t)\;\text{has a period $T$ for all $k\in\mathbb{Z}$}''
$$
The same can be said for a polynomial $p$ of the form :
$$
p(t):=\sum_{k\in I}c_{k}e^{2jk\pi}
$$
where $I$ is any fixed, finite set of integers and the $c_{k}$ are arbitrary complex numbers. By adding zero terms if necessary, we may assume that :
$$
p(t)=\sum_{k=-N}^{N}c_{k}e^{2jk\pi \frac{t}{T}}
\tag{1}$$
Before we dig in into the next concept of orthogonality we should note that $(1)$ can be represented in terms of $\text{sine}$ and $\text{cosine}$ as follow :
$$
p(t)=c_{0}+\sum_{k=1}^{N}\left(c_{k} e^{2k\pi\frac{t}{T}j}+c_{-k} e^{-2k\pi\frac{t}{T}j}\right)
$$
and by expanding the exponentials, this becomes :
$$
p(t)=\frac{T_{0}}{2}+\sum_{k=1}^{N}\left(\alpha_{k} \cos \left(2k\pi\frac{t}{T}\right)+\beta_{k} \sin \left(2k\pi\frac{t}{T}\right)\right)
$$
where for $k\geq0$ we have :
$$
\alpha_{k}:= c_{k}+c_{-k}\qquad\text{and}\qquad \beta_{k}:= j(c_{k}-c_{-k})
\tag{2}$$
The inverse formulas are :
$$
c_{k}=\frac{1}{2}(\alpha_{k}-j\beta_{k})\qquad\text{and}\qquad c_{-k}=\frac{1}{2}(\alpha_{k}+j\beta_{k})
\tag{3}$$
These relations are fundamental in determining the coefficients of the Fourier series.
Orthogonality
A simple computation shows that the following important relation holds
for the functions $e_{k}(t)$ :
$$
\int_{0}^{T}e_{k}(t)\overline{e}_{m}(t)\;\text{d}t=
\begin{cases}
T&\text{if $k=m$}\\
0&\text{if $k\neq m$}
\end{cases}
$$
We let $\mathcal{P}_{N}$ denote the set of all trigonometric polynomials $p$ of degree
less than or equal to $N$. $\mathcal{P}_{N}$ is obtained by letting the $c_{k}$ in formula $(1)$
vary over all possible values. If we endow this vector space, which has finite dimension equal to $\dim(\mathcal{P}_{N})\leq2N+1$
dimension with the scalar product
$$
\langle p,q \rangle := \int_{0}^{T}p(t)\overline{q}(t)\;\text{d}t
\tag{4}$$
the relation $(4)$ expresses the fact that the functions $e_{k}$ and $e_{m}$ are orthogonal :
$$
\langle e_{k},e_{m}\rangle =\begin{cases}0&\text{if $k\neq m$}\\
\|e_{k}\|_{2}=\sqrt{T}&\text{if $k=m$}
\end{cases}
$$
It follows that the vectors $e_{k}$ are independent and that
$\dim(\mathcal{P}_{N})=2N + 1$ If $p$ is of the form $(1)$, we have :
$$
\langle p,e_{k}\rangle=c_{k}\|e_{k}\|_{2}^{2}=Tc_{k}
$$
and that :
\begin{equation}
c_{k}:=\frac{1}{T}\int_{0}^{T}p(t)e^{-2k\pi \frac{t}{T}j}\;\text{d}t
\end{equation}
This is called Fourier's formula; it gives the coefficients $c_{k}$ explicitly in
terms of the function $p$. Now using $(2)$ and $(3)$ to obtain following formulas for the
coefficients $\alpha_{k}$ and $\beta_{k}$ for $k\geq0$ :
\begin{equation}
\alpha_{k}=\frac{2}{T}\int_{0}^{T}p(t)\cos\left(2k\pi\frac{t}{T}\right)\;\text{d}t\qquad\text{and}\qquad \beta_{k}=\frac{2}{T}\int_{0}^{T}p(t)\sin\left(2k\pi\frac{t}{T}\right)\;\text{d}t
\end{equation}
Best Answer
What you have looks fine, and I likely wouldn't bother trying to simplify it at all (unless you want to take Spencer's suggestion and work with complex numbers). That being said, one might note that the angle addition formula for the sine function might allow some moderate simplification. Recall that $$ \sin(\alpha + \beta) = \cos(\alpha)\sin(\beta) + \cos(\beta)\sin(\alpha) $$ for all $\alpha$ and $\beta$. With $\alpha = -nx$ and $\beta = \frac{n\pi}{2}$, we obtain $$ \cos(nx) \sin\left( \frac{n\pi}{2} \right) - \cos\left(\frac{n\pi}{2}\right) \sin(nx) = \sin\left( -nx + \frac{n\pi}{2} \right) = \sin\left(n\left(\frac{\pi}{2}-x\right)\right).$$ Your series then becomes \begin{align} &\frac{1}{4}+\sum_{n=1}^\infty \left[\left(\frac{1}{n\pi}\sin\left({n\frac{\pi}{2}}\right)\right)\cos(nx) + \left(\frac{-1}{n\pi}\cos\left( {n\frac{\pi}{2}}\right) - 1 \right)\sin(nx)\right] \\ &\qquad\qquad= \frac{1}{4}+\sum_{n=1}^\infty \left[ \frac{1}{n\pi} \left( \cos(nx)\sin\left({n\frac{\pi}{2}}\right) - \cos\left(\frac{n\pi}{2}\right) \sin(nx) \right) - \sin(nx) \right]\\ &\qquad\qquad= \frac{1}{4} + \sum_{n=1}^{\infty} \left[ \frac{1}{n\pi} \sin\left( n\left(\frac{\pi}{2}-x\right) \right) - \sin(nx) \right]. \end{align} I'm not sure that this is any simpler, really, but it is correct (at least, assuming that your derivation tis correct) and it eats up slightly less ink.
On the other hand, I am slightly worried about your derivation. Are you sure that you completed the Fourier coefficients correctly? When I plot the 50th partial sum, I get the following:
Your function is piecewise continuous, hence the Fourier series converges pointwise, and should converge to $\chi_{[0,\frac{\pi}{2}]}$ (i.e. the characteristic function of the interval $[0,\frac{\pi}{2}]$, i.e. the "box" you initially described) almost everywhere. I don't see the sums converging nicely... Indeed, you have a bunch of terms that, taken together, look like $\sum \sin(nx)$. Since $\sin(nx)$ is 1 quite a lot, this is going to cause some major problems for you as $n$ goes to infinity. I would encourage you to check your work.
There is definitely an error in your derivation of the Fourier coefficients. For $n=0$ I get $c_0 = \frac{1}{4}$, and for $n \ne 0$ I get the (complex) Fourier coefficients \begin{align} c_n &= \frac{1}{2\pi} \int_{0}^{2\pi} \chi_{[0,\frac{\pi}{2}]}(x) \mathrm{e}^{-inx}\,\mathrm{d}x \\ &= \frac{1}{2\pi} \int_{0}^{\frac{\pi}{2}} \mathrm{e}^{-inx}\,\mathrm{d}x \\ &= \frac{1}{2\pi in} \left( 1 - \mathrm{e}^{-\frac{in\pi}{2}} \right). \end{align} This then gives us \begin{align} f(x) \sim \frac{1}{4} + \sum_{n=-\infty}^{\infty} \frac{1}{2\pi in} \left( 1 - \mathrm{e}^{-\frac{in\pi}{2}} \right) \mathrm{e}^{inx} &= \frac{1}{4} + \sum_{n=-\infty}^{\infty} \frac{1}{2\pi in} \left( \mathrm{e}^{inx} - \mathrm{e}^{inx-\frac{in\pi}{2}} \right) \\ &= \frac{1}{4} + \sum_{n=1}^{\infty} \frac{1}{2\pi i n} \left( \left(\mathrm{e}^{inx} - \mathrm{e}^{-inx} \right) - \left( \mathrm{e}^{in(x-\frac{\pi}{2})} - \mathrm{e}^{in(x-\frac{\pi}{2})} \right) \right) \\ &= \frac{1}{4} + \sum_{n=1}^{\infty} \frac{1}{n\pi} \left( \sin(nx) - \sin\left( n\left(x-\frac{\pi}{2}\right) \right) \right). \end{align} Modulo the (expected) Gibbs phenomenon, I'd say this looks pretty good: