Part (a)

Check and visualize solution

Clear[k]

w[x_,t_]=(1+Erf[x/Sqrt[4 k t]])/2

u[x_,t_]=w[x+1,t]-w[x-1,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_]=Piecewise[{{1,Abs[x]<1}}]

k=1;
Plot[{u0[x],u[x,0.000001]},{x,-5,5},PlotRange->{0,1}]

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

Clear[k]

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

Can Mathematica integrate?

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

Clear[k]

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

u0[x_]=Piecewise[{{1,Abs[x]<1}}]

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

Part (b)

Check and visualize solution

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

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_]=Piecewise[{{0,x<0},{Exp[-x],x>0}}]

k=1

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

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

Clear[k]

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

Can Mathematica integrate?

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

Clear[k]

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

u0[x_]=Piecewise[{{0,x<0},{Exp[-x],x>0}}]

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