Question:
Find the solution to $$u_t+u_x=-u+g(x,t),~-\infty<x<\infty, 0<t, $$$$u(x,0)=f(x)$$
My attempt using method of characteristics: $$ x_0=s,~t_0=0,~u_0=f(s)$$ $$\frac{dx}{d\tau}=1,~\frac{dt}{d\tau}=1,~\frac{du}{d\tau}=-u+g(x,t)$$ Solving for $\tau$ and $s$: $$\tau=t,~s=x-t$$ Now when I solve for u: $$\int_{f(s)}^{u}\frac{du}{-u+g(x,t)}=\int_0^\tau d\tau=t$$ Treating g as a constant with respect to u, I get $$-\ln(-u+g(x,t))+\ln(-f(x-t)+g(x,t))=t$$ $$u=g(x,t)+\frac{f(x-t)-g(x,t)}{e^t}$$
However, the answer gives $$u=\frac{f(x-t)+\int_0^tg(\xi+x-t,\xi)d\xi}{e^t}$$
May I know where did I go wrong in my attempt?
The solution for $u$ is not right. To solve $\frac{du}{d\tau}=-u+g(x,t)$, consider it as a first order linear ODE. It is not separable, since $g(x,t)$ also involves $\tau$, so you cannot simply divide and integrate. $$\frac{du}{d\tau}=-u+g(x,t)\\ \frac{du}{d\tau}+u=g(x,t)\\ e^{\tau}(\frac{du}{d\tau}+u)=e^{\tau}g(x(\tau),t(\tau)) \quad \text{ multiplying by an integration factor }e^{\tau}\\ \frac{d(e^{\tau}u)}{d\tau}=e^{\tau}g(x(\tau),t(\tau))\\ e^{\tau}u-f(x_0)=\int^{\tau}_0 e^{\xi}g(x(\xi),t(\xi))\,d\xi.$$
Now you can proceed to get the answer (I believe your answer missed a $e^{\xi}$ in the integral): $$u=\frac{f(x-t)+\int_0^t e^{\xi}g(\xi+x-t,\xi)d\xi}{e^t}$$