# NDSolve with piecewise boundary conditions

I am trying to solve two simultaneous partial differential equation for $$P[x,t]$$ and $$V[x,t]$$. I have a piecewise boundary condition for $$V[L,t]$$. When using that piecewise condition, I get the error

NDSolve::ndnum : Encountered non-numerical value for a derivative at t==0

However, I get a solution when I manually solve within the piecewise ranges.

Vout =
Piecewise[
{{1.1182586384 t, 0 <= t <= 1}, {1.11826, 1 <= t <= 14},
{644.41640535 (0.00173530 - 0.00173530 (-14 + t)), 14 <= t <= 15}}];

NDSolve[
{D[P[x, t], t] + 7.17358*^8 D[V[x, t], x] == 0,
D[V[x, t], t] + D[P[x, t], t]/1000 ==
Piecewise[
{{-0.00984252 Abs[V[x, t]] V[x, t], 0 < x < 3100},
{-0.00656168 Abs[V[x, t]] V[x, t], 3100 < x < 5800},
{-0.02249719 Abs[V[x, t]] V[x, t], 5800 < x < 5809.144}}],
V[x, 0] == 0., P[x, 0] == 3.4474*^7, P[0, t] == 3.447*^7, V[5809.144, t] == Vout},
{P, V}, {x, 0, 5809.144}, {t, 0, 15}]

• Did you try defining Vout as a function? Specifically use Vout[t_?NumericQ]:=... to make sure it is only evaluated with numeric values – Eric William Smith Mar 21 at 3:44

The problem is that by limiting the domain of Vout to 0 <= t < 15, its derivative becomes Indeterminate at the boundaries t = 0, 15: We can fix it by extending the definition of Vout beyond the time interval. The extension won't be used, except in values of its derivative at the endpoints of the time interval.

Clear[x, t, V, P];
Vout = Piecewise[{
{1.1182586384 t, t <= 1},
{1.11826, 1 <= t <= 14},
{644.41640535 (0.00173530 - 0.00173530 (-14 + t)), 14 <= t}}];

NDSolve[{
D[P[x, t], t] + 7.17358*^8 D[V[x, t], x] == 0,
D[V[x, t], t] + D[P[x, t], t]/1000 == Piecewise[{
{-0.00984252 Abs[V[x, t]] V[x, t], 0 < x < 3100},
{-0.00656168 Abs[V[x, t]] V[x, t], 3100 < x < 5800},
{-0.02249719 Abs[V[x, t]] V[x, t], 5800 < x < 5809.144}}],
V[x, 0] == 0., P[x, 0] == 3.4474*^7, P[0, t] == 3.447*^7, V[5809.144, t] == Vout},
{P, V}, {x, 0, 5809.144}, {t, 0, 15}] 