Mathematica 2D Heat Equation Animation

2019-05-26 07:29发布

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?

2条回答
【Aperson】
2楼-- · 2019-05-26 07:51

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...

查看更多
男人必须洒脱
3楼-- · 2019-05-26 07:51

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 :)

查看更多
登录 后发表回答