D'Alembert solution for wave equation on a bounded interval

f[x_]=Piecewise[{{x/10,0<x<0.5},{(1-x)/10,0.5<x<1}}]

Plot[f[x],{x,-2,2},PlotRange->All]

fodd[x_]=Piecewise[{{-f[-x],-1<x<0},{f[x],0<x<1}}]

Plot[fodd[x],{x,-2,2},PlotRange->All]

Plot[fodd[1-Mod[x,2]],{x,-2,2},PlotRange->All]

foddext[x_]:=fodd[1-Mod[x,2]]

Plot[foddext[x],{x,-2,2},PlotRange->All]

Plot[{foddext[x-0.2]/2,foddext[x+0.2]/2,(foddext[x-0.2]+foddext[x+0.2])/2},{x,-2,2},PlotPoints->1000]

Animate[Plot[{foddext[x-t]/2,foddext[x+t]/2,(foddext[x-t]+foddext[x+t])/2},{x,-2,2},
PlotRange->{-0.05,0.05},PlotStyle->Thick],{t,0,2},AnimationRunning->False]

Animate[Plot[{foddext[x-t]/2,foddext[x+t]/2,(foddext[x-t]+foddext[x+t])/2},{x,0,1},
PlotRange->{-0.05,0.05},PlotStyle->Thick],{t,0,2},AnimationRunning->False]

Laplace's equation on a rectangle

u[x_,y_,nmax_]:=Sum[(a[n]Cosh[n Pi y/l]+b[n]Sinh[n Pi y/l])Sin[n Pi x/l],{n,1,nmax}]

l=1;
h=2;

f1[x_]=0

Plot[f1[x],{x,0,l}]

f1dotv=Integrate[f1[x]Sin[n Pi x/l],{x,0,l},Assumptions->Element[n,Integers]]

vdotv=Integrate[Sin[n Pi x/l]^2,{x,0,l},Assumptions->Element[n,Integers]]

a[n_]=f1dotv/vdotv

f2[x_]=x

f2dotv=Integrate[f2[x]Sin[n Pi x/l],{x,0,l},Assumptions->Element[n,Integers]]

c[n_]=f2dotv/vdotv

b[n_]=(c[n]-a[n]Cosh[n Pi h/l])/Sinh[n Pi h/l]

Plot[u[x,h,31],{x,0,l}]

Plot3D[u[x,y,31],{x,0,l},{y,0,h},PlotRange->All]

ContourPlot[u[x,y,51],{x,0,l},{y,0,h},
ContourLabels->Automatic]