How to find a reference temperature distribution? Heat flow with sources The textbook gives 
$$ \text{PDE: } u_{t}^{'} = ku^{''}_{xx} + Q(x,t)$$ with nonhomogeneous boundary conditions,
$$ \text{BC: } u(0,t) =A(t)\text{ and } u(L,t) = B(t).$$
The reference temperature distribution $r(x,t) = A(t) +\frac{x}{L}[B(t)-A(t)] $ is given without any explanation of how to get it.
Is there a general procedure to find the reference temperature distribution $r(x,t)$? Because if we have different B.C., the reference temperature distribution $r(x,t)$ would change. For example, 
$$ \text{BC: } u(0,t) =A(t) \text{ and } u^{'}_{x}(L,t) = B(t),$$
or
$$\text{BC: } u^{'}_{x}(0,t) =A(t) \text{ and } u(L,t) = B(t),$$
or
$$\text{BC: } u^{'}_{x}(0,t) =A(t) \text{ and } u^{'}_{x}(L,t) = B(t),$$
 A: Since a complete solution requires much time I just outline the solution.
The function $r(x, t)$ is required to homogenize the boundary conditions and coming from interpolation at the points $x=0$ and $x=L.$  Let us define the function $V(x,t)=u(x,t)-r(x,t)$ and reformulate the problem for $V$. Start with taking the derivatives: $u_t=V_t+r_t=V_t+A'(t)+\frac{x(A'(t)-B'(t)}{L}$ and $u_{xx}=V_{xx}$ since $r_{xx}=0$. Substituting these into the equation we get 
\begin{equation}
  V_t-kV_{xx}=R(x,t), \ \ \qquad (1)   
\end{equation} 
where $R(x,t)=Q(x,t)-k\big[A'(t)+\frac{x(A'(t)-B'(t)}{L}\big]$ (is the new inhomogeneous functio) with the initial condition \begin{equation}V(x, 0)=u(x,0)-r(x,0)=u_0(x)-\big[A(0)+\frac{x(A(0)-B(0)}{L}\big]=V_0(x), \ \ \qquad (2)
\end{equation}(I suppose that $u_0(x)$ is the initial condition for the given equation)
and with the zero boundary conditions 
\begin{equation}V(0, t)=u(0, t)-r(0,t)=0;\, V(L, t)= u(L, t)-r(L,t)=0. \ \ \qquad (3)
\end{equation}
Now we can solve problem (1)-(3) by eigenfunction expansions of $V$ and $R$:
 \begin{equation}
V(x, t)=\sum_{n=1}^\infty a_n(t)\sin\frac{n\pi x}{L} \ \ \qquad (5)
\end{equation}
\begin{equation}
R(x, t)=\sum_{n=1}^\infty b_n(t)\sin\frac{n\pi x}{L}. \ \ \qquad (5)
\end{equation}
Here the coeffients $b_n(t)$ is found by othogonality of eigenfunctions.
Inserting $V$ and $R$ into equation (1) provide a first order linear ODE for the coefficients $a_n(t)$:
\begin{equation}
\frac{da_n(t)}{dt}+k(\frac{n\pi x}{L})^2a_n(t)=b_n(t). \ \ \qquad (6)
\end{equation}
 In this case we will be need an initial condition to determine constant of integration after solving the DE. This is $a_n(0)$ which is obtained from $V(x,0)=V_0(x)=\sum_{n=1}^\infty a_n(0)\sin\frac{n\pi x}{L}.$ Sorry now I realized the types of your boundary conditions but after some modifications you can get your solution. A little bit about Lagrange interpolation: Suppose that $A$ and $B$ are just constants and $u$ is only a function of $x$, namely $u(0)=A$ and $u(L)=B$. Then by the Lagrange interpolation on the variable $x$ we have $u(x)=ax+b$ and hence $u(0)=A=b$ and $u(L)=B=aL+b$.So we get $b=A$ and $a=\frac{B-A}{L}$. Putting in $u$ we find $u(x)=\frac{B-A}{L}x+A $.Since we just use interpolation w.r.to $x$ time dependence of $A$ and $B$ dont change anythin. This is a way which is used to convert nonhomogeneous boundary conditions to homogeneous ones.
