# Mathematica DSolve gives zero solution for 1D heat PDE

This could possibly be duplicate. I do not know. Hard to search. But I just found out that for a very simple heat PDE in 1D with homogeneous boundary conditions, DSolve gives answer which does not make sense to me. It gives zero as the solution.

Here are the specs

\begin{align*} \frac{\partial u}{\partial t} & =k\frac{\partial^{2}u}{\partial t^{2}}\\ t & >0\\ 0 & <x<L \end{align*}

Initial conditions

$$u\left( x,0\right) =\sin\left( \pi\frac{x}{L}\right)$$

BC

\begin{align*} u\left( 0,t\right) & =0\\ u\left( L,t\right) & =0 \end{align*}

Here is the Mathematica code to solve it using DSolve

ClearAll[x,t,L0,k]
eq=D[u[x,t],{x,2}]*k==D[u[x,t],t];
bc={u[0,t]==0,u[L0,t]==0};
ic=u[x,0]==Sin[Pi x/L0 ];

(*now tried with assumptions and no assumptions, same result*)

(*sol=DSolve[{eq,ic,bc},u[x,t],{x,t}]*)
sol=DSolve[{eq, ic, bc}, u[x, t],{x, t},Assumptions->{L0 > 0,t >= 0,x >= 0}]

There is no inconsistency in boundary and initial conditions.

But this can be easily solved by hand. The analytical solution is

$$u\left( x,t\right) =\sin\left( \frac{\pi}{L}x\right) e^{-k\left( \frac{\pi}{L}\right) ^{2}t}%$$

NDSolve solves this correctly. Here is side-by-side of the solution by NDSolve and the above analytical solution to verify that the above analytical solution is correct.

values={k->2/3,L0->2};
numericalSol=NDSolve[Evaluate[{eq,ic,bc}/.values],u,{x,0,2},{t,0,3}];
myAnalyticalSolution[x_,t_]:= (Sin[ Pi/L0 x] Exp[-k ( Pi/L0)^2 t])/.values;

Manipulate[
Grid[{{Plot[u[x, t] /. numericalSol, {x, 0, 2},
PlotRange -> {{0, 2}, {-.1, 1}}, PlotLabel -> "NDSolve",
ImageSize -> 250],
Plot[myAnalyticalSolution[x, t], {x, 0, 2},
PlotRange -> {{0, 2}, {-.1, 1}}, PlotLabel -> "analytical",
ImageSize -> 250]}}],
{t, 0, 3, .01}]

Question is Why did DSolve gives zero as solution? And is there a way to correct this at user level (may be using some option or such).

Is this a bug in DSolve?

Using Version 11.1.1 on windows 7.

• If you set L0=1 then it works perfectly. Weird. Jun 20, 2017 at 4:05
• I suspect that it has something to do with the eigenvalues.
– zhk
Jun 20, 2017 at 5:25
• @yohbs Not so weird : DSolve is not "aware" that L0>0 Jun 20, 2017 at 10:34
• @andre FYI, Tried assumptions that length>0 but has no effect. Actually DSolve does not seem to use assumptions. Jun 20, 2017 at 15:35

One way to work around the issue is to tell Mathematica that L0 is NumericQ. For instance:

NumericQ[L0] = True;

Then:

eq = k D[u[x,t], {x,2}] == D[u[x, t], t];
bc = {u[0, t] == 0, u[L0, t] == 0};
ic = u[x,0] == Sin[Pi x/L0];

sol = DSolve[{eq, ic, bc}, u[x,t], {x,t}]
sol //TeXForm

{{u[x, t] -> E^(-((k [Pi]^2 t)/L0^2)) Sin[([Pi] x)/L0]}}

$\left\{\left\{u(x,t)\to e^{-\frac{\pi ^2 k t}{\text{L0}^2}} \sin \left(\frac{\pi x}{\text{L0}}\right)\right\}\right\}$