# Plotting output from method of characteristics - travelling wave solutions

I am looking to plot the output of a DSolve for a quasi-linear first order ode with known boundary condition, which is solved using the Method of Characteristics.

In[1] sol =
DSolve[{D[u[t, x], t] + a D[u[t, x], x] == b - c u[t, x],
u[t, 0] == u0[t]}, u[t, x], {t, x}] // Simplify // ExpandAll

Out[1] {{u[t, x] ->
b/c - (b E^(-((c x)/a)))/c + E^(-((c x)/a)) u0[t - x/a]}}


I am unsure how to plot solutions given the functional representation u0[t - x/a], where a,b and c are known. u0 is also a known function of time and is defined at x = 0.

I am looking to do both 3D plots in x and t, as well as 2D plots for specific x or t values.

Edited to add: Although u0, a, b and c are known I don't want to have to specify them in the DSolve because I need to evaluate this many times over for different values.

EDIT: typo in the solution corrected.

• Do you have an expression for u0[t]? And sample values for a,b,c, and f? – MelaGo Apr 3 '19 at 6:48
• This is an example problem, simpler than the real one, to figure out the plotting. But essentially yes those values will be known. u0 can be any smooth (differentiable) function. One example would be u0 = t. a, b and c are constants, e.g. a = 2, b = 3 and c = 4. That f is a typo, which I will now correct. – Esme_ Apr 3 '19 at 7:11

There are many ways to do this, all is matter of convenience. I'd like to minimize nested lists, substitutions, global variable definitions, etc. So I would use DSolveValue for a start:

sol=DSolveValue[{
D[u[t,x],t]+a D[u[t,x],x]==b-c u[t,x],u[t,0]==u0[t]},
u[t,x],{t,x}]//Simplify//ExpandAll


$$-\frac{b e^{-\frac{c x}{a}}}{c}+e^{-\frac{c x}{a}} \text{u0}\left(t-\frac{x}{a}\right)+\frac{b}{c}$$

Then for example:

Plot3D[sol/.{a->2,b->3,c->4,u0->Sech},{x,-1,1},{t,0,1},PlotRange->All]


or something like this for 2D:

Plot[Evaluate[Table[sol/.{a->2,b->3,c->4,u0->Sech},
{t,0,1,.2}]],{x,-1,1},PlotRange->All]


note the need of Evaluate sometimes. For custom not built-in u0 you can use substitution of pure function or a head of custom preliminary defined function.

Of course to go further you can define:

sol[a_,b_,c_,u0_][x_,t_]=DSolveValue[{
D[u[t,x],t]+a D[u[t,x],x]==b-c u[t,x],u[t,0]==u0[t]},
u[t,x],{t,x}]//Simplify//ExpandAll


to get things very compact:

sol[1, 2, 3, Exp[#] Sec[#] &][x, t]


$$e^{t-4 x} \sec (t-x)-\frac{2 e^{-3 x}}{3}+\frac{2}{3}$$

also for differentiation, integration etc.:

Integrate[D[sol[1, 2, 3, Exp[#] Sec[#] &][x, t], x], t]


$$e^{-4 x} \left(-(3-3 i) e^{(1+i) t-i x} \, _2F_1\left(\frac{1}{2}-\frac{i}{2},1;\frac{3}{2}-\frac{i}{2};-e^{2 i (t-x)}\right)+2 t e^x-e^t \sec (t-x)\right)$$

Note possible separation of parameters from variables with currying f[...][...] for operator actions like:

sol[1, 2, 3, Sin] @@@ RandomInteger[10, {3, 2}]


$$\left\{\frac{2}{3}-\frac{2}{3 e^3}+\frac{\sin (8)}{e^3},\frac{2}{3}-\frac{2}{3 e^{24}}+\frac{\sin (1)}{e^{24}},\frac{2}{3}-\frac{2}{3 e^{21}}+\frac{\sin (1)}{e^{21}}\right\}$$

or definitions like

sol123Sin = sol[1, 2, 3, Sin];
Plot3D[sol123Sin[x,t],{x,-1,1},{t,0,1},PlotRange->All]


• I want to avoid having to solve for specific u0, a, b, and c values. I need to be able to evaluate for a large number of different values, and want to avoid having to resolve the DE hundreds or thousands of times. I'll clarify this in the original question. I'm without Mta today, but will see if I can adapt these with a post-defined values tomorrow. – Esme_ Apr 4 '19 at 0:30
u0[t_] = t;

a = 2; b = 3; c = 4;

sol = DSolve[{D[u[t, x], t] + a D[u[t, x], x] == b - c u[t, x],
u[t, 0] == u0[t]}, u[t, x], {t, x}]

Plot3D[u[t, x] /. sol, {x, 0, 1}, {t, 0, 1}]


Plot[u[t, x] /. sol /. {t -> 1}, {x, 0, 1}]