I am working through the first chapter of "Finite Difference Schemes and Partial Differential Equations" by Strikwerda and I am confused by this inhomogeneous problem (1.1.2):
Show that $$ u_t +au_x = f(t,x) $$ with $u(0,x) = 0$, $a>0$ a positive constant, and $$ f(t,x) = \begin{cases} 1, & \text{for } -1\leq x\leq 1\\ 0, & \text{otherwise.} \end{cases} $$ has solution $$ u(t,x) = \begin{cases} \frac{1+x}{a}, & \text{if} & -1 \leq x \leq 1 &\text{and} & x-at\leq -1; \\ t, & \text{if} & -1 \leq x \leq 1 &\text{and} & -1 \leq x-at; \\ \frac{2}{a}, & \text{if} & x \geq 1 &\text{and} & x-at\leq -1; \\ \frac{1-x+at}{a}, & \text{if} & x \geq 1 &\text{and} & -1 \leq x-at\leq1; \\ 0, & \text{otherwise} \end{cases} $$
My initial approach was to use the formula derived for a general problem with $u(x,0) = u_0(x)$ given by $ u(t,x) = u_0(x-at) + \int_0^t f(s, x-a(s-t))\,ds$. For this particular problem, the formula would be $u(t,x) = \int_0^t f(s, x-a(s-t))\,ds$, but I am struggling on how to treat the integral given the source $f$ is limited to a region.
Is it possible to use this general formula by carefully considering the region in $u$-$t$ space to integrate? If so, any guidance on how? If not, any guidance as how to proceed? I have always had a difficult time with method of characteristics, so any help is appreciated.