wolfram-mathematica - 如何在 Mathematica 中解决这个 NDSolve 问题
问题描述
我在 Mathematica 中使用 NDSolve 解决 ODE 问题时发现了一个令人困惑的问题,代码如下:我尝试过'Clear[Derivative]'
并重新启动内核,但这些方法不起作用。代码:
Clear[Derivative];
ClearSystemCache;
r = 0.3; a = 3; delta = 0.45; M0 = 0.975; T = 20;
u[t] = 0.5*l[t]*delta*M[t];
eql1 = M'[t] == r*M[t] Log[1/M[t]] - u[t]*delta*M[t];
eql2 = l'[t] == -2 *a *M[t] - l[t]* r *Log[1/M[t]] + l[t]*r -
l[t]*u[t]*delta;
condition = {M[0] == M0, l[T] == 0};
sol = NDSolve[Flatten@{{eql1, eql2}, condition}, {M, l}, {t, 0, 20}]
The result is as follows:
Power::infy: Infinite expression 1/0. encountered.
Infinity::indet: Indeterminate expression 0. \[Infinity] encountered.
Power::infy: Infinite expression 1/0. encountered.
Infinity::indet: Indeterminate expression 0. \[Infinity] encountered.
Power::infy: Infinite expression 1/0. encountered.
General::stop: Further output of Power::infy will be suppressed during this calculation.
Infinity::indet: Indeterminate expression 0. ComplexInfinity encountered.
General::stop: Further output of Infinity::indet will be suppressed during this calculation.
NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0.
我不知道为什么会有“ non-numerical value for a derivative at t == 0
”,t==0 时不应该有非数值,当 t<=20 时整个 M[t] 应该 >0。我在这个问题上花了很多时间,仍然找不到答案,请帮助我。此致!
解决方案
这些代码不起作用的原因是,mathematica 无法解决具有奇异点和有界条件的 ODES。我使用 python 编写 Ronge-Kutta 方法来解决问题并且它有效。人生苦短,我用python :>
推荐阅读
- android - 每当从 Play 商店启动并放回后台时,Top Activity 都会被删除
- python - 如何将.txt文件从多个文件夹复制到python中的excel
- arrays - PHP7.4 问题-count():参数必须是数组或实现的对象(NULL)
- python - NumPy:将二进制文件读入现有数组
- firebase-authentication - SwiftUI + Firebase 重新验证无密码登录错误
- git - 无法在 Gitlab 中的此项目中创建受保护的分支
- angular - 在星云步进器的任何一步中移动
- mysql - 使用 any_value 后也得到错误 ORDER BY 子句的表达式 #1 不在 GROUP BY 子句中并且包含非聚合列
- java - 线程“AWT-EventQueue-0”中的异常 java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlOptions.put(Ljava/lang/Object;)V
- c# - 如何设置,如果循环达到最大数量,它会重新开始