2
$\begingroup$

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

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Ulrich Neumann Dec 26 '17 at 14:22
  • 3
    $\begingroup$ I see nothing wrong with the initial and boundary conditions, or with the answer returned. $\endgroup$ – bbgodfrey Dec 26 '17 at 14:57
  • $\begingroup$ Your bc's match your ic, so that warning is erroneous. The final result looks good though. $\endgroup$ – Bill Watts Dec 26 '17 at 18:43
  • $\begingroup$ 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! $\endgroup$ – Ulrich Neumann Dec 26 '17 at 18:52
  • $\begingroup$ To be specific, add e.g. Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 40}} to NDSolve will resolve your problem. $\endgroup$ – xzczd Dec 27 '17 at 4:28
2
$\begingroup$

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" }}]  
| improve this answer | |
$\endgroup$

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