In order to solve non-homogeneous heat equations, assume that $w(x,t)=u(x,t)+\phi(x)$, where $\phi$ is a function yet to be determined.
So, we've $u_{xx} = w_{xx} - \phi''$ and $u_{t} = w_{t}$. If we substitute this in to our equation, then we have to solve the new problem
$\begin{cases}
w_t - c^2 w_{xx} - c^2 \phi'' - \sin{5 \pi x} = 0\\
w(0,t) - \phi(0) = 0\\
w(1,t) = \phi(1) = 0\\
w(x,0) - \phi(x) = 4\sin{3\pi x} + 9\sin{7 \pi x}
\end{cases}
$
So we really want to choose $\phi$ so that $-c^2\phi^2 - \sin{5 \pi x} = 0$, the choice of $\phi = \frac{1}{25 \pi^2 c^2}\sin{5 \pi x}$ works. And so we want to solve the new equation:
$\begin{cases}
w_t - c^2 w_{xx} = 0\\
w(0,t) = 0\\
w(1,t) = 0\\
w(x,0) = 4\sin{3\pi x} +\frac{1}{25 \pi^2 c^2}\sin{5 \pi x} + 9\sin{7 \pi x}
\end{cases}
$
At this point, this should be easy to do, separation of variables yields that the resulting corresponding Fourier series is a sine series, and we can easily match what the coefficients according to our initial condition. We have
$$w(x,t) = \sum_{n=1}^{\infty} b_n e^{-(cn\pi)^2t}\sin{n\pi x}$$
Matching coefficients, we see $b_3 = 4$, $b_5 = \frac{1}{25 \pi^2 c^2}$, and $b_7 = 9$, and $b_n = 0$ otherwise.
Thus we have
$$w(x, t) = 4 e^{-(3c\pi)^2t}\sin{3\pi x} + \frac{1}{25 \pi^2 c^2} e^{-(5c\pi)^2t}\sin{5\pi x} + 9 e^{-(7n\pi)^2t}\sin{7\pi x}$$
Now, remember that $u(x, t) = w(x, t) - \phi(x)$, the full solution is
$$u(x, t) = 4 e^{-(3c\pi)^2t}\sin{3\pi x} + \frac{1}{25 \pi^2 c^2} e^{-(5c\pi)^2t}\sin{5\pi x} + 9 e^{-(7n\pi)^2t}\sin{7\pi x} - \frac{1}{25 \pi^2 c^2}\sin{5 \pi x}$$
Best Answer
FIrst solve the equation $$ u''=-\sin \pi x-\sin 2\pi x, $$ subject to the boundary conditions $$ u(0)=u(1)=0. $$ This problem has solution $$ u_{st}=\frac{1}{\pi^2}\sin \pi x+\frac{1}{2^2\pi^2}\sin 2\pi x. $$ Now put $u(x,t)=u_{st}+v(x,t)$. Make sure that you understand that $v(x,t)$ solves the problem $$ v_t=v_{xx},\\ v(0,t)=0,\\ v(1,t)=0,\\ v(x,0)=-u_{st}. $$ Note the initial condition.
Now you can solve it to find $$ v(x,t)=-\frac{1}{\pi^2}e^{-\pi^2 t}\sin \pi x-\frac{1}{2^2\pi^2}e^{-2^2\pi^2t}\sin 2\pi x. $$ Finally write $$ u(x,t)=\underbrace{v(x,t)}_{\mbox{transient part}}+\underbrace{u_{st}}_{\mbox{stationary part}} $$