首页 > 解决方案 > 如何在 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。我在这个问题上花了很多时间,仍然找不到答案,请帮助我。此致!

标签: wolfram-mathematicaode

解决方案


这些代码不起作用的原因是,mathematica 无法解决具有奇异点和有界条件的 ODES。我使用 python 编写 Ronge-Kutta 方法来解决问题并且它有效。人生苦短,我用python :>


推荐阅读