Mathematica 二维热方程动画

发布于 2024-10-05 18:37:12 字数 731 浏览 2 评论 0原文

我正在努力绘制二维温度梯度图,但遇到了很多麻烦。我当前的方法是定义一个插值函数,然后尝试多次绘制它的图表,然后为该图表表设置动画。这是我到目前为止所得到的:

RT = 388.726919
R = 1
FUNC == NDSolve[{D[T[x, y, t], t] == 
RT*(D[T[x, y, t], x, x] + D[T[x, y, t], y, y]),

   T[x, y, 0] == 0,
   T[0, y, t] == R*t,
   T[9, y, t] == R*t,
   T[x, 0, t] == R*t,
   T[x, 9, t] == R*t},

  T, {x, 0, 9}, {y, 0, 9}, {t, 0, 6}]

所以前两个变量只是控制变化率。我正在求解的方程是基本的二维热方程,其中 dT/dt=a(d^2T/dx^2+d^2T/dy^2)。初始条件将所有内容设置为 0,然后将边缘定义为热变化源。现在它从 t=0 到 t=6 扫描 9x9 的块。

第二部分尝试为函数的运行提供动画效果。

ListAnimate[
Table[
   DensityPlot[T[x, y, t] /. FUNC, {x, 0, 9}, {y, 0, 9}, Mesh -> 9]
, {t, 0, 6}]
]

不幸的是,这不起作用,我正疯狂地试图找出原因。我首先认为它与插值函数有关,但现在我对动画代码的工作原理也不太有信心。有人有什么想法吗?

I'm working on mapping a temperature gradient in two dimensions and having a lot of trouble. My current approach is to define an Interpolating Function and then try to graph it a lot of times, then animate that table of graphs. Here's what I have so far:

RT = 388.726919
R = 1
FUNC == NDSolve[{D[T[x, y, t], t] == 
RT*(D[T[x, y, t], x, x] + D[T[x, y, t], y, y]),

   T[x, y, 0] == 0,
   T[0, y, t] == R*t,
   T[9, y, t] == R*t,
   T[x, 0, t] == R*t,
   T[x, 9, t] == R*t},

  T, {x, 0, 9}, {y, 0, 9}, {t, 0, 6}]

So the first two variables just control the rate of change. The equation I'm solving is the basic 2D heat equation, where dT/dt=a(d^2T/dx^2+d^2T/dy^2). The initial conditions set everything to 0, then define the edges as the source of the heat change. Right now it sweeps over a 9x9 block from t=0 to t=6.

The second part attempts to animate the function working.

ListAnimate[
Table[
   DensityPlot[T[x, y, t] /. FUNC, {x, 0, 9}, {y, 0, 9}, Mesh -> 9]
, {t, 0, 6}]
]

Unfortunately, this doesn't work, and I'm going crazy trying to figure out why. I first thought it had something to do with the Interpolating Function but now I'm not so confident that the animating code works either. Anyone have any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花期渐远 2024-10-12 18:37:12

只需快速检查一下:

RT = 1
R = 1
FUNC = NDSolve[{D[T[x, y, t], t] == 
     RT*(D[T[x, y, t], x, x] + D[T[x, y, t], y, y]), T[x, y, 0] == 0, 
    T[0, y, t] == R*t,
    T[9, y, t] == R*t,
    T[x, 0, t] == R*t,
    T[x, 9, t] == R*t}, T,
   {x, 0, 9}, {y, 0, 9}, {t, 0, 6}];
a = Table[
  Plot3D[T[x, y, t] /. FUNC, {x, 0, 9}, {y, 0, 9}, Mesh -> 15, 
   PlotRange -> {{0, 9}, {0, 9}, {-1, 10}}, 
   ColorFunction -> Function[{x, y, z}, Hue[.3 (1 - z)]]], {t, 0, 6}]
Export["c:\anim.gif", a]

alt text

PS:使用小写字母作为第一个字符可以避免很多错误符号...

Just a quick check:

RT = 1
R = 1
FUNC = NDSolve[{D[T[x, y, t], t] == 
     RT*(D[T[x, y, t], x, x] + D[T[x, y, t], y, y]), T[x, y, 0] == 0, 
    T[0, y, t] == R*t,
    T[9, y, t] == R*t,
    T[x, 0, t] == R*t,
    T[x, 9, t] == R*t}, T,
   {x, 0, 9}, {y, 0, 9}, {t, 0, 6}];
a = Table[
  Plot3D[T[x, y, t] /. FUNC, {x, 0, 9}, {y, 0, 9}, Mesh -> 15, 
   PlotRange -> {{0, 9}, {0, 9}, {-1, 10}}, 
   ColorFunction -> Function[{x, y, z}, Hue[.3 (1 - z)]]], {t, 0, 6}]
Export["c:\anim.gif", a]

alt text

PS: A lot of mistakes are avoided by using a lowercase letter as the first char for your symbols...

独夜无伴 2024-10-12 18:37:12

我同意马克的观点——你的程序没有任何问题。问题是在 t=0 之后您的函数没有发生任何有趣的事情:尝试看看

ListAnimate[
 Table[Plot3D[T[x, y, t] /. FUNC, {x, 0, 9}, {y, 0, 9}, Mesh -> 9], {t, 0, 6}]]

如您所见,发生的只是缩放,因此当 DensityPlot独立地重新缩放每个帧,它们最终看起来相同:)

I'm with Mark -- there is nothing wrong with your program. The problem is that nothing interesting happens to your function after t=0: Try having a look at

ListAnimate[
 Table[Plot3D[T[x, y, t] /. FUNC, {x, 0, 9}, {y, 0, 9}, Mesh -> 9], {t, 0, 6}]]

As you can see, all that happens is a scaling, so that when DensityPlot rescales each frame independently, they end up looking identical :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文