# heat equation with fourier series

Original PDE $$T_t=\alpha T_{xx}$$ I need to solve this equation numerically and analytically and compared them. I've already done the numerical part. But I need to solve it analytically now.

Given the initial condition $$T(x,0)=sin(\frac{\pi x}{L})$$ where $$L=1$$

I would like to find the exact solution of the heat equation.

I know what $$T(x,t)=\sum_{n=1}^{\infty}B_n sin(n\pi x)e^{-n^2\pi^2\alpha t}\\where\\B_n=2\int_0^1T(x,0)sin(n\pi x)dx$$

After evaluating this integral, I get the solution as

$$T(x,t)=\sum_{n=1}^{\infty}\frac{2sin(n\pi)}{(1-n^2)\pi} sin(n\pi x)e^{-n^2\pi^2\alpha t}$$

I think I've done something wrong here because $$n=1^{th}$$ term is not defined. Can someone point out my mistake if there is? Thank you!

Corrected

Bn is nonzero only at n=1. Evaluating the case for n=1, Bn=1

So the solution is

$$T(x,t)=sin(\pi x)e^{-\pi^2\alpha t}$$

Thanks to Leucippus and AlexZorn for the correction.

• Without seeing your intermediate computations, I imagine that the coefficient $\frac{1}{1 - n^2}$ comes from integrating to find $B_n$ and not considering a special case in $n$. – Travis Oct 10 '14 at 4:46
• In fact, something more seems to be wrong, as $\sin (\pi n) = 0$ for all $n$, and so $T(x, t) = 0$. – Travis Oct 10 '14 at 4:47
• yes indeed...so while finding Bn, do I just exclude n=1 from the calculations? – Alp Oct 10 '14 at 4:48
• What is the original equation to solve? There seems to be a factor, $\alpha$, in the exponential...of its origins it is not stated. – Leucippus Oct 10 '14 at 4:50
• I've checked my integral with wolfram and I got the same result though – Alp Oct 10 '14 at 4:50

First, you're integral computation looks something like this:

$$2\int_0^1\sin(\pi x)\sin(n\pi x)\, dx = \int_0^1 \cos((n - 1)\pi x) - \cos((n+1)\pi x)\, dx$$

Now, it's tempting to write:

$$\int \cos((n-1)\pi x)\, dx = \frac{\sin((n-1)\pi x)}{\pi(n-1)} + C$$

But of course this is not true when $n = 1$. Hence your mistake.

The second comment is that you can actually solve for the coefficients "by inspection", without having to compute any integrals. Specifically, we have:

$$T(x,t) = \sum_{n = 1}^{\infty} B_n \sin(n \pi x)e^{-n^2\pi^2 \alpha t}$$

So:

$$T(x,0) = \sum_{n = 1}^{\infty} B_n \sin(n \pi x) = B_1\sin(\pi x) + B_2 \sin(2\pi x) + \cdots$$

And also $T(x,0) = \sin(\pi x)$. It should be clear from this that $B_1 = 1$ and the rest of the $B_n$ are zero.

Given the pde $u_{t} = \alpha u_{xx}$, $u(0,t) = u(L,t) = 0$ and $u(x,0) = \sin\left(\frac{\pi x}{L} \right)$ : the equation can be separated by use of $u(x,t) = F(t) G(t)$ and leads to the equations \begin{align} F' + \lambda^{2} \alpha F &= 0 \\ G'' + \lambda^{2} G &= 0 \end{align} which have solutions \begin{align} F(t) &= e^{- \lambda^{2} \alpha t} \\ G(x) &= A \cos(\lambda x) + B \sin(\lambda x). \end{align} Now applying the boundary conditions it is seen that the general solution is \begin{align} u(x,t) = \sum_{n=1}^{\infty} B_{n} \, \sin\left( \frac{n \pi x}{L} \right) \, e^{- \frac{n^{2} \pi^{2} \alpha t}{L^{2}}}. \end{align} Applying the initial condition yields \begin{align} \sin\left(\frac{\pi x}{L} \right) = \sum_{n=1}^{\infty} B_{n} \, \sin\left( \frac{n \pi x}{L} \right). \end{align} This is a Fourier series for which the coefficients are given by \begin{align} B_{n} = \frac{2}{L} \, \int_{0}^{L} \sin\left(\frac{\pi x}{L} \right) \, \sin\left( \frac{n \pi x}{L} \right) \, dx. \end{align} For the case $n= 1$ it is seen that \begin{align} B_{1} = \frac{2}{L} \int_{0}^{L} \sin^{2}\left( \frac{\pi x}{L} \right) \, dx = 1 \end{align} whereas for $n \geq 2$ \begin{align} B_{n} = \frac{1}{2 \pi} \, \frac{\sin(n \pi) }{1 - n^{2}} = 0 \end{align} since $n$ is an integer. The solution for $u$ is now \begin{align} u(x,t) = \sin\left( \frac{\pi x}{L} \right) \, e^{- \frac{\pi^{2} \alpha t}{L}}. \end{align}

• Yes I get that part. And Bn is the integral written above, right? – Alp Oct 10 '14 at 5:09
• had to add the remaining portions. The process you have started was correct, just missed a special case. – Leucippus Oct 10 '14 at 5:14
• Ok, Bn vanishes everywhere but n=1 and it is actually equal to 1. – Alp Oct 10 '14 at 5:17
• does that mean \begin{align} u(x,t) = \sin\left( \frac{n \pi x}{L} \right) \, e^{- \frac{n^{2} \pi^{2} \alpha t}{L^{2}}}. \end{align} – Alp Oct 10 '14 at 5:18
• The only non-zero solution is the case of $n=1$. Meaning what you just posted should have $n=1$. – Leucippus Oct 10 '14 at 5:20