When I numerically solving a ode with the following code, warnings named “evfrf” prompted.
I am wondering how to force variables of differential equations to be Real numbers
NDSolve[{y''[t] + .1 y'[t] + Sin[y[t]] == 0, y'[0] == 1,
y[0] == 0}, y, {t, 0, 20},
Method -> {"EventLocator", "Event" -> y[t],
"EventCondition" -> y'[t] > 0,
"EventAction" :> Print[t, ", ", y[t], ", ", y'[t]]}]
warning message:
NDSolve::evfrf:
The event function did not evaluate to a real number somewhere
between t = 1.5798366385128957` and t = 1.6426647495929725`,
preventing FindRoot from finding the root accurately. >>
Thanks 🙂
I don’t think this is an issue of the answer genuinely being a complex number at those points.
The following does not give an error.
The issue is the attempt to find the zero in
y'[t]and limitations in the implied root-finding process. I tried increasing theWorkingPrecisionand theMaxStepsbut it didn’t remove the error.Unless you really care about the eighth or subsequent decimal place, I would suggest not worrying about this error.
Those more expert than me in numerical analysis might disagree, but I work in a field where we usually don’t have any faith in the accuracy of any data past the first decimal place of a percentage change (third decimal place of a level).