Heated rod with ice bath (Example 9.5.2)
L := 50; u0:=100; k:=0.15;
u := (x,t,N) -> (4*u0/Pi)* sum((1/(2*j-1)) * exp( -((2*j-1)*Pi/L)^2*k*t ) * sin((2*j-1)*Pi*x/L),j=1..N);
plot3d(u(x,t,50),x=0..L,t=0..2000,color=black,style=wireframe,axes=boxed);
Heated rod with insulated ends (Example 9.5.3)
f := x -> piecewise(0<x and x<=25, 4*x, 25<x and x<=50, 200-4*x);
plot(f(x),x=0..50, color=black);
Fourier series of f(t)
a:= n-> (2/L) * int(f(x)*cos(n*Pi*x/L),x=0..L);
f2 := (x,N) -> a(0)/2 + sum(a(n)*cos(n*Pi*x/L),n=1..N);
plot({f2(x,10),f(x)},x=0..50);
u2 := (x,t,N) -> a(0)/2 + sum(a(n) * exp(-(n*Pi/L)^2*k*t) * cos(n*Pi*x/L),n=1..N);
plot3d(u2(x,t,50),x=0..L,t=0..2000,color=black,style=wireframe,axes=boxed);