c:1$ L:1$

Initial condition

p:1/4$ h:1$
f(x):=(h/p)*x*charfun(0<x and x<p)+(h/(L-p))*(L-x)*charfun(p<x and x<L)$

Fourier coefficients

declare(n,integer)$
B(n):=ratsimp((2/L)*(integrate((h/p)*x*sin(n*%pi*x/L),x,0,p)+
integrate(h/(L-p)*(L-x)*sin(n*%pi*x/L),x,p,L)))$
B(n); makelist(B(n),n,1,10);

Fourier approximants

makelist(sum(B(n)*sin(n*%pi*x/L),n,1,k),k,1,6)$
plot2d(append(%,[f(x)]),[x,0,L])$

Wave equation

u(x,t):=sum(B(n)*sin(n*%pi*x/L)*cos(c*n*%pi*t/L),n,1,20);
makelist(u(x,0.1*k),k,0,7)$
plot2d(%,[x,0,L])$

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

Heat equation

u(x,t):=sum(B(n)*sin(n*%pi*x/L)*exp(-(c*n*%pi/L)^2*t),n,1,5);
u(x,t);
makelist(u(x,0.01*k),k,0,10)$
plot2d(%,[x,0,L])$

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