Consider the problem:

> restart;eqn := diff(U(x,t),t)=2*diff(U(x,t),x,x);

[Maple Math]

> BC := {convert(D[1](U)(0,t),diff)=0,U(Pi,t)=0};IC:={U(x,0)=f(x)};

[Maple Math]

[Maple Math]

This problem has the LH side at 0 and the RH side at Pi INSULATED.

> alias(u=Heaviside);

[Maple Math]

> f(x):=x*(u(x)-u(x-Pi/2))+(Pi-x)*(u(x-Pi/2)-u(x-Pi));

[Maple Math]

> plot(f(x),x=0..Pi);

[Maple Plot]

Our problem needs a new set of eigenfunctions in x. They must satisfy:

> ODE:=diff(X[n](x),x,x)+k[n]*X[n](x)=0;

[Maple Math]

> BC:={X[n](0)=0,`X'`[n](Pi)=0};

[Maple Math]

Such functions will be given by sin((2n-1)/2*x) as we can see by plotting a few...

> plot([seq(sin((2*n-1)/2*x),n=1..6)],x=0..Pi);

[Maple Plot]

Notice that all the sins have value 0 at x = 0 BUT have slopes =0 at x=Pi. Such functions will staisfy the BC.

> b[n] := 2/Pi*(Int(x*sin((2*n-1)/2*x),x=0..Pi/2)+Int((Pi-x)*sin((2*n-1)/2*x),x=Pi/2..Pi));

[Maple Math]

> b[n] := value(%);

[Maple Math]
[Maple Math]
[Maple Math]

> for p from 1 to 5 do B[p]:=subs(n=p,b[n])=eval(subs(n=p,b[n])) od;

[Maple Math]
[Maple Math]

[Maple Math]
[Maple Math]
[Maple Math]

[Maple Math]
[Maple Math]

[Maple Math]
[Maple Math]

[Maple Math]
[Maple Math]

> U(x,t) := Sum(exp(-2*((2*n-1)/2)^2*t)*b[n]*sin((2*n-1)/2*x),n=1..10);

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

> plots[animate]({f(x),U(x,t)},x=0..Pi,t=0..10,color=black);

[Maple Plot]

New Problem with different IC, same BC and equation...IC=u(x,0)=f(x) given by...

> f(x):=-(u(x)-u(x-Pi/3))+(u(x-2*Pi/3)-u(x-Pi));

[Maple Math]

> plot(f(x),x=0..Pi);

[Maple Plot]

> b[n] :=

> 2/Pi*(Int(-1*sin((2*n-1)/2*x),x=0..Pi/3)+Int(sin((2*n-1)/2*x),x=2*Pi/3..Pi));

[Maple Math]

> b[n] := value(%);

[Maple Math]

> for p from 1 to 5 do B[p]:=subs(n=p,b[n])=eval(subs(n=p,b[n])) od;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

> U(x,t) := Sum(exp(-2*((2*n-1)/2)^2*t)*b[n]*sin((2*n-1)/2*x),n=1..20);

[Maple Math]

> plots[animate]({f(x),U(x,t)},x=0..Pi,t=0..20,frames=20,color=black);

[Maple Plot]

Notice that the heat will leave thru the end at x=0, since x=Pi is insulated. It will take longer for the temp to go to zero than if the RH end condition was 0 as well. Eventually it will however go to zero.