如何强制微分方程的变量为实数。警告引起的问题:“NDSolve::evfrf:”
当我使用以下代码对颂歌进行数值求解时,会出现名为“evfrf”的警告。
我想知道如何强制微分方程的变量为实数
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]]}]
警告消息:
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. >>
谢谢:)
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 :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该错误消息似乎是由
"EventCondition" -> 引起的仅 y'[t] >= 0
部分。我不知道问题出在哪里,但考虑到您想将事件 (y[t]==0) 限制为向上的段落 (y'[t]>0),您可以将该部分替换为 <代码>“方向”-> 1 其作用相同。或者,您可以简单地使用 Off[NDSolve::evfrf] 关闭消息,因为它似乎对最终结果没有影响。
“方向”-> 1
方法产生与生成消息的原始事件相同的事件。The error message seems to be caused by the
"EventCondition" -> y'[t] >= 0
part only. I don't know what the problem is there, but given that you want to restrict events (y[t]==0) to passages going up (y'[t]>0), you can replace that part with"Direction" -> 1
which does the same.Alternatively, you could simply switch off the message using
Off[NDSolve::evfrf]
as it doesn't seem to make a difference in the final result. The"Direction" -> 1
method yields the same events as the original one which generated the messages.我认为这并不是答案在这些点上真正成为复数的问题。
以下不会报错。
问题在于尝试在
y'[t]
中查找零以及隐含的寻根过程的局限性。我尝试增加WorkingPrecision
和MaxSteps
但它没有消除错误。除非您真的关心第八位或随后的小数位,否则我建议不要担心此错误。
那些在数值分析方面比我更专业的人可能会不同意,但在我工作的领域,我们通常对百分比变化的小数点后第一位(级别的小数点后第三位)之后的任何数据的准确性没有任何信心。
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 theWorkingPrecision
and theMaxSteps
but 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).
使用EventLocator 重要吗?是否可以求解 y' 然后对其应用 FindRoot?类似于:
is it important to use the EventLocator? is it possible to solve for y' and then apply FindRoot on it? something like: