# Heat equation - confusion with boundary conditions

Okay So ill start by writing the question out, as maybe I'm interpreting it wrong:

One end A of an insulated metal bar AB of length 2m is kept at 0c while the other end B is maintained at 50c until a steady sate temperature along the bar is reached, At t=0 the end B is suddenly reduced to 0c and kept at that temperature. Using the heat equation $\frac{1}{c^2}u_t=u_{xx}$ determine an expression for the temperature at any point in the bar distance x from A at any time t.

$u(0,t)=0$ , $u(2,t) = 50$, $u(2,0) = 0$ , $u(x,0) = 0 (Not,sure)$

So because it isn't homogeneous boundary conditions:

$u(x,t) = v(x) + w(x,t)$

$v(x) = Ax + B ,\space \space v(0)=B=0,\space\space v(2)=2A=50,\space A=25$

$v(x)=25x$

$u(x,t) - v(x) = w(x,t)$

$u(0,t) - v(0) = 0 \space \space, \space u(2,t) - v(2) = 0$

As the boundary conditions are now homogeneous i can proceed with separation of variables which produces the following:

$w(x,t)= \sum_{r=1}^{\infty}Q_r\sin(\frac{r\pi x}{2})\mathrm{e}^{-\lambda^2t} , \space\space\space where \space \lambda=\frac{r\pi c}{2}$

I'm not proficient enough in LaTeX commands to show all the steps but if the above is wrong i guess i need to !

This is kind of where i have a problem, im not sure which boundary conditions i should apply, so if i applied $u(x,0) = 0$ then $v(x)=25x$ therefore:

$-25x = w(x,0)= \sum_{r=1}^{\infty}Q_r\sin(\frac{r\pi x}{2})$

$Q_r = \frac{2}{2} \int_{0}^{2}-25xsin(\frac{r\pi x}{2})dx$

$Q_r = \left[\frac{50x}{r\pi}\cos(\frac{r\pi x}{2})\right]_0^{2}$

$Q_r = -\frac{100}{r\pi}\space when\space r = 1,3,5$ or $Q_r = \frac{100}{r\pi}\space when\space r = 2,4,6$

So my solution to u(x,t) would be

$u(x,t) = 25x + \frac{100}{\pi}\sum_{r=1}^{\infty}\frac{1}{r}(-1)^r\sin(\frac{r\pi x}{2})\mathrm{e}^{-\lambda^2t}$

But the book has $u(x,t) = \frac{100}{\pi}\sum_{r=1}^{\infty}\frac{1}{r}(-1)^{r+1} \sin(\frac{r\pi x}{2})\mathrm{e}^{-\lambda^2t}$

So it doesn't even take into account the steady state part of the solution, im confused, maybe Ive interpreted boundary conditions wrong?

The steady state solution for the case where one end is being held at Temp=$0$ and the other at Temp=$50$ would be a linear temperature distribution ranging from $0$ to $50$. That definitely would be a solution where $u_{xx}=0$, and $u_{t}=Ku_{xx}=0$. So that's steady state. That means the next part starts with $u(x,0)=25x$, where $x$ is in meters. Assuming the end at $B$ is suddenly set to $0$, then, setting $t=0$ at that instant, you'll have the new problem $$u_{t}(x,t)=u_{xx}(x,t),\;\;\; 0 \le x \le 2,\;\; t \ge 0,\\ u(0,t)=u(2,t)=0,\;\;\; t \ge 0,\\ u(x,0)=25x,\;\;\; 0 \le x < 2.$$ The idea is that you instantly set $u(2,0)=0$, which still leaves $u(x,0)=25x$ for $0 \le x < a$. Of course that's out of equilibrium, which is why you must solve a new heat equation. I think that's a reasonable intepretation based on the description. You'll want a solution of the form $$u(x,t) =\sum_{n=1}^{\infty}C_{n}\sin(n\pi x/2)e^{-n^{2}\pi^{2}c^{2} t/4}.$$ The $n\pi x/2$ comes from making sure that $\sin(n\pi x/2)=0$ at $x=2$ for all $n\ge 1$. Differentiating twice in $x$ and multiplying by $c^{2}$ must give the same thing as differentiation once in $t$. So the exponent of $e$ must be $-c^{2}(n\pi/2)^{2}t$. (Check my constants; I'm always getting things like that wrong.) The only missing piece is to make sure that $u(x,0)=25x$ by expanding $25x$ in a Fourier sine series. So you need to find the constants $C_{n}$ such that $$u(x,0)=\sum_{n=1}^{\infty}C_{n}\sin(n\pi x/2).$$ Using orthogonality of the $\sin$ functions (which you do have,) $$\int_{0}^{2}(25x)\sin(n\pi x/2)\,dx = C_{n}\int_{0}^{2}\sin^{2}(n\pi x/2)\,dx.$$ You're wanting to add the extra $25x$ in, but that will just lead to the previous steady state solution because all of the coefficients of the separated solutions must be 0 in order to match $u(x,0)=25x$. And that solution won't satisfy $u(2,t)=0$ for $t > 0$.