Nasser
Nasser

Reputation: 13173

Why does this pde give Boundary and initial conditions are inconsistent error? (1D heat pde)

I have been staring at this simple pde for last 20 minutes and can't find why I am getting this error

Boundary and initial conditions are inconsistent

it is that standard 1D heat equation

 eq = Derivative[2, 0][u][x, t] == Derivative[0, 1][u][x, t]

and boundary conditions are (notice they are both spatial derivatives)

u'(0,t)=0     (derivative here w.r.t.  x )
u'(Pi,t)=0    (derivative here w.r.t.  x )

and initial conditions are

u(x,0) = cos(2 x) 

So at initial condition, u'(x,0) = -2 sin(2 x), which is zero at both x=0 and x=Pi.

So it seems to me to be consistent with boundary conditions, right? or Am I missing something?

Here is the actual Mathematica code:

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}
              ]

I have a feeling since it is a numerical solver, using Pi in the above, become Real Pi=3.1415... and so at exactly this value the initial and boundary conditions do not match? (floating point comparison somewhere?)

I know about the trick to resolve such an error from help ref/message/NDSolve/ibcinc but my question is really why I am getting this error in the first place, since it seems on the face of it, they are consistent. If it is due to the floating point issue with Pi, then how to resolve this? I tried to use the trick shown in help on this one (i.e. the use of exp(-1000 t) but did not help in removing this error.

question: Why I am getting this error message ?

version 8.04, on windows.

Actually I have been trying to get this solution shown here (also using Mathematica)

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

but the BC and IC shown in the above example gave me this error also, so I made the change in the BC in the hope they become consistent now.

thanks.

edit(1)

Here are the commands I used to plot the plot the solution, and it looks ok

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}]

edit(3)

I am still little confused (also did not have coffee yet, which does not help).

I changed the IC so that it is not derivative any more so that the IC (non-derivative) now agrees with the BC's (but those are kept as derivatives). But I still get the same error:

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

Also the solution appears ok when plotted

Animate[Plot[sol[x, t], {x, 0, Pi}, 
  PlotRange -> {{0, Pi}, {-1, 1}}], {t, 0, 1.5}]

What IC is needed for this problem to eliminate this erorr, or is it the case then that only essential BC must be used? and also non-derivative IC's be used, and only after that, I worry on the consistency part?

Upvotes: 4

Views: 3401

Answers (1)

user1054186
user1054186

Reputation:

Szabolcs gave the right hint (See inconsistent boundary condition section in 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}}]

I have filed a suggestion, that the link to the tutorial be added to the NDSolve::ibcinc message page.

Upvotes: 4

Related Questions