Finding the heat equation (PDE) I have the terms:
$$\left\{\begin{array}{l l} u_t=u_{xx}, 0<x<1, t>0\\u(0,t)=1, u(1,t)=3, t>0\\ u(x,0)=2x+1-\sin(2\pi x), 0<x<1\end{array}\right.\ $$
And I should determine the heat equation. I can begin like this: $$ u(x,t)=f(x)g(t)\\u_t = u_{xx} \Rightarrow f(x)g'(t)=f''(x)g(t)\\\frac{g'(t)}{g(t)}=\frac{f''(x)}{f(x)}=\lambda$$
But then I'm stuck. Where should I go from here? I should probably solve HL and VL separately but is there some obvious knowledge about solving those that I should know? It seems to me that all the examples I have looked is doing some magic here... 
 A: Given ( slightly more general):
\begin{align}
u_{t} &= u_{xx}  \hspace{10mm} 0 \leq x \leq L , t \geq 0 \\
u(0,t) &= a , \, \, u(L, t) = b \\
u(x, 0) &= \frac{1}{L} + \frac{2x}{L} - \sin\left(\frac{2 \pi x}{L}\right)
\end{align}

The equation $u_{t} = u_{xx}$ can be solved, as stated, by letting $u(x,t) = f(t) \, g(x)$ for which
\begin{align}
g \, f_{t} = f \, g_{xx} \rightarrow \frac{f_{t}}{f} = - \lambda^{2} = \frac{g_{xx}}{g} 
\end{align}
This leads to the equations $f_{t} + \lambda^{2} f = 0$ and $g_{xx} + \lambda^{2} g = 0$. The solution for $f$ is seen to be $f(t) = e^{- \lambda^{2} t}$. The solution for $g$ is seen as $g(x) = A \cos(\lambda x) + B \sin(\lambda x)$. 

Initial conditions: $u(0,t) = a$ and $u(L,t) = b$ lead to $g(0) = a$ and $g(L) = b$. From this it is seen that
\begin{align}
g(0) &= a = A \\
g(L) &= b = A \cos(\lambda L) + B \sin(\lambda L).
\end{align} 
This leads to the equation to determine $\lambda$ as
\begin{align}
B \, \tan(\lambda L) = b \sec(\lambda L) - a.
\end{align}
Supposing this equation leads to solutions, let these values be given by $\lambda_{n}$, $0 \leq n \leq \infty$.

General solution:
The general solution is of the form
\begin{align}
u(x,t) = a \, e^{- \lambda_{0}^{2} t} +  \sum_{n=1}^{\infty} e^{-\lambda_{n}^{2} t} \left( a \cos(\lambda_{n} x) + B_{n} \sin(\lambda_{n} x) \right)
\end{align}
Now, for $t=0$, $u(x, 0) = 1/L + \frac{2x}{L} - \sin\left(\frac{2 \pi x}{L}\right)$ which leads to
\begin{align}
\frac{1}{L} - a + \frac{2x}{L} - \sin\left(\frac{2 \pi x}{L}\right) = \sum_{n=1}^{\infty} \left( a \cos(\lambda_{n} x) + B_{n} \sin(\lambda_{n} x) \right).
\end{align} 

Case for $a=b=0$
When $a=0$ the equations reduce to a more solvable case. From the initial conditions: $g(0) = 0$ and $g(L) = 0$ lead to $A = 0$ and $0 = B \sin(\lambda L)$. This leads to $\lambda L = n \pi$. The solution now becomes
\begin{align}
u(x,t) = \sum_{n=1}^{\infty} B_{n} \, \sin\left( \frac{n \pi x}{L} \right) \, e^{- \left( \frac{n \pi}{L} \right)^{2} \,t }.
\end{align}
Now, for $t=0$, $u(x, 0) = 1/L + \frac{2x}{L} - \sin\left(\frac{2 \pi x}{L}\right)$ which leads to
\begin{align}
\frac{1}{L} + \frac{2x}{L} - \sin\left(\frac{2 \pi x}{L}\right) = \sum_{n=1}^{\infty}  B_{n} \sin\left(\frac{n \pi x}{L}\right).
\end{align} 
The coefficients $B_{n}$ can be found by making use of the Fourier series integral
\begin{align}
B_{n} &= \frac{2}{L} \, \int_{0}^{L} \left[ \frac{1}{L} + \frac{2x}{L} - \sin\left(\frac{2 \pi x}{L}\right) \right] \, \sin\left(\frac{n \pi x}{L}\right) \\
&= \frac{2}{L} \left[ \frac{1 - (-1)^{n}}{n \pi} - \frac{2 L \, (-1)^{n}}{n \pi}  - \frac{L}{2} \delta_{n,2} \right].
\end{align}
This leads to the solution
\begin{align}
u(x,t) &= \frac{ 4 (1 + L) }{\pi \, L} \, \sin\left( \frac{\pi x}{L} \right) \, e^{- \frac{\pi^{2} t}{L^{2}}} - \frac{(2+\pi)}{\pi} \, \sin\left( \frac{2 \pi x}{L} \right) \, e^{- \frac{4 \pi^{2} t}{L^{2}}} \\
& \hspace{5mm} + \frac{1}{\pi} \sum_{n=3}^{\infty} \left[ \frac{1 - (1 + 2 L) (-1)^{n}}{n} \right] \, \sin\left( \frac{n \pi x}{L} \right) \, e^{- \left( \frac{n \pi}{L} \right)^{2} \,t }.
\end{align}
