FourierSinCoefficient[x,x,n]

U[x_,t_]:=Sum[-((2 (((-1))^n))/n)Sin[n x]Exp[-n^2 t],{n,1,500}]

Plot3D[U[x,t],{x,0,Pi},{t,0,3},PlotRange->{0,Pi},BoxRatios->{Pi,5,Pi},AxesLabel->Automatic,ColorFunction->"DarkRainbow", PlotStyle->Directive[Opacity[0.4],Green]]

FourierCosCoefficient[x,x,n]

V[x_,t_]:=Pi/2+Sum[((2 (-1+(((-1))^n)))/((n^2) π))Cos[n x]Exp[-n^2 t],{n,1,20}]

Plot3D[V[x,t],{x,0,Pi},{t,0,5},PlotRange->{0,Pi},BoxRatios->{Pi,5,Pi}]

FourierSinCoefficient[Pi/2-Abs[x-Pi/2],x,n]

W[x_,t_]:=Sum[((4 Sin[((n π)/2)])/((n^2) π))Sin[n x]Exp[-n^2 t],{n,1,100}]

Plot3D[W[x,t],{x,0,Pi},{t,0,3},PlotRange->{0,Pi},BoxRatios->{Pi,5,Pi}]