【问题标题】:Find zeros for solutions to differential equations in Mathematica在 Mathematica 中找到微分方程解的零点
【发布时间】:2011-10-02 00:47:17
【问题描述】:

给定以下代码:

s := NDSolve[{x''[t] == -x[t], x[0] == 1, x'[0] == 1}, x, {t, 0, 5 }]
Plot[Evaluate[{x[t]} /. s], {t, 0, 3}]

这绘制了微分方程的解。我将如何数值求解 x[t] 的零,其中 t 介于 0 和 3 之间?

【问题讨论】:

    标签: wolfram-mathematica differential-equations


    【解决方案1】:

    @rcollyer 回答了最初的问题。我正在回答您在对 rcollyer 的回答的第一条评论中发布的问题:

    但是如果我们的 s 改为 "s := NDSolve[{x'[t]^2 == -x[t]^3 - x[t] + 1, x[0] == 0.5}, x, {t, 0, 5}]" 然后 FindRoot 函数只返回一个错误,而绘图显示在 0.6 左右有一个零。

    所以:

    s = NDSolve[{x'[t]^2 == -x[t]^3 - x[t] + 1, x[0] == 0.5}, 
                 x, {t, 0, 1}, Method -> "StiffnessSwitching"];
    Plot[Evaluate[{x[t]} /. s], {t, 0, 1}]
    FindRoot[x[t] /. s[[1]], {t, 0, 1}]
    

    {t -> 0.60527}
    

    编辑

    回答rcollyer的评论,“第二行”来自平方导数,如:

    s = NDSolve[{x'[t]^2 == Sin[t], x[0] == 0.5}, x[t], {t, 0, Pi}];
    Plot[Evaluate[{x[t]} /. s], {t, 0, Pi}]
    

    来自:

    DSolve[{x'[t]^2 == Sin[t]}, x[t], t]
    (*
    {{x[t] -> C[1] - 2 EllipticE[1/2 (Pi/2 - t), 2]}, 
     {x[t] -> C[1] + 2 EllipticE[1/2 (Pi/2 - t), 2]}}
    *)
    

    【讨论】:

    • 第二行从何而来?
    【解决方案2】:

    FindRoot 有效

    In[1]:=  FindRoot[x[t] /. s, {t, 0, 3}]
    Out[1]:= {t -> 2.35619}
    

    【讨论】:

    • 但是如果我们的 s 是 "s := NDSolve[{x'[t]^2 == -x[t]^3 - x[t] + 1, x[0] == 0.5}, x, {t, 0, 5}]" 然后 FindRoot 函数只返回一个错误,而绘图显示在 0.6 左右有一个零。
    • @LiKun,我没提,但这里使用:=(SetDelayed)没有任何意义。每次访问s 时,它都会重新执行NDSolve,但对于您的系统,这不是必需的。改用=(Set),那么s只会被执行一次。
    • @LiKun 是什么错误?看起来有一个奇点可能导致错误
    • @FooBah,不可能有奇点,它是一个二阶线性微分方程,有通解a Sin[t] + b Cos[t]
    • @rcollyer 我指的是你的第二部分:x'[t]^2 == -x[t]^3 - x[t] + 1
    猜你喜欢
    • 2015-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多