c:1$ L:1$

Initial condition

f(x):=x$

Fourier coefficients

ave:ratsimp((1/L)*integrate(f(x),x,0,L))$
A(n):=ratsimp((2/L)*integrate(x*cos(n*%pi*x/L),x,0,L))$

Fourier approximants

makelist(ave+sum(A(n)*cos(n*%pi*x/L),n,1,k),k,1,6)$
plot2d(append(%,[f(x)]),[x,0,L],same_xy)$

Heat equation

u(x,t):=ave+sum(A(n)*cos(n*%pi*x/L)*exp(-(c*n*%pi/L)^2*t),n,1,15);
u(x,t);
makelist(u(x,0.02*k),k,0,10)$
plot2d(%,[x,0,L])$

plot3d(u(x,t),[x,0,L],[t,0,0.3])$