Solving $u_t+2u_x=0$ I have to solve: $u_t+2u_x=0,$ with $u(x,0)=x, x \ge 0$ and $u(0,t)=t, t \ge 0.$ Setting $p=x-2t, q=t,$ I have $u_p=0,$ so $u=f(p)=f(x-2t).$ Then I can’t apply the initial values, I need a help
 A: Synthesizing what Cesareo has done and the comments from mattos, the general idea is that since we know that
$$u(x,t) = f(x-2t),$$
then although $x \geq 0$ and $t \geq 0$ (I'm assuming this is the domain in which you are solving the equation, given your initial data), $f$ can still take negative inputs if $x < 2t$.
Now, we apply the initial data as follows. For $x \geq 0$, we have
$$u(x,0) = f(x - 2(0)) = f(x) = x$$
where the last equality is obtained by substituting the given initial data. Note that since this is only true for $x \geq 0$, this means that the function $f$ is basically $f(s) = s$ for $s \geq 0$.
For the other initial data, for $t \geq 0$, we have
$$u(0,t) = f(0 - 2t) = f(-2t) = t.$$
Note that for this case, we are dealing with $t > 0$ and thus the argument in $f$ is now negative. Rewriting this, we have that $f$ is basically $f(s) = -\frac{1}{2}s$ for $s \leq 0$.
Summarizing the above, we have
$$u(x,t) = f(x - 2t) = \begin{cases} x - 2t &\text{ for } x - 2t \geq 0 \\ -\frac{1}{2}(x-2t) &\text{ for } x - 2t \leq 0\end{cases}. $$
This is consistent with the formula from Cesareo when written with Heaviside step functions.
(Note that the formula is consistent at $x = 2t$ since both cases give $f(0) = 0$.)
A: You can solve it with the help of Laplace transform.
After transforming we have
$$
s U(x,s)+2U_x(x,s)=x, \ \ U(0,s)= \frac{1}{s^2} 
$$
and solving this ODE for $x$ we have
$$
U(x,s) = \frac{s x+3 e^{-\frac{s x}{2}}-2}{s^2}
$$
and after inversion
$$
u(x,t) = 3 \left(t-\frac{x}{2}\right) \theta \left(t-\frac{x}{2}\right)-2 t+x
$$
where $\theta(\cdot)$ is the Heaviside step function.
A: Applying the characteristics you found
$$
u(x,t)=f(x-2t)=u(x-2t,0)=u(0,t-x/2).
$$
In the last two expressions, only one has both coordinates non-negative. Then apply the appropriate boundary condition
$$
u(x,t)=\begin{cases}x-2t&\text{for }x\ge 2t,\\t-x/2&\text{for }x<2t.\end{cases}
$$
