Heat Equation with zero temperature at endpoints
Consider the problem
\begin{cases} \frac{\partial u}{\partial t} = k \frac{\partial^2 u}{\partial x^2}\\ u(0,t) = 0\\ u(L,t) = 0\\ u(x,0) = f(x) \end{cases}We want to find u(x,t) where 0 < x < L, t> 0. Here we use the method of seperation of variables.
We assume the function is of the form u(x,t) = A(x)G(t) where A is a function depending only on x and G only on t. We call solutions in this form product solutions.
Plugging our product solution into the partial differential equation, we get
\frac{\partial u}{\partial t} = k \frac{\partial^2 u}{\partial x^2} \iff \frac{\partial (A(x)G(t))}{\partial t} = k \frac{\partial^2 (A(x)G(t))}{\partial x^2}
Which simplifies too
A(x)\frac{dG(t)}{dt} = kG(t)\frac{d^2A(x)}{dx^2} \iff \frac{1}{kG(t)}\frac{dG(t)}{dt} = \frac{1}{A(x)}\frac{d^2A(x)}{dx^2}
We set both of these terms equal to a constant, -\lambda. We then have
\frac{dG}{dt} = -\lambda kG(t) \qquad \frac{d^2A}{dx^2} = -\lambda A(x)
We now must satisfy our boundary conditions.
u(0,t) = A(0)G(t) = 0 \qquad u(L,t) = A(L)G(t)
Thus either G(t) = 0 for all times t, or A(0) = A(L) = 0. We call the case where G(t) = 0 the trivial case, and only focus on the case where A(0) = A(L) = 0 We have
\frac{dG}{dt} = -\lambda kG(t) \implies G(t) = Ce^{-\lambda k t}
If \lambda > 0, then the solution exponentially decays as t \to \infty. If \lambda = 0, then the solution is constant for some c. If \lambda < 0, then the solution increases to infinity. We want too find the values of lambda for A such that non-trivial solutions exist. We must introduce eigenvalues and eigenfunctions in order to do this. For each eigenvalue we have one corresponding eigenfunction.
We use the characteristic equation
r^2 = -\lambda \implies r = \pm \sqrt{-\lambda}
When \lambda > 0
r = \pm i \sqrt{\lambda} \implies A(x) = c_1 \cos (\sqrt{\lambda}x) + c_2\sin (\sqrt{\lambda}x)
Working this into our boundary conditions, we have
A(0) = c_1\cos(0) + c_2\sin(0) = c_1 \implies c_1 = 0
Thus
A(x) = c_2 \sin(\sqrt{\lambda}x)
Using the second boundary conditions
A(L) = c_2\sin(\sqrt{\lambda}L) \implies \lambda = (\frac{\pi n}{L})^2
So \lambda > 0 gives us
A(x) = c_2\sin\left(\frac{nx\pi}{L}\right)
Next we have to consider the case where \lambda = 0.
\frac{d^2 A}{dA^2} = 0 \implies c_3x + c_4
This immeditally implies that A(0) = c_4 = 0. Thus we have A(x) = c_3 x. But A(L) = Lc_3 = 0 \implies c_3 = 0. Thus we have no solutions. Thus \lambda = 0 is not an eigenvalue.
Next we consider \lambda < 0. This gives us r = \pm\sqrt{+ \lambda}
A(x) = c_1e^{\sqrt{-\lambda}x} + c_2e^{-\sqrt{-\lambda}x}
We get
u(x,t) = B\sin\left(\frac{n\pi x}{L}\right)e^{-k\left(\frac{n\pi}{L}\right)^2t}
Something something
u(x,t) = 7\sin\left(\frac{8\pi x}{L}\right)e^{-k(8\pi/L)^2t}
We use the principle of superposition, which states that any solution can be in the form
u(x,t) = \sum_{n=1}^NB_n\sin\left(\frac{n\pi x}{L}\right)e^{-k(n\pi/L)^2t}
We know that the sum of multiple solutions is a solution due to linearity. We have infinite solutions. The sum of all possible solutions is
u(x,t) = \sum_{n=1}^\infty B_n\sin\left(\frac{n\pi x}{L}\right)e^{-k(n\pi/L)^2t}
This will work for any initial condition u(x,0) = f(x). We need functions that can wrote as an infinite sum we can apply linearity to. We claim any function can be wrote as an infinite linear combination of \sin functions, known as a Fourier Series
f(x) = \sum_{n=1}^\infty B_n \sin \frac{n\pi x}{L}.
But how do we determine the constant B_n for a given function f(x)? For this we need to check
\int_0^L \sin(\frac{n\pi x}{L}) \sin(\frac{m\pi x}{L}) \; dx.
When n \not = m we use the product of \sin to get
\frac{1}{2} \int_0^L \cos(\frac{(n-m)\pi x}{L}) \; dx - \frac{1}{2}\int_0^L \cos\left(\frac{(n+m)\pi x}{L}\right) \; dx
Which is equal to
\frac{1}{2}\frac{L}{(n-m)\pi}\left.\sin\left(\frac{(n-m)\pi x}{L}\right)\right|^L_0 - \frac{1}{2}\frac{L}{(n+m)\pi}\left.\sin\left(\frac{(n+m)\pi x}{L}\right)\right|^L_0 = 0
When n = m we have
\frac{1}{2}\int_0^L \cos(0)\; dx - \frac{1}{2}\int_0^L \cos\left(\frac{2n\pi x}{L}\right)\; dx = \frac{L}{2}
Thus we have
\int_0^L \sin\left(\frac{n\pi x}{L}\right) \sin\left(\frac{m\pi x}{L}\right) \; dx = \begin{cases} 0 & n \not = m\\ L/2 & n = m \end{cases}
So lets find B_m. We know
f(x) = \sum_{n=1}^\infty B_n \sin \frac{n\pi x}{L}.
Multiplying both sides by \sin(m\pi x/L) gets us
\sin\left(\frac{m\pi x}{L}\right)f(x) = \sin\left(\frac{m\pi x}{L}\right)\sum_{n=1}^\infty B_n \sin \frac{n\pi x}{L} = \sum_{n=1}^\infty B_n \sin \frac{n\pi x}{L}\sin\frac{m\pi x}{L}
Integrating both sides from 0 to L with respect to x gives
\int_0^L\sin\left(\frac{m\pi x}{L}\right)f(x)\; dx = \sum_{n=1}^\infty B_n \int_0^L \sin \frac{n\pi x}{L}\sin\frac{m\pi x}{L} \; dx
Which we solved earlier. We can expand the sum
\begin{align*} \sum_{n=1}^\infty B_n \int_0^L \sin \frac{n\pi x}{L}\sin\frac{m\pi x}{L} \; dx &= B_1 \int_0^L \sin \frac{\pi x}{L}\sin\frac{m\pi x}{L} \; dx\\ &+ B_2 \int_0^L \sin \frac{2\pi x}{L}\sin\frac{m\pi x}{L} \; dx\\ &+ B_3\int_0^L \sin \frac{3\pi x}{L}\sin\frac{m\pi x}{L} \; dx\\ &+ B_4\int_0^L \sin \frac{4\pi x}{L}\sin\frac{m\pi x}{L} \; dx\\ &+ \cdots\\ &+ B_m\int_0^L \sin \frac{m\pi x}{L}\sin\frac{m\pi x}{L} \; dx\\ &+ B_{m+1}\int_0^L \sin \frac{(m+1)\pi x}{L}\sin\frac{m\pi x}{L} \; dx\\ &+ \cdots\\ &= B_m \frac{L}{2} \end{align*}
Thus
B_m = \frac{2}{L} \int_0^L f(x) \sin\left(\frac{m\pi x}{L}\right)\; dx
If we want to represent f(x), we just use the coeffiencts given by the above integral.
Lets say for example we have u(x,0) = f(x) = 100. To write the solution, we need to compute B_n.
\begin{align*} B_n &= \frac{2}{L} \int_0^L f(x) \sin\left(\frac{n\pi x}{L}\right)\; dx\\ &= \frac{2}{L} \int_0^L 100 \sin\left(\frac{n\pi x}{L}\right)\; dx\\ &= \frac{200}{L} \frac{L}{n\pi} \left.\left(- \cos\left(\frac{n\pi x}{L}\right)\right)\right|^L_0\\ &= \frac{200}{n\pi}\left[-\cos(n\pi) + \cos(0)\right] \end{align*}
Thus we have
B_n = \begin{cases} 400/n\pi & \text{if } n \mod 2 = 1\\ 0 & \text{if } n \mod 2 = 0 \end{cases}
Then f(x) is
f(x) = \sum_{n=0}^\infty \frac{400}{(2n+1)\pi} \sin \frac{(2n+1)\pi x}{L}.
Then we can rewrite our heat equation as
u(x,t) = \left(\sum_{n=0}^\infty \frac{400}{(2n+1)\pi} \sin \frac{(2n+1)\pi x}{L}\right)e^{-k((2n+1)\pi/L)^2t}
Another problem with different boundary conditions
u(x,t) = C\cos\left(\frac{n\pi x}{L}\right)e^{-k(n\pi/L)^2t}
Using the superposition principle
u(x,t) = \sum_{n=0}^\infty A_n \cos\left(\frac{n\pi x}{L}\right) e^{-k(n\pi/L)^2t}
Is also a solution. What do we need in the solution to satisfy the initial condition u(x,0) = f(x) = \sum A_n\cos(n\pi x/L). Same idea as before but with \cos instead of \sin. Again we need to find A_n.
To determine A_n, we will need
\int_0^L \cos\left(\frac{n\pi x}{L}\right) \cos\left(\frac{m\pi x}{L}\right) \; dx = \begin{cases} 0 & n \not = m\\ L/2 & n = m\\ L & n = m = 0 \end{cases}