2
$\begingroup$
The hybrid system that I am solving
pfun = ParametricNDSolveValue[{y''[t] == -9.8 bounce[t], 
        y[0] == height, y'[0] == 0, bounce[0] == 1, 
        WhenEvent[y[t] == 0, 
         If[Abs[y'[t]] > 10^-6, 
          y'[t] -> -0.7 y'[t], {bounce[t], y'[t]} -> {0, 0}]]}, 
       y[t], {t, 0, 4}, {height}, DiscreteVariables -> bounce];
Plot[Evaluate[Table[pfun[height], {height, 1, 5, .2}]], {t, 0, 4},PlotRange -> All]

Result First run, result

Then I run the following:

Plot[Evaluate[Table[pfun'[height], {height, 1, 5, .2}]], {t, 0, 4}, 
 PlotRange -> All]

Result: Sensitivity

Now I rerun

Plot[Evaluate[Table[pfun[height], {height, 1, 5, .2}]], {t, 0, 4}, 
 PlotRange -> All]

to get New simulation

Why are these results different. Please help.

$\endgroup$
2
$\begingroup$

Try your second picture with this command:

Plot[Evaluate[Table[D[pfun[height], t], {height, 1, 5, .2}]], {t, 0,4}, PlotRange -> All]

enter image description here

Then repeating the first plot givse the same picture as it was:

Plot[Evaluate[Table[pfun[height], {height, 1, 5, .2}]], {t, 0, 4}, PlotRange -> All]

enter image description here

$\endgroup$
  • $\begingroup$ Could you please explain what makes this different? $\endgroup$ – q than a Aug 12 at 20:51
  • $\begingroup$ pfun' means take derivative w.r.t. parameter, i.e. height in your case.I supposed you want to see dependance of derivative on time, so I changed this to explicit differenciation w.r.t. time t. I don't understand what's going on when you take derivative w.r.t. parameter, MMA somehow changes pfun after that. The same effect can be seen if you just take pfun'[1], then repeat first Plot---it changed. I think you better ask Wolfram support, probably this is a bug or misunderstanding. $\endgroup$ – Alx Aug 13 at 4:48
  • $\begingroup$ Interesting answer, thank you. But, No, I actually want the derivative with respect to the parameter height varied as a function of time.That is, (pfun' w.r.t height)[t] as a function of time. $\endgroup$ – q than a Aug 13 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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