# 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:

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

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

$A_{0}+\sum _{n=1}^{N}{\bigl [}A_{n}\cos(nx)+B_{n}\sin(nx){\bigr ]}$

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 $x^{n}$  with $n=0,1,2,3,\dots$  . Here the functions are $\cos(nx)$  or $\sin(nx)$  with $n=0,1,2,3,\dots$

 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: $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 ${\frac {\sin(5x+3x)-\sin(5x-3x)}{2}}$ we find that it is: $f(x)=\cos(3x)\sin(5x)={\frac {\sin(8x)-\sin(2x)}{2}}$ Exercise: An alternative? $\sum _{n=0}^{N}{\bigl [}A_{n}\cos(nx)+B_{n}\sin(nx){\bigr ]}$ Look at the formula above for trigonometric polynomials. Does it include the same functions?
 Exercise: A Trigonometric Polynomial Express$\sin ^{2}(x)$ as a trigonometric polynomial in $x$ Exercise: Combining Trigonometric Polynomials If $g(x)$ is an ordinary polynomial then $g(x)^{2}$ is also a polynomial and so is $g{\bigl (}g(x){\bigr )}$ . 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 \limits _{-\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 \limits _{-\pi }^{\pi }\cos(nx)\cos(mx)dx={\begin{cases}0&{\text{if }}n\neq m\\2\pi &{\text{if }}n=m\end{cases}}$
$\int \limits _{-\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 function we started with, $f(x)=5+3\cos(x)+2\sin(2x)-5\cos(4x)$  , we can compute

{\begin{aligned}&{\frac {1}{\pi }}\int \limits _{-\pi }^{\pi }f(x)\cos(x)dx\\&={\frac {5}{\pi }}\int \limits _{-\pi }^{\pi }\cos(x)dx+{\frac {3}{\pi }}\int \limits _{-\pi }^{\pi }\cos ^{2}(x)dx+{\frac {2}{\pi }}\int \limits _{-\pi }^{\pi }\sin(x)\cos(x)dx-{\frac {5}{\pi }}\int \limits _{-\pi }^{\pi }\cos(x)\cos(4x)dx\\&=0+{\frac {3}{\pi }}\cdot \pi +0+0=3\end{aligned}}

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)=5\sin(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.