# How to solve 1D heat equation with Neumann boundary conditions?

I am struggling with EDP solving and boundary condition. I would like to solve this system (heat equation) :

$$\frac {\partial^2 u}{\partial x^2}-\frac {\partial u}{\partial t} = 0$$ with

$$\frac{\partial u}{\partial x}\bigg|_{x=0} =0 \quad (1)$$

$$\frac{\partial u}{\partial x}\bigg|_{x=h} =u(x=h,t) \quad (2)$$

$$u(x,0)=1 \quad (3)$$

$(1)$ cause trouble and maybe there is a conflict between (2) and (3)

Here what I have tried :

NDSolve[{D[u[t, x], {t, 1}] - D[u[t, x], {x, 2}] == NeumannValue[0, x == 0]
+ NeumannValue[u[t,x], x == 1, u[t, x] == 1}, u, {x, 0, 1}, {t,0, 10}]


And the message I get :

NDSolve::bcart: Warning: an insufficient number of boundary conditions have been specified for the direction of independent variable x. Artificial boundary effects may be present in the solution.
NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0..


The ndnum message can come from the conflict between (2) and (3) ? But i don't know how deal with this.

And for the boundary condition I am aware that NeumannValue[0, x == 0] is not what I am looking for since that mean "no condition" (if I understand correctly the NeumannValue's documentation). So I tried other exotic things like :

Derivative[{0, 1}][u][0, x] == 0
D[u[t, x], {x, 1}] == 0


without any succes.

So I need a little bit of help...

NDSolve is able to solve the one dimensional heat equation with initial condition $(3)$ and bc $(1)$. The missing boundary condition is artificially compensated but the solution may not be accurate,

sol = NDSolve[{D[u[t, x], {t, 1}] - D[u[t, x], {x, 2}] == 0,
(D[u[t, x], x] /. x -> 0) == 0, u[0, x] == 1},
u, {x, 0, 1}, {t, 0, 10}];


When we use MethodOfLines with FiniteElement, then we will be able to get a solution with Neumann boundary conditions,

sol2 = NDSolveValue[{D[u[t, x], {t, 1}] - D[u[t, x], {x, 2}] == NeumannValue[0, x == 0]
+ NeumannValue[u[t, x], x == 1], u[0, x] == 1},
u, {x, 0, 1}, {t, 0, 10},
Method -> {"MethodOfLines", "SpatialDiscretization" -> {"FiniteElement"}}];

Plot3D[sol2[t, x], {x, 0, 1}, {t, 0, 10}, PlotRange -> All]


Finally, checking whether the initial condition is satisfied or not,

Plot[{sol2[t, x] /. x -> 0, sol2[t, x] /. x -> 0.5, sol2[t, x] /. x -> 1}, {t, 0, 1},
PlotRange -> All, Frame -> True]
`

the above 2D plot shows that at $t=0$, $u=1$.

• I forgot to thank you for your answer. This works fine (better than the transform fourrier expension of the analytique solution huhu) ! I juste made an obvious mistake in the boundary condition (2) : a "-" is missing. But I let the things like that for the keeping coherence between my question and your answer. Thank you Commented Mar 13, 2017 at 14:36
• @Dalnor I am glad it helped. BTW, no need to say thanks explicitly when you accepted the answer.
– zhk
Commented Mar 13, 2017 at 16:20