Bad “solution”

We initially arrived at this as a solution:

u[x_,t_]=Exp[-x^2/(1+4 k t)]/Sqrt[4Pi k t]/Sqrt[1+4 k t]

Check if this satisfies the heat equation:

D[u[x,t],t]-k*D[u[x,t],{x,2}]

Simplify[%]

No, it does not.  Just for fun, check graphically if this satisfies the initial condition:

u0[x_]=Exp[-x^2]

k=1

Plot[{u0[x],u[x,0.00001]},{x,-5,5},PlotRange->{0,5}]

Animate[Plot[{u0[x],u[x,t]},{x,-5,5},PlotRange->{0,5}],{t,0,1},
AnimationRunning->False,AnimationRate->0.1]

Seems wrong.  We can also ask Mathematica to look at the limit as t approaches 0.

Clear[k]

Limit[u[x,t],t->0]

Correct solution

After finding that our initial attempt was not correct, we fixed things up to arrive at

u[x_,t_]=Exp[-x^2/(1+4 k t)]/Sqrt[1+4 k t]

Check if this satisfies the heat equation:

D[u[x,t],t]-k*D[u[x,t],{x,2}]

Simplify[%]

Yes!.  Now check graphically if this satisfies the initial condition:

u0[x_]=Exp[-x^2]

k=1

Plot[{u0[x],u[x,0.00001]},{x,-5,5},PlotRange->{0,1}]

Animate[Plot[{u0[x],u[x,t]},{x,-5,5},PlotRange->{0,1}],{t,0,1},
AnimationRunning->False,AnimationRate->0.1]

Seems wrong.  We can also ask Mathematica to look at the limit as t approaches 0.

Clear[k]

Limit[u[x,t],t->0]

Yes!!  So we have the correct solution.  You should check the limit by hand rather than trust Mathematica.

Can Mathematica integrate?

Just for fun, let’s see if Mathematica can evaluate the integral we worked so hard to get by hand:

g[x_,t_]=Exp[-x^2/4/k/t]/Sqrt[4Pi k t]

u0[x_]=Exp[-x^2]

Integrate[u0[y]g[x-y,t],{y,-Infinity,Infinity},Assumptions->{k>0,t>0}]

Yes!!!  So why did we spend all day on this...