我在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 <=时,整个M [t]应该> 0 20我已经在这个问题上花了很多时间,但仍然找不到答案,请帮助我。
最好的问候!
答案 0 :(得分:0)
这些代码不起作用的原因是mathematica无法解决具有奇异点和有界条件的ODES。我使用python编写Ronge-Kutta方法来解决此问题,并且可以正常工作。寿命短,我用python:>