I am attempting to find an efficient (less computationally demanding than solving with numeric integration) solution for the 1D heat equation:
$u_t - \alpha u_{xx} = 0$
IC: $ u(x, 0) = 0$
BC 1: $-u_x(0, t) = 1$
BC 2: $u(L, t) = 0$
I have attempted to solve this using separation of variables and have arrived at
$u(x, t) = L - x -\sum_{n=1}^{\infty}A_n e^{-\lambda_n^2\alpha t} \cos(\lambda_n x)$
with $ \lambda_n = \frac{(2n-1)\pi}{2L}, n = 1, 2, \dots $ and $ A_n = \frac{{(2n-1)(L-1)} \pi \left(-1\right)^{n} - 2}{L \lambda_{n}^{2}} $
Unfortunately, this series does not seem to converge. I can show my working to arrive at the above if it is required, but I feel certain that this problem has been solved before, so any pointers would be appreciated.
I include the solution steps I took below:
Let's say \begin{align} u(x, t) = w(x, t) + v(x) \end{align} where $w$ is the transient solution and $v$ is the steady state solution. Now, clearly $v(x) = c(L - x)$. This satisfies BC2 directly. BC1 leads to $-u_x(0, t) = -v_x = c = 1$, so \begin{align} v(x) = L-x \end{align}
For the transient solution, we go back to original problem, which transforms simply to $w_t = \alpha w_{xx}$.
IC: $u(x, 0) = 0 = w(x, 0) + v(x) = w(x, 0) + L - x$, so $w(x, 0) = x-L$
BC1: $-u_x(0, t) = -(w_x(0, t) + v_x(x)) = -w_x(0, t) + 1 = 1$, therefore $w_x(0, t)=0$.
BC2: $u(L, t) = w(L, t) + v(L) = w(L, t) = 0$.
We assume that $w(x, t) = X(x)T(t)$, so that $w_t=XT'$ and $w_{xx} = X''T$. The original problem therefore becomes $XT'=\alpha X''T$, which leads to \begin{align} \frac{X''}{X} = \frac{1}{\alpha}\frac{T'}{T} = -\lambda^2 \end{align} since these can only be equal if they are constant. Other signs or zero value for the constant leads only to trivial solutions.
We now have two separate ODEs: \begin{align} X'' + \lambda^2X = 0 \quad \text{and} \quad T + \lambda^2 \alpha T' = 0 \end{align} The general solutions to these are \begin{align} X = c_1 \cos (\lambda x) + c_2 \sin(\lambda x) \quad \text{and} \quad Y=c_3e^{-\lambda^2\alpha t} \end{align} Therefore \begin{align} w &= XT \\ &= c_3e^{-\lambda^2\alpha t}[ c_1 \cos(\lambda x) + c_2 \sin(\lambda x) ] \\ &= e^{-\lambda^2\alpha t}[A \cos(\lambda x) + B \sin(\lambda x)] \end{align} Applying the boundary conditions: \begin{align} BC1: w_x(0, t) = 0 \rightarrow -e^{-\lambda^2\alpha t}(A \lambda {\sin(\lambda 0)} + B \lambda \cos(\lambda 0)) = 0 \rightarrow B=0 \end{align} So we know that $w = Ae^{-\lambda^2\alpha t}\cos(\lambda x)$ \begin{align} BC2: w(L, t) = 0 \rightarrow w = Ae^{-\lambda^2\alpha t}\cos(\lambda L) = 0 \end{align} Obviously there are infinitely many $\lambda$s that satisfy this condition, which we indicate by writing \begin{align} \lambda_n = \frac{(2n-1)\pi}{2L}, n = 1, 2, \dots \end{align} Since all these values are solutions to the original problem, but do not in general satisfy the boundary conditions individually, we assume that some linear combination of the solutions is the actual solution, and write \begin{align} w = \sum_{n=1}^\infty A_ne^{-\lambda_n^2\alpha t}\cos(\lambda_nx) \end{align}
We solve for $A_n$ from the initial condition: \begin{align} w(x, 0) = x - L = \sum_{n=1}^\infty A_n\cos(\lambda_nx) \end{align}
If we multiply by $\cos(\lambda_m x)$ (note the different subscript) and integrate along the length of the rod (0 to $L$), we find \begin{align} \int_0^L \cos(\lambda_m x)x - L\cos(\lambda_mx) \mathrm{d}x = A_n \sum_{n=1}^\infty \int_0^L \cos(\lambda_nx) \cos(\lambda_m x) \mathrm{d}x \end{align} The integral on the right vanishes except when $n=m$, so we have \begin{align} \int_0^L \cos(\lambda_n x)x\mathrm{d}x - L\int_0^L\cos(\lambda_nx) \mathrm{d}x = A_n \sum_{n=1}^\infty \int_0^L \cos^2(\lambda_nx) \mathrm{d}x \end{align} Which evaluates to \begin{align} \frac{L \lambda_{n} \sin(L \lambda_{n}) + \cos(L \lambda_{n}) - 1}{\lambda_{n}^{2}}% -\frac{L^{2} \sin(L \lambda_{n})}{\lambda_{n}}% =% A_n\frac{2L\lambda_n + \sin(2L\lambda_n)}{4\lambda_n} \end{align} We can solve for $A_n$ as \begin{align} A_n = -\frac{4 \, {\left({\left(L^{2} \lambda_{n} - L \lambda_{n}\right)} \sin\left(L \lambda_{n}\right) - \cos\left(L \lambda_{n}\right) + 1\right)}}{2 \, L \lambda_{n}^{2} + \lambda_{n} \sin\left(2 \, L \lambda_{n}\right)} \end{align} Applying trigonometric identites yields \begin{align} A_n = -\frac{2 \, {\left({\left(L^{2} \lambda_{n} - L \lambda_{n}\right)} \sin\left(L \lambda_{n}\right) - \cos\left(L \lambda_{n}\right) + 1\right)}}{L \lambda_{n}^{2} + \lambda_{n} \sin\left(L \lambda_{n}\right) \cos\left(L \lambda_{n}\right)} \end{align} But we found $\lambda_n$ by requiring $\cos(L\lambda_n)=0$, so \begin{align} A_n = -\frac{2 \, {\left({\left(L^{2} \lambda_{n} - L \lambda_{n}\right)} \sin\left(L \lambda_{n}\right) + 1\right)}}{L \lambda_{n}^{2}} \end{align}
Now we substitute our solution for $\lambda_n$ and simplify to find \begin{align} A_n = \frac{{(2n-1)(L-1)} \pi \left(-1\right)^{n} - 2}{L \lambda_{n}^{2}} \end{align}
