# Trigonometry/A Square Wave in Sines

## Trigonometric Polynomials

We start by considering trigonometric polynomials. These are functions that are a sum of different sine and cosine functions. For example:

$\displaystyle f(x)=5 + 3\cos(x)+2\sin(2x)-5\cos(4x)$

is a trigonometric polynomial. In general, a trigonometric polynomial has the form:

$\displaystyle A_0+\sum_{n=1}^N [A_n\cos(nx)+B_n\sin(nx)]$

Really, the underlying idea here isn't that different from ordinary polynomials. We're forming a linear combination of functions whose properties we know well. With ordinary polynomials the functions are $\displaystyle x^n$ with $\displaystyle n=0,1,2,3...$. Here the functions are $\displaystyle \cos nx$ or $\displaystyle \sin nx$ with $\displaystyle n=0,1,2,3...$

 Worked Example: We can and will define the degree of a trigonometric polynomial, and discuss their various properties but before we get into that it might be interesting to notice it is not immediately obvious which functions can be written as trigonometric polynomials. Consider for example: $\displaystyle f(x)=\cos(3x)\sin(5x)$ It doesn't look like a trigonometric polynomial at first sight, but if we use our sum of angle formulas to calculate $\tfrac{1}{2}\sin(5x+3x)-\tfrac{1}{2}\sin(5x-3x)$ we find that it is: $f(x)=\cos(3x)\sin(5x)=\tfrac{1}{2}\sin(8x)-\tfrac{1}{2}\sin(2x)$

 Exercise: An alternative? $\displaystyle \sum_{n=0}^N [A_n\cos(nx)+B_n\sin(nx)]$ Look at the formula above for trigonometric polynomials. Does it include the same functions?
 Exercise: A Trigonometric Polynomial Express $\displaystyle\sin^2\theta$ as a trigonometric polynomial in $\displaystyle\theta$
 Exercise: Combining Trigonometric Polynomials If $\displaystyle g(x)$ is an ordinary polynomial then $\displaystyle (g(x))^2$ is also a polynomial and so is $\displaystyle g(g(x))$. Is this in general true for trigonometric polynomials?

As well as sum of angle formulas we have another very useful tool on our side. Among the many amazing properties of the trigonometric functions sin(x) and cos(x) are the so-called orthogonality relations. These are the following results concerning the integrals:

$\int_{-\pi}^{\pi} \sin(nx)\sin(mx)\,dx=\begin{cases}0 & \text{if }n\neq m \\ 2\pi & \text{if }n=m\end{cases}$

Similarly,

$\int_{-\pi}^{\pi} \cos(nx)\cos(mx)\,dx=\begin{cases}0 & \text{if }n\neq m \\ 2\pi & \text{if }n=m\end{cases}$
$\int_{-\pi}^{\pi} \cos(nx)\sin(mx)\,dx=0 \quad\text{for all }n \text{ and } m.$

to do: graphs showing informal argument as to why this is so using symmetry properties.

For example, taking the the function we started with, $f(x)=5 + 3\cos(x)+2\sin(2x)-5\cos(4x)$, we can compute

\begin{align}&\frac{1}{\pi}\int_{-\pi}^\pi f(x)\cos(x)\,dx\\ &=\frac{5}{\pi}\int_{-\pi}^\pi \cos(x)\,dx+\frac{3}{\pi}\int_{-\pi}^\pi \cos^2(x)\,dx+\frac{2}{\pi}\int_{-\pi}^\pi \sin(x)\cos(x)\,dx-\frac{5}{\pi}\int_{-\pi}^\pi\cos(x)\cos(4x)\,dx\\&=0+\frac{3}{\pi}\cdot\pi+0+0=3\end{align}

Notice this last line follows from the integrals we have computed above. This means we can use integrals to determine the coefficients of a trigonometric polynomial. This is an intriguing idea since not every trigonometric polynomial is clearly a trigonometric polynomial at first sight. The question becomes how do we know when to stop calculating the coefficients of the trigonometric polynomial? How do we know when we have found them all? One answer might be to compare the graphs. We first demonstrate that this idea can be used in the case that we know how far to go, for example let

$f(x)=5+3\cos(x)+2\sin(2x)-\sin(3x)-\tfrac{1}{8}\cos(4x)$

then numerically calculate the integrals for $A_n$ and $B_m$. We can see from the graph when we have calculated all of the coefficients, as indicated in the animation below.

Let's try another example where we do not know the degree of the trigonometric polynomial immediately. The function $f(x)=5sin(x)cos^2(2x)+sin^{14}(12x)$ can be written as a trigonometric polynomial, our procedure of integrating to find the coefficients and looking at the graph to tell when we are done can be used, and below is an animation of what happens.

Notice that for this specific function it took rather a long time to decide when we reached the end. It turns out that we have have to go all the way to N=48 before we find all the coefficients. This may seem like a problem, particularly if we accidentally start out with a function that is not a trigonometric polynomial.

To see what happens, let's assumed that we started with a square wave, that is we let

$f(x)=\begin{cases}1 & \text{if } 0\leq x\leq\pi \\ -1 &\text{if } -\pi

and $f(x)$ is defined to be periodic with period $2\pi$, i.e. we define $f(x+2\pi)=f(x)$. If we use our procedure on $f(x)$, then we quickly discover that it never seems to stop as shown in the animation:

This animation shows that as we increase the number of terms we take in the trigonometric polynomial, we never quite make it to the original function. On the other hand, we get very close, especially away from $x=-\pi, 0, \pi$.

With this motivation we could ask the bold question, what if we let the number of terms approach infinity; do the trigonometric polynomials converge to the square wave? This is the beginning of the study of Fourier series.