# How to solve heat equation with Robin type conditions with NDSolve?

Could you help me please to solve following problem! I need to solve one-dimensional heat equation with Robin type boundary conditions. But Mathematica find only constant solution with no dependence on time and space coordinates. My code:

NDSolve[{
D[T[x, t], t] - D[D[ T[x, t], x], x] == 0,
(D[T[x, t], x] - (T[x, t] - 100) == 0) /. x -> 0,
(D[T[x, t], x] + (T[x, t] - 20) == 0) /. x -> 1,
T[x, 0] == 20
}, T, {x, 0, 1}, {t, 0, 1}]


Mathematica returns that temperature will be constant in all region: T[x,t]=20 (but in steady state solution we will have the liner low for the T(x)).

• When trying to run your code, I get a warning, complaining that boundary and initial conditions are inconsistent. Do you see the same? Have you looked into that? Commented Jul 9, 2015 at 17:24
• Are you sure of your boundary conditions? This example has Robin boundary conditions. (it is a link to a pdf file) Commented Jul 9, 2015 at 18:24
• Thanks to MarcoB. I try to use good initial conditions (exponential low or Piecewise[] function), and it works now.
– Yury
Commented Jul 10, 2015 at 11:15
• Yuri, I'm glad to hear you got it working. Would you please summarize your working solution as an answer? This way the question will be more valuable to other people experiencing similar problems. Commented Jul 11, 2015 at 3:27

Something like this:

NDSolve[{D[T[x, t], t] - D[D[T[x, t], x], x] ==
NeumannValue[T[x, t] - 100, x == 0] -
NeumannValue[T[x, t] - 20, x == 1], T[x, 0] == 20
}, T, {x, 0, 1}, {t, 0, 1},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> "FiniteElement"}]


Update Response to comment:

NDSolve[{D[D[T[x], x], x] == NeumannValue[T[x] - 100, x == 0] - NeumannValue[T[x] - 20, x == 1]}, T, {x, 0, 1}]


Update V12.1:

There is now a new Heat Transfer tutorial.

• Comment please, if I understand correctly: the method option you apply is due to the fact that the equation is time dependent, not because of the Robin condition. The Robin condition is treated automatically, right? Commented Nov 6, 2015 at 10:46
• Yes, this tells NDSolve to treat this as a time dependent problem with x as a spatial variable and t as time. Otherwise it tries to solve this as a purely spatial problems with both x and t as spatial coordinates. Commented Nov 6, 2015 at 12:26
• @user21 I checked the two Neumann conditions -Derivative[1, 0][T][0, t] == T[0, t] - 100 and Derivative[1, 0][T][1, t] == T[1, t] - 20 in your answer. The solution only fullfills the first . What could be the reason? Thanks! Commented Sep 20, 2019 at 8:22
• What if the steady state solution is required? Commented Mar 28, 2020 at 22:14
• @Jiangming, you'd then delete time. NDSolve[{D[D[T[x], x], x] == NeumannValue[T[x] - 100, x == 0] - NeumannValue[T[x] - 20, x == 1]}, T, {x, 0, 1}] Commented Mar 29, 2020 at 5:35