# Solving a heat equation problem

I'm brand new to Mathematica. I am trying to solve a heat equation problem, but I keep getting back the input on the output line.

The problem:

Consider the equation

$$\qquad u_t = u_{xx} - 9 u_x$$, $$0\lt x\lt1 , t\gt0$$,

with boundary condition $$u(0,t) = 0 ,\ u(1,t) = 0$$

and initial condition

$$u(x,0) = e^{4.5x}\!\left(5\sin\!\left(\pi\,x\right)+9\sin\!\left(2\,\pi\,x\right)+2\sin\!\left(3\,\pi\,x\right)\right)$$.

Solve for $$u(x,t)$$

My try at the code:

heqn = D[u[x, t], t] == D[u[x, t], {x, 2}] - 9*D[u[x, t], x];
ic =
{u[x, 0] == E^(4.5x)*(5 Sin[Pi*x] + 9 Sin[2*Pi*x] + 2 Sin[3*Pi*x]),
u[0,t] == 0, u[1,t] == 0};
sol = DSolveValue[{heqn, ic}, u[x, t], {x, t}]


The output is just a simplified version of my input.

What am I doing wrong?

• One thing is that you need square brackets for Sin, for example Sin[Pi x] – MelaGo Apr 26 '19 at 23:52
• @MelaGo Adding square brackets still gives me back the input – CA1998 Apr 26 '19 at 23:56
• never use real numbers when using exact solvers like DSolve and Solve and Integrate, etc.. This is the first rule of thumb I learned using Mathematica long time ago. – Nasser Apr 27 '19 at 7:00

Clear["Global*"]

heqn = D[u[x, t], t] == D[u[x, t], {x, 2}] - 9*D[u[x, t], x];
ic = {u[x, 0] == E^(9 x/2)*(5 Sin[Pi*x] + 9 Sin[2*Pi*x] + 2 Sin[3*Pi*x]),
u[0, t] == 0, u[1, t] == 0};

sol[x_, t_] = DSolveValue[{heqn, ic}, u[x, t], {x, t}] //
FullSimplify

(* E^(-(9/4) ((9 + 4 π^2) t - 2 x)) (5 E^(8 π^2 t) Sin[π x] +
9 E^(5 π^2 t) Sin[2 π x] + 2 Sin[3 π x]) *)


Verifying the solution,

{heqn, ic} /. u -> sol // Simplify

(* {True, {True, True, True}} *)


Plotting the solution,

Plot3D[sol[x, t], {x, 0, 1}, {t, 0, 0.15},
AxesLabel -> (Style[#, 12, Bold] & /@ {"x", "t", "sol"}),
PlotRange -> All] Limit[sol[x, t], t -> Infinity]

(* 0 *)

• Funny, the only modification here is 4.5 -> 9/2? – xzczd Apr 27 '19 at 6:12

This finds a solution very quickly.

uF =
NDSolveValue[
{D[u[x, t], t] == D[u[x, t], {x, 2}] - 9*D[u[x, t], x],
u[x, 0] == E^(4.5 x) (5 Sin[Pi x] + 9 Sin[2 Pi x] + 2 Sin[3 Pi x]),
u[0, t] == 0, u[1, t] == 0},
u, {x, 0, 1}, {t, 0, 1}]


and gives the following plot:

Plot3D[uF[x, t], {x, 0, 1}, {t, 0, 0.1},
AxesLabel -> {"x", "t", "u"}, PlotRange -> All]
` • Thank you for the solution. – CA1998 Apr 27 '19 at 3:55
• @CA1998. I have made major corrections to the code. – m_goldberg Apr 27 '19 at 4:14