1. ## Non-Homogeneous PDE

Use the method of eigenfunction expansion to solve $u_t = u_{xx} + e^{-t} \sin (3x)$ with boundary conditions $u(0,t) = u(\pi,t) = 0$ and initial condition $u(x,0) = f(x)$

I think I might have stuffed my solution here, but I don't know.
Would someone please be able to help me out?

Base a trial solution on the solution to the homogeneous problem

$\displaystyle u_t = u_{xx} \ \Rightarrow \ u(x,t) = \sum_1^{\infty} b_n \sin(\frac{n \pi x}{L})$

$\displaystyle \frac{\partial u}{\partial t} = \sum_1^{\infty} \dot{b_n(t)} \sin (\frac{n \pi x}{L}) , \frac{\partial u}{\partial x} = \sum_1^{\infty} b_n(t) \frac{n \pi}{L} \cos (\frac{n \pi x}{L}) , \frac{\partial^2 u}{\partial x^2} = - \sum_1^{\infty} b_n(t) \frac{n^2 \pi^2}{L^2} \sin (\frac{n \pi x}{L})$

Now represent $q(x,t)$ as a series of the particular eigenfunctions

Let

$\displaystyle q(x,t) = \sum_1^{\infty} c_n (t) \sin (\frac{n \pi x}{L})$

i.e. Let $\displaystyle c_n(t) = \frac{2}{L} \int_0^L \sin (\frac{n \pi x}{L}) q(x,t) \ dx)$

Sub into PDE $\displaystyle u_t = u_{xx} + q(x,t)$

$\displaystyle \sum_1^{\infty} \dot{b_n(t)} \sin (\frac{n \pi x}{L}) = - \sum_1^{\infty} b_n(t) \frac{n^2 \pi^2}{L^2} \sin (\frac{n \pi x}{L}) + \sum_1^{\infty} c_n (t) \sin (\frac{n \pi x}{L})$

$\displaystyle \sum_1^{\infty} \big( \dot{b_n(t)} + b_n(t) \frac{n^2 \pi^2}{L^2} - c_n(t) \big) \sin (\frac{n \pi x}{L}) = 0$

The only way for this to be true for all $x$ is if

$\displaystyle \dot{b_n}(t) +b_n(t) \frac{n^2 \pi^2}{L^2} = c_n(t)$

This is a first order ODE.....so use an integrating factor

$\displaystyle e^{\int \frac{n^2 \pi^2}{L^2} dt} = e ^{\frac{n^2 \pi^2}{L^2}t}$

$\displaystyle e^{k_n t}$ where $\displaystyle k_n = \frac{n^2 \pi^2}{L^2}$

$\displaystyle \dot{b_n} + k_n b_n = c_n$

Multiply by $e^{k_n t} \ \Rightarrow$

$\displaystyle \dot{b_n}e^{k_n t} + k_n e^{k_n t} b_n = c_n e^{k_n t}$

$\displaystyle \frac{d}{dt} \Big( b_n e^{k_n t} \Big) = c_n e^{k_n t}$

$\displaystyle \int_0^t \frac{d}{d \tau} \Big( b_n(\tau) e^{k_n \tau} \Big) \ d \tau = \int_0^t c_n (\tau) e^{k_n \tau} \ d \tau$

$\displaystyle b_n(t) e^{k_n t} - b_n(0) = \int_0^t c_n (\tau) e^{k_n \tau} \ d \tau$

In order for $u(x,0) = f(x)$ choose

$\displaystyle b_n(0) = \frac{2}{L} \int_0^L \sin \Big( \frac{n \pi x}{L} \Big) f(x) dx$

Skipping a few lines of calculation...

$\displaystyle u(x,t) = \sum_1^{\infty} b_n(0) \sin \Big( \frac{n \pi x}{L}\Big) e^{-k_n t} + \sum_1^{\infty} \int_0^t c_n(\tau) e^{- k_n (t - \tau)} \ d \tau \sin \Big( \frac{n \pi x}{L} \Big)$

2. I think what you have here is OK but an overkill. First off, you interval is $[0,\pi]$ with the BCs $u(0,t) = u(\pi,t) = 0$ so your eigenfunction expansion should be

$u(x,t) = \displaystyle \sum_1^{\infty} b_n \sin( n x)$. Next when you sub. into your PDE you obtain

$\displaystyle \sum_1^{\infty} \dot{b_n} \sin( n x) = \sum_1^{\infty} - n^2 b_n \sin( n x) + e^{-t} \sin 3 x$

which gives

$\dot{b_n} = -n^2 b_n \;\text{for}\; n \ne 3
$

$
\dot{b_n} = -n^2 b_n + e^{-t} \; \text{for}\; n = 3
$

Each of which you can solve separately. This should get you started.