Backslide introduced in 9.0, persisting through 11.0.1
I try to solve a boundary value problem of coupled ODEs. For reference, when I solve this set of equations it works without any problems:
eq1 = {y'[x] == Piecewise[{{z[x], x < 5}, {y[x], x > 5}}]};
eq2 = {z'[x] == Piecewise[{{2 z[x] + 1, x < 5}, {2 y[x] + 1, x > 5}}]};
eqs = {eq1, eq2, y[0] == 1, z[10] == 0};
sol1 = NDSolve[eqs, {y, z}, {x, 0, 10},
Method -> {"Shooting",
"StartingInitialConditions" -> {y[0] == 1, z[0] == 1}}]
When I try to use more than 2 sections in the piecewise function I receive the following error:
eq1 = {y'[x] ==
Piecewise[{{z[x], x < 5}, {y[x], 8 > x > 5}, {2 z[x], x > 8}}]};
eq2 = {z'[x] == Piecewise[{{2 z[x] + 1, x < 5}, {2 y[x] + 1, x > 5}}]};
eqs = {eq1, eq2, y[0] == 1, z[10] == 0};
sol1 = NDSolve[eqs, {y, z}, {x, 0, 10},
Method -> {"Shooting",
"StartingInitialConditions" -> {y[0] == 1, z[0] == 1}}]
NDSolve::bvdisc: NDSolve is not currently able to solve boundary value problems with discrete variables. >>
I searched for a solution to this error online but non of the offered solutions helped. I don't understand why mathematica reads at as discrete variables when more than 2 sections are included. Same error appears whenever a boundary of the form a<x<b is set in the piecewise function. It is important to note that for initial boundary problems, there are no issues. For example:
eq1 = {y'[x] ==
Piecewise[{{z[x], x < 5}, {y[x], 8 > x > 5}, {2 z[x], x > 8}}]};
eq2 = {z'[x] == Piecewise[{{2 z[x] + 1, x < 5}, {2 y[x] + 1, x > 5}}]};
eqs = {eq1, eq2, y[0] == 1, z[0] == 0};
sol1 = NDSolve[eqs, {y, z}, {x, 0, 10}]
Yields
{{y -> InterpolatingFunction[{{0., 10.}}, <>],
z -> InterpolatingFunction[{{0., 10.}}, <>]}}
Does anyone have a solution to this?
Thanks in advance.


NDSolveimplements discontinuities with discrete variables forPiecewisewith more than two pieces, not counting the default. This approach may solve some problems, but causes one here. Why do you consider this a bug, since there is a proper warning, instead of it being a limitation? – Michael E2 Dec 14 '16 at 13:49NDSolvedoesn't output a wrong answer in this case. BTW you meanNDSolveis trying to handle the discontinuity withDiscreteVariablesin this case? (At least in v9 the warningbvdiscisn't documented at all. ) Maybe you can elaborate a little with an answer? – xzczd Dec 14 '16 at 14:31{state} = NDSolve`ProcessEquations[<ndsolve code>]and withstate["NumericalFunction"]andstate["Variables"]. Image: http://i.stack.imgur.com/OWNZ8.png – Michael E2 Dec 14 '16 at 14:37