2

I want to solve the heat equation in 1-D. When I evaluate the following

NDSolve[
  {D[u[t, x], t] == D[u[t, x], {x, 2}], 
   (D[u[t, x], x] /. x -> 0) == 1, 
   (D[u[t, x], x] /. x -> Pi) == 1, 
   u[0, x] == Cos[2 x] + x}, 
  u[t, x], {t, 0, 1}, {x, 0, Pi}][[1]]

I get the error

initial and boundary conditions are inconsistent

but I can't see why. I use version 10.2.0.0

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
freddy90
  • 851
  • 4
  • 12
  • Mathematica assumes 3 pde's: D[u,t]==... Are you shure about your 2 boundary conditions (which usually have to be of lower order as the pde. – Ulrich Neumann Dec 26 '17 at 14:22
  • 3
    I see nothing wrong with the initial and boundary conditions, or with the answer returned. – bbgodfrey Dec 26 '17 at 14:57
  • Your bc's match your ic, so that warning is erroneous. The final result looks good though. – Bill Watts Dec 26 '17 at 18:43
  • Sorry my comment was wrong. NDSolve gives only a warning (perhaps pointweise inconsintent?) but the NDSolve result seems to be ok in version 11.0.1! – Ulrich Neumann Dec 26 '17 at 18:52
  • To be specific, add e.g. Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 40}} to NDSolve will resolve your problem. – xzczd Dec 27 '17 at 04:28
  • @ xzczd: sorry your comment was hidden while I posted my answer... – Ulrich Neumann Dec 27 '17 at 11:08

1 Answers1

2

You can avoid this warning

NDSolve[{D[u[t, x], t] == D[u[t, x], {x, 2}], (D[u[t, x], x] /. x -> 0) ==1, 
(D[u[t, x], x] /. x -> Pi) == 1, u[0, x] == Cos[2 x] + x}
,u[t, x], {t, 0, 1}, {x, 0, Pi},
Method -> {"MethodOfLines","SpatialDiscretization" -> {"TensorProductGrid", 
  "MinPoints" -> 35}}] [[1]]

if you enforce a smoother spacial grid("MinPoints" > 31).

An approach without refinement is "FiniteElement" (works only with NeumannValue instead of the two bc D[u[t,x],x]==... )

NDSolveValue[{D[u[t, x], t] ==D[u[t, x], {x, 2}] + NeumannValue[1, x == 0 ||x == Pi],
u[0, x] == Cos[2 x] + x}, u , {t, 0, 1}, {x, 0, Pi}, 
Method -> {"MethodOfLines", "TemporalVariable" -> t,"SpatialDiscretization" -> {"FiniteElement" }}]  
Ulrich Neumann
  • 53,729
  • 2
  • 23
  • 55