Bug introduced in 10.4.0.0 or earlier and fixed in 11.0.1.
Compare the two solution sets below: in the first one (x == False
), there are only 3 dependent variables while in the second one (x == True
), a dependent algebraic variable is introduced as r[t] == 5
(converting the ODE to a DAE). A DAE often requires a different NDSolve
method, here I used "EquationSimplification" -> {Automatic, "SimplifySystem" -> True}
which messes up the solution order as is apparent from the plots.
ClearAll[t, R, A, P, r, x];
eq = {
R'[t] == -.1 R[t],
A'[t] == .1 A[t],
P'[t] == 0,
If[x, r[t] == Sin[t], Nothing],
R[0] == 1, A[0] == 1, P[0] == 1
};
sol1 = Block[{x = False},
NDSolve[eq, {R, A, P}, {t, 0, 20}, DependentVariables -> {R, A, P}]];
sol2 = Block[{x = True},
NDSolve[eq, {R, A, P, r}, {t, 0, 20}, DependentVariables -> {R, A, P, r},
Method -> {"EquationSimplification" -> {Automatic,
"SimplifySystem" -> True}}]];
Grid[{
LogPlot[#[t] /. sol1, {t, 0, 20}, PlotLabel -> #] & /@ {R, A, P},
LogPlot[#[t] /. sol2, {t, 0, 20}, PlotLabel -> #] & /@ {R, A, P, r}
}]
Can anyone reproduce this bug?
(Mathematica 10.4.0.0, Windows 7, 64bits)
TechSupport filed an internal report acknowledging the wrong order of output.
DependentVariables -> ...
insol2
will also solve the issue. Ifr[t]
is to be regarded as an algebraic function it may be more robust to provide initial conditions, e.g.{ r[0] == 5, r[t] == 5 }
. $\endgroup$r
can be anyt
-dependent function likeSin[t]
, I only left it as a constant for the sake of simplicity. I've edited it into the post. $\endgroup$[bug]
as TS did not confirm it yet. $\endgroup$[bug]
tag from TS yet? $\endgroup$