An archived instance of discourse for discussion in undergraduate PDE.

A semi-tricky integral

Mark

How can I compute
$$\int_0^{\pi} \sin(x) \cos(nx) \, dx$$
for integer $n>1$?

Mark

The idea is to use integration by parts twice. We will ultimately re-produce the expression we started with yielding an equation containing that expression, which we solve for. Here are the details:

I will be using integration by parts, or IBP, in the form
$$\int_a^b u \, dv = uv\bigg|_a^b - \int_a^b v \, du.$$
To do so we must simply specify $u$ and $dv$ which, in turn, specifies $v$ and $du$.

First IBP

To begin with
$$\int_0^{\pi} \sin(x)\cos(nx) \, dx$$
we let
$$
\begin{array}{ll}
u = \sin(x) & v = \frac{1}{n}\sin(nx) \, dx \\
du = \cos(x) \, dx & dv= \cos(nx) \, dx.
\end{array}
$$
Then,
\begin{align}
\int_0^{\pi} \sin(x)\cos(nx) \, dx &= \frac{1}{n} \sin(x)\sin(nx)\bigg|_0^{\pi} -
\frac{1}{n} \int_0^{\pi} \cos(x)\sin(nx) \, dx \\
&= 0 - \frac{1}{n} \int_0^{\pi} \cos(x)\sin(nx) \, dx.
\end{align}
I guess we'll have to do
$$\int_0^{\pi} \cos(x)\sin(nx) \, dx$$
by parts.
















Second IBP

To continue with
$$\int_0^{\pi} \cos(x)\sin(nx) \, dx$$
we let
$$
\begin{array}{ll}
u = \cos(x) & v = -\frac{1}{n}\cos(nx) \, dx \\
du = -\sin(x) \, dx & dv= \sin(nx) \, dx.
\end{array}
$$
Then,
\begin{align}
\int_0^{\pi} \cos(x)\sin(nx) \, dx &= -\frac{1}{n} \cos(x)\cos(nx)\bigg|_0^{\pi} -
\frac{1}{n} \int_0^{\pi} \sin(x)\cos(nx) \, dx \\
&= -\frac{(-1)^{n+1}-1}{n} - \frac{1}{n} \int_0^{\pi} \sin(x)\cos(nx) \, dx.
\end{align}













Putting it all together

Putting the previous computations together we get
$$\int_0^{\pi} \sin(x) \cos(nx) \, dx = -\frac{1}{n} \left(
- \frac{(-1)^{n+1}-1}{n} - \frac{1}{n} \int_0^{\pi} \sin(x)\cos(nx) \, dx \right).$$
If we let
$$I =\int_0^{\pi} \sin(x)\cos(nx) \, dx,$$
this becomes
$$I = -\frac{1}{n} \left(
- \frac{(-1)^{n+1}-1}{n} - \frac{1}{n} I\right) =
\frac{(-1)^{n+1}-1}{n^2} + \frac{1}{n^2} I.$$
Finally, solving for $I$, we get
$$
\int_0^{\pi} \sin(x)\cos(nx) \, dx = \frac{(-1)^{n+1} - 1}{n^2-1}.$$










I guess this doesn't work for $n=1$ but I think it's much easier to see that this is zero.

sfrye

Right on. I thought integrating over sine times cosine would produce 0 due to orthogonality but I see why this works now.

jradford

Now what about the other integral?$$\int_{0}^{\pi}sin(x)sin(nx)$$

jtamberi

... I have to say that I feel really dumb that I wasn't able to do this considering I had the right idea of what to do, with one major mistake for it. As for the other integral, I think Mark already said in class that it was 0.

dwillia2

If you are talking about the sine integral we expect $\frac{\pi}{2}$ for $n=1$ and $0$ otherwise. That is

$$
\int_0^\pi \sin(x)\sin(nx)dx = \left\{
\begin{array}{lr}
\frac{\pi}{2} \text{ for}\,\,\, n=1\\
0 \text{ else}\,\,\,
\end{array}
\right.
$$






That would give us $\sin(x)$ as the fourier sine series of $\sin(x)$.

rjensen

@dwillia2 I think you meant to say "we expect $1$ for $n=1$ and $0$ otherwise based on the rest of your work.

dwillia2

Yup, yes, yup. Thanks for that! Also worth noting I was wrong about the constant we receive, the whole reason we put $\frac{2}{L}$ in the front is to normalize!