Example 7.5.mw

Example 7.5 Heat Conduction in a Slab with a Linear Initial Profile

> |

> | with(plots):

> | eq:=diff(u(x,t),t)=diff(u(x,t),x$2);

| (1)

> | IC:=u(x,0)=1-x;

| (2)

> | bc1:=diff(u(x,t),x)=0;

| (3)

> | bc2:=u(x,t)=0;

| (4)

> | Eq:=subs(u(x,t)=X(x)*T(t),eq):

> | Eq:=expand(Eq/X(x)/T(t)):

> | Eq_T:=lhs(Eq)=-lambda^2:

> | T(t):=rhs(dsolve({Eq_T,T(0)=T0},T(t)));

| (5)

> | Eq_X:=rhs(Eq)=-lambda^2:

> | Eq_X:=expand(Eq_X*X(x)):

> | dsolve({Eq_X},X(x)):

> | X(x):=c[1]*sin(lambda*x)+c[2]*cos(lambda*x):

> | Bc1:=diff(X(x),x)=0:

> | Bc2:=X(x)=0:

> | Eq_Bc1:=eval(subs(x=0,Bc1)):

> | c[1]:=solve(Eq_Bc1,c[1]):

> | Eq_Bc2:=eval(subs(x=1,Bc2)):

> | Eq_Eig:=cos(lambda)=0:

> | _EnvAllSolutions := true:

> | solve(Eq_Eig,lambda);

| (6)

> | U:=eval(X(x)*T(t)):

> | Un:=subs(c[2]=A[n]/T0,lambda=lambda[n],U):

> | u(x,t):=Sum(Un,n=0..infinity):

> | u(x,t):=subs(lambda[n]=(2*n+1)/2*Pi,u(x,t));

| (7)

> | eq_An:=eval(subs(t=0,u(x,t)))=rhs(IC);

| (8)

> | phi[n]:=cos((2*n+1)/2*Pi*x):

> | r(x):=1:

> | I1:=int(phi[n]^2*r(x),x=0..1):

> | IC;

| (9)

> | I2:=int(rhs(IC)*phi[n]*r(x),x=0..1);

| (10)

> | vars:={sin(n*Pi)=0}:

> | I1:=subs(vars,I1):

> | I2:=subs(vars,I2):

> | A[n]:=I2/I1:

> | A[n]:=simplify(A[n]);

| (11)

> | u(x,t):=eval(u(x,t));

| (12)

> | u(x,t):=subs(infinity=N,u(x,t)):

> | ua:=subs(N=20,u(x,t)):

The dimensionless temperature distribution is given by:

> | uu:=piecewise(t=0,rhs(IC),t>0,ua);

| (13)

> | plot3d(uu,x=1..0,t=0.5..0,axes=boxed,title="Figure Exp. 7.11.",labels=[x,t,"u"],orientation=[45,60]);

> | plot([subs(t=0,uu),subs(t=0.05,uu),subs(t=0.1,uu),subs(t=0.2,uu),subs(t=0.5,uu)],x=0..1,axes=boxed,title="Figure Exp. 7.12.",thickness=5,labels=[x,"u"],legend=["t=0","t=0.05","t=0.1","t=0.2","t=0.5"]);

Temperature at the surface, x = 0, can be found and plotted:

> | us:=eval(subs(x=0,uu));

| (14)

> | plot(us,t=0..1,axes=boxed,title="Figure Exp. 7.13.",thickness=3,labels=[t,"u"]);

> |