Can someone explain why, if I have



Derivative[1,0][u][0,t] == 0

doesn't give the same result as


I just want to solve heat/diffusion equation

D[u[x,t],t] == D[u[x,t],{x,2}]

with 2 bc saying that the derivative with respect to $x$ at $x=0$ and $x=1$ is equal to $0$ (flux=0) and that ic is


I got it right in COMSOL but not in Mathematica

  • 1
    $\begingroup$ Err... Because the first is a differential equation, and the second says that something is supposed to be zero at $x=0$? Your question is like asking why Range[42] doesn't give the same result as ListPlot[{1,2}]. What is it that you really are doing? $\endgroup$ – corey979 Jun 22 '18 at 19:08
  • 3
    $\begingroup$ Can you give a complete example? $\endgroup$ – Szabolcs Jun 22 '18 at 19:28
  • 3
    $\begingroup$ I second @Szabolcs: please post the complete Mathematica code you are using. Without it we're not really able to help you. $\endgroup$ – corey979 Jun 22 '18 at 20:28
  • 1
    $\begingroup$ Here user21 writes :"Specifying NeumannValue will lead to FEM since the correspondence to Derivative is not one to one". I confess that I don't understand the section "The Relation between NeumannValue and Boundary Derivatives" in the linked page. $\endgroup$ – andre314 Jun 22 '18 at 22:54
  • 1
    $\begingroup$ In your case zero Neumann value at x==0 is indeed equivalent to Derivative[1,0][u][0,t] == 0, how did you code it? Please add the complete code sample. Also, notice your i.c. is inconsistent with b.c., so you'll face the problem mentioned here if you're not using "FiniteElement" method for spatial discretization. $\endgroup$ – xzczd Jun 23 '18 at 4:24

Just use DSolve in the normal way. No need to use NeumannValue in this case.

pde = D[u[x, t], t] == D[u[x, t], {x, 2}]

DSolve[{pde, Derivative[1, 0][u][1, t] == 0, 
  Derivative[1, 0][u][0, t] == 0, u[x, 0] == Sin[Pi x]}, 
 u[x, t], {x, t}]

(*{{u[x, t] -> 2*Inactive[Sum][((1 + (-1)^K[1])*Cos[Pi*x*K[1]])/
        (E^(Pi^2*t*K[1]^2)*(Pi - Pi*K[1]^2)), {K[1], 1, Infinity}] + 

Change from K[1] to n to make simpler and make finite number of terms for plotting

u[x_, t_, m_] := 2/Pi + (2/Pi)*Sum[((1 + (-1)^n)*Cos[Pi*x*n])/(E^(Pi^2*t*n^2)*(1 - n^2)), 
     {n, 2, m}]

The trick is that the n = 1 term appears singular to MMA with the denominator and if you take the limit MMA returns a complex result. Plotting the real portion shows that the n = 1 term is zero, so we can start the sum at n = 2.

tp = Table[
   Plot[Evaluate[u[x, t, 200]], {x, 0, 1}, PlotRange -> {0, 1}], {t, 
    0, .2, .005}];

enter image description here

  • $\begingroup$ How is a DSolve answer the same as an NDSolve answer? $\endgroup$ – Bill Watts Jun 23 '18 at 7:28

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