3
$\begingroup$

I'm trying to familiarize myself with using Mathematica's NDSolve to solve PDEs. I'm using a simple one-dimensional heat equation as a start. The initial condition is a sine function and I'm expecting a standing wave as a solution of the heat equation. For some reason, plotting the result gives an empty plot.

What's the problem here? Is the code causing the solution to be zero everywhere (for all values of x) for all values of t?

ss == NDSolve[{D[u[x, t], t, t] == D[u[x, t], x, x], 
    u[x, 0] == Sin[x], u[0, t] == 0, u[Pi, t] == 0}, 
   u, {x, 0, Pi}, {t, 0, 3}];

list = Table[Plot[ss[x, t], {x, 0, Pi}, PlotRange -> {-0.1, 1.3}], {t, 0, 1, 0.1}];

ListAnimate[list]
$\endgroup$
  • $\begingroup$ The first thing I see is that you have ss == NDSolve, but it should be ss = NDSolve $\endgroup$ – mattiav27 Jan 9 '17 at 22:47
  • $\begingroup$ totally unrelated, but also a heat equation solution using Mathematica: mathematica.stackexchange.com/q/95358/9490 $\endgroup$ – Jason B. Jan 9 '17 at 23:06
4
$\begingroup$

First, you should use Set (=) not Equal (==) for ss = NDSolve..... Second, NDSolve gives a nested list of rules (with ->), so you need to extract the actual interpolating function with First and ReplaceAll (/.):

ss = u /. 
  First @ NDSolve[{D[u[x, t], t, t] == D[u[x, t], x, x], 
     u[x, 0] == Sin[x], u[0, t] == 0, u[Pi, t] == 0}, 
    u, {x, 0, Pi}, {t, 0, 3}]

list = Table[Plot[ss[x, t], {x, 0, Pi}, PlotRange -> {-0.1, 1.3}], {t, 0, 1, 0.1}];

ListAnimate[list]

enter image description here

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.