Heat equation example

ϕ[x_]=x

vdotv=Integrate[Sin[n Pi/l x]^2,{x,0,l}]

vdotv=Simplify[vdotv,Assumptions->Element[n,Integers]]

ϕdotv=Integrate[ϕ[x] Sin[n Pi/l x],{x,0,l}]

ϕdotv=Simplify[ϕdotv,Assumptions->Element[n,Integers]]

a[n_]=ϕdotv/vdotv

u[x_,t_,l_,m_]:=Sum[a[n]Exp[-(n Pi/l)^2 t]Sin[n Pi/l x],{n,1,m}]

u[x,0,1,20]

u[x_,t_,l_,m_]:=Sum[-((2 (((-1))^n) l)/(n π))Exp[-(n Pi/l)^2 t]Sin[n Pi/l x],{n,1,m}]

Plot[%,{x,0,1}]

Plot[u[x,0.001,1,40],{x,0,1},PlotRange->{0,1}]

Animate[Plot[u[x,t,1,40],{x,0,1},PlotRange->{0,1.5}],{t,0,0.2},AnimationRunning->False]