# DAE with NDSolve -monitor numerical noise

I have a very 2d non-linear differential algebraic equation I'm trying to solve with NDSolve.

The solution seems fine, but There are some numerical issues I cannot manage to control, and I don't know how to approach it.

Here is the example

f[x_, z_] := ((20 z)/(1 - Exp[-20 x z])/(
1 + (20 z)/(1 - Exp[-20 x z])) - (20 z Exp[-20 x z])/(
1 - Exp[-20 x z])/(
1 + (20 z Exp[-20 x z])/(1 - Exp[-20 x z]))) - z;
f[x_, y_, z_] := z - 0.1 (x - 1) (1 + 1/(4 y) Exp[(x - 1)/(5 y)]);
g[x_, y_] := 1 - y - y Exp[(x - 1)/(5 y)];

sol = NDSolve[{
f[x[t], z[t]] == 0,
x'[t] == f[x[t], y[t], z[t]], y'[t] == g[x[t], y[t]], x[0] == 1.9,
y[0] == 0.9}, {x[t], y[t], z[t]}, {t, 0, 100},
Method -> {"EquationSimplification" -> {Automatic,
"SimplifySystem" -> True}}];

Plot[{Evaluate[x[t] /. sol], Evaluate[y[t] /. sol],
Evaluate[z[t] /. sol]}, {t, 0, 10},
PlotLegends -> Placed[{"x(t)", "y(t)", "z(t)"}, {Right, Top}],
Frame -> True, FrameLabel -> {Style["t", FontSize -> 14, Black], ""}]

Plot[{Evaluate[z[t] /. sol]}, {t, 0, 10},
PlotLegends -> Placed[{"z(t)"}, {Right, Top}], Frame -> True,
FrameLabel -> {Style["t", FontSize -> 14, Black], ""}]

When I plot the three functions together, the solution seems fine. however when I plot $z(t)$ by itself, you can see that there is always noise.

How can I add a fixed step to the solution of the DAE, or somehow monitor that what that I'm doing is correct?

• Try PlotRange->All for the z plot. Apr 10, 2018 at 8:43
• @user21, It's still noisy, The solution is expected to converge smoothly to the constant value. Apr 10, 2018 at 8:45
• have you noticed that the y-range doesn't even give an indication of the size of the noise? To me it looks like that could well be within the expected numeric precision... Apr 10, 2018 at 8:48
• @AlbertRetey, is there I way I can verify that? Apr 10, 2018 at 8:49
• Well, then use PlotRange -> {0.94, 0.96}. Apr 10, 2018 at 8:49

This is well in the acceptable numerical noise regime:

Subtract @@ MinMax[Table[Evaluate[z[t] /. sol], {t, 0, 10, 0.01}]]
-3.606067700001603`*^-8

Set the NDSolve options

, AccuracyGoal -> 12, PrecisionGoal -> 12

to lower this if you think it is too much.

• So, if I understand correctly, the numerical noise is not the issue here. Apr 10, 2018 at 8:59
• @jarhead, No, I do not think so. It is just Plot that tries hard to show some action in the data. I would not worry about it. Apr 10, 2018 at 9:07