This is the question I am trying to solve enter image description here

After fours hours of research and 61 attempts (just today) on how to do this, I'm asking for help. I've been in hospital and am now trying to catch up on lectures and unfortunately, although the Maths makes sense, the Mathematica does not.

This is the latest attempt and I really cannot find where I am going wrong.

NDSolve[{D[T[x, t], t] == 2.5*D[T[x, t], {x, 2}] + 10*Exp[-x^2],T[-2, t] == 22, (D[T[x, t], x] /. x -> 2) == 0}, T[x, t], {x, -2, 2}, {t, 0, 20}]

I am literally in tears typing this because I don't know what do anymore.

This is what it appears as in Mathematica

enter image description here

I assumed because I am given the flux, this is Neumann boundary conditions but the error is coming up about Dirichlet boundary conditions. What am I doing wrong and how do I go about fixing it?

Thank you in advance for your help.

  • 2
    $\begingroup$ If I add the initial condition then it works for me. I don't know what the second error message is complaining about, but I think the solution looks correct once I do that. $\endgroup$
    – SPPearce
    Commented Jan 11, 2019 at 11:39
  • $\begingroup$ Yeah, I made the same observation. The error messages are really misleading. $\endgroup$ Commented Jan 11, 2019 at 11:44
  • $\begingroup$ @KraZug Thank you! $\endgroup$
    – Gracious
    Commented Jan 11, 2019 at 11:57
  • $\begingroup$ @HenrikSchumacher Thank you! $\endgroup$
    – Gracious
    Commented Jan 11, 2019 at 11:57
  • $\begingroup$ why does the problem says the heat is open to flow through the right boundary then it says the flux is zero? flux zero means it is insulated on the right. If something is insulated, does this not mean heat does not flow? which book/page number did you get this problem from? $\endgroup$
    – Nasser
    Commented Jan 11, 2019 at 14:41

1 Answer 1


Everything works fine if you include the initial condition,

alpha = 2.5; 

HE = D[T[x, t], t] == alpha*D[T[x, t], {x, 2}] + 10*Exp[-x^2]

sol = NDSolve[{HE, T[x, 0] == 22, T[-2, t] == 22, (D[T[x, t], x] /. x -> 2) == 0}, 
  T, {x, -2, 2}, {t, 0, 20}]
  • $\begingroup$ Thank you, ever so much! $\endgroup$
    – Gracious
    Commented Jan 11, 2019 at 11:56
  • $\begingroup$ @Grace My pleasure :) $\endgroup$
    – zhk
    Commented Jan 11, 2019 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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