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

I looked at this simple pde in the last 20 minutes and cannot find why I am getting this error

Boundary and initial conditions are inconsistent 

this is the standard one-dimensional heat equation

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

and boundary conditions (note that they are also spatial derivatives)

 u'(0,t)=0 (derivative here wrt x ) u'(Pi,t)=0 (derivative here wrt x ) 

and initial conditions

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

So, in the initial state, u'(x,0) = -2 sin(2 x) , which is zero both on x=0 and x=Pi .

So, it seems to me that I agree with the 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, it becomes Real Pi = 3.1415 ... and therefore, with exactly this value, the initial and boundary conditions do not match? (floating point comparison somewhere?)

I know about the trick to resolve this error from the ref/message/NDSolve/ibcinc , but my question really is why I get this error in the first place, since it seems at first glance, it is consistent. If this is due to a floating point problem with Pi, then how to solve this? I tried using the trick shown in the help on this (e.g. using exp (-1000 t), but did not help remove this error.

Q: Why am I getting this error message?

version 8.04, on the windows.

I actually tried to show this solution (also using Mathematica)

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

but BC and IC shown in the above example also gave me this error, so I made changes to BC in the hope that they would become permanent.

thanks.

edit (1)

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

 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'm still a little confused (also there was no coffee yet, which does not help).

I changed IC so that it was no longer derivative, so IC (non-derivative) is now consistent with BC (but they are saved 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 when displaying

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

What is the IC for this problem to eliminate this erorr, or is it then necessary to use only the main BC? and also not a derivative of IP, and only after that I worry about the partial consistency?

+4
source share
1 answer

Szabolcs gave the correct hint (see the section on inconsistent boundary conditions at 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 suggested that a link to the tutorial be added to the NDSolve :: ibcinc message page.

+4
source

Source: https://habr.com/ru/post/1390039/


All Articles