gpt4 book ai didi

wolfram-mathematica - 为什么这个 pde 会给出 Boundary 和初始条件不一致的错误? (一维热pde)

转载 作者:行者123 更新时间:2023-12-01 01:21:44 24 4
gpt4 key购买 nike

我一直盯着这个简单的 pde 过去 20 分钟,但找不到为什么我会收到这个错误

Boundary and initial conditions are inconsistent

这是标准的一维热方程
 eq = Derivative[2, 0][u][x, t] == Derivative[0, 1][u][x, t]

和边界条件是(注意它们都是空间导数)
u'(0,t)=0     (derivative here w.r.t.  x )
u'(Pi,t)=0 (derivative here w.r.t. x )

和初始条件是
u(x,0) = cos(2 x) 

所以在初始条件下, u'(x,0) = -2 sin(2 x) ,在 x=0 处都为零和 x=Pi .

所以在我看来与边界条件一致,对吗?或者我错过了什么?

这是实际的 Mathematica 代码:
ClearAll[u, x, t]
eq = Derivative[2, 0][u][x, t] == Derivative[0, 1][u][x, t]

sol = NDSolve[{eq,
Derivative[1, 0][u][0, t] == 0,
Derivative[1, 0][u][Pi, t] == 0,
u[x, 0] == Cos[2 x]},
u, {t, 0, 12}, {x, 0, Pi}
]

我有一种感觉,因为它是一个数值求解器,在上面使用 Pi,变成 Real Pi=3.1415...所以在这个值上,初始条件和边界条件不匹配? (某处浮点比较?)

我从帮助 ref/message/NDSolve/ibcinc 中知道解决此类错误的技巧但我的问题实际上是为什么我首先会收到此错误,因为从表面上看,它们是一致的。如果是由于 Pi 的浮点问题,那么如何解决?我尝试使用帮助中显示的技巧(即使用 exp(-1000 t) 但没有帮助消除此错误。

问题:为什么我会收到此错误消息?

版本 8.04,在 Windows 上。

实际上,我一直在尝试在此处显示此解决方案(也使用 Mathematica)

http://en.wikipedia.org/wiki/File:Heatequation_exampleB.gif

但是上面示例中显示的 BC 和 IC 也给了我这个错误,所以我在 BC 中进行了更改,希望它们现在变得一致。

谢谢。

编辑(1)

这是我用来绘制解决方案图的命令,看起来没问题
eq = Derivative[2, 0][u][x, t] == Derivative[0, 1][u][x, t]
sol = u /.
First@NDSolve[{eq, Derivative[1, 0][u][0, t] == 0,
Derivative[1, 0][u][Pi, t] == 0, u[x, 0] == Cos[2 x]},
u, {t, 0, 1.5}, {x, 0, Pi}]
Animate[Plot[sol[x, t], {x, 0, Pi},
PlotRange -> {{0, Pi}, {-1, 1}}], {t, 0, 1.5}]

编辑(3)

我仍然有点困惑(也没有喝咖啡,这无济于事)。

我更改了 IC,使其不再是衍生品,因此 IC(非衍生品)现在与 BC 一致(但它们保留为衍生品)。但我仍然得到同样的错误:
eq = Derivative[2, 0][u][x, t] == Derivative[0, 1][u][x, t]
sol = u /.
First@NDSolve[{eq,
Derivative[1, 0][u][0, t] == 0,
Derivative[1, 0][u][Pi, t] == 0,
u[x, 0] == Sin[2 x]},
u, {t, 0, 1.5}, {x, 0, Pi}
]

NDSolve::ibcinc: Warning: Boundary and initial conditions are inconsistent. >>

绘制时,该解决方案也显示正常
Animate[Plot[sol[x, t], {x, 0, Pi}, 
PlotRange -> {{0, Pi}, {-1, 1}}], {t, 0, 1.5}]

这个问题需要什么IC来消除这个错误,还是必须只使用必要的BC?并且还使用非衍生IC,只有在那之后,我才担心一致性部分?

最佳答案

Szabolcs 给出了正确的提示(参见 http://reference.wolfram.com/mathematica/tutorial/NDSolvePDE.html 中的不一致边界条件部分)

eq = Derivative[2, 0][u][x, t] == Derivative[0, 1][u][x, t]
sol = u /.
First@NDSolve[{eq, Derivative[1, 0][u][0, t] == 0,
Derivative[1, 0][u][Pi, t] == 0, u[x, 0] == Cos[2 x]},
u, {t, 0, 1.5}, {x, 0, Pi},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid",
"MinPoints" -> 100}}]

我提出了一个建议,将教程的链接添加到 NDSolve::ibcinc 消息页面。

关于wolfram-mathematica - 为什么这个 pde 会给出 Boundary 和初始条件不一致的错误? (一维热pde),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8788728/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com