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.
Two comments.
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.