捕获 Mathematica 警告/错误而不显示它们
我在 Mathematica 中遇到涉及 NDSolve 的问题,我使用不同的参数值运行了多次。对于其中一些值,解会导致奇点,并且 NDSolve 会发出 NDSolve::ndsz 警告或其他相关警告。
我只想捕捉这些警告,抑制它们的显示,并跟踪这些特定参数值出现问题的事实。我想到了以下选项(这两个选项都没有真正起作用):
- 我知道我可以使用
Check
确定命令是否导致警告或错误。但是,仍然会显示警告。如果我使用Off
将其关闭,Check
也无法报告警告。 - 可以使用 EventLocator 方法停止 NDSolve,因此我可以检查函数或其导数的值是否非常大,并在这种情况下停止计算。然而,在实践中,这仍然会时不时地产生警告,大概是因为步长有时可能太大,以至于 NDSolve 警告在我的
Event
发生之前触发。
还有其他建议吗?
I have a problem involving NDSolve in Mathematica, which I run multiple times with different values of the parameters. For some of these values, the solution results in singularities and NDSolve warns with NDSolve::ndsz or other related warnings.
I would simply like to catch these warnings, suppress their display, and just keep track of the fact that a problem occurred for these particular values of the parameters. I thought of the following options (neither of which really do the trick):
- I know I can determine whether a command has resulted in a warning or error by using
Check
. However, that will still display the warning. If I turn it off withOff
theCheck
fails to report the warning too. - It is possible to stop NDSolve using the
EventLocator
method, so I could check for very large values of the function or its derivatives and stop evaluation in that case. However, in practice, this still produces warnings from time to time, presumably because the step size can sometimes be so large that the NDSolve warning triggers before myEvent
has taken place.
Any other suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您将
Check
与Quiet
包装在一起,那么我相信一切都应该按您的意愿进行。例如,您可以抑制特定消息Power::indet
但仍显示其他消息
If you wrap the
Check
withQuiet
then I believe that everything should work as you want. For example, you can suppress the specific messagePower::indet
but other messages are still displayed
一起使用 Quiet 和 Check 可以发挥作用:
Using Quiet and Check together works:
也许您希望重定向消息?这几乎是从该页面逐字复制的。
Perhaps you wish to redirect messages? This is copied almost verbatim from that page.