2
$\begingroup$

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.

enter image description here

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

$\endgroup$
9
  • 1
    $\begingroup$ Try PlotRange->All for the z plot. $\endgroup$
    – user21
    Apr 10, 2018 at 8:43
  • $\begingroup$ @user21, It's still noisy, The solution is expected to converge smoothly to the constant value. $\endgroup$
    – jarhead
    Apr 10, 2018 at 8:45
  • 1
    $\begingroup$ 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... $\endgroup$ Apr 10, 2018 at 8:48
  • $\begingroup$ @AlbertRetey, is there I way I can verify that? $\endgroup$
    – jarhead
    Apr 10, 2018 at 8:49
  • $\begingroup$ Well, then use PlotRange -> {0.94, 0.96}. $\endgroup$
    – user21
    Apr 10, 2018 at 8:49

1 Answer 1

7
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ So, if I understand correctly, the numerical noise is not the issue here. $\endgroup$
    – jarhead
    Apr 10, 2018 at 8:59
  • 2
    $\begingroup$ @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. $\endgroup$
    – user21
    Apr 10, 2018 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.