Example 5.1 b rev 1.mw

Example 5.1b Heat Conduction in a Rectangular Slab

Consider the heat conduction problem in a slab.[6] The governing equation in dimensionless form is

u(x,0) = 1 (5.1.12)

u(0,t) = 0 and u(1,t) = 0

This equation is solved in Maple below using the procedure described above.

> | restart;

> | with(linalg):with(plots):

Enter the governing equation here:

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

| (1)

Enter the boundary condition at x = 0:

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

| (2)

Enter the boundary condition at x = L:

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

| (3)

Enter the initial condition:

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

| (4)

Enter the number of interior node points:

> | N:=10;

| (5)

Enter the length of the domain:

> | L:=1;

| (6)

Enter the three point backward difference expression (accurate to the order h2) for the first derivative at x = L:

> | dydxf:=1/2*(-u[2](t)-3*u[0](t)+4*u[1](t))/h;

| (7)

Enter the three point central difference expression (accurate to the order h2) for the second derivative at x = L:

> | dydxb:=1/2*(u[N-1](t)+3*u[N+1](t)-4*u[N](t))/h;

| (8)

Convert the boundary conditions to the finite difference form:

> | dydx:=1/2/h*(u[m+1](t)-u[m-1](t));

| (9)

> | d2ydx2:=1/h^2*(u[m-1](t)-2*u[m](t)+u[m+1](t));

| (10)

> | bc1:=subs(diff(u(x,t),x)=dydxf,u(x,t)=u[0](t),x=0,bc1);

| (11)

> | bc2:=subs(diff(u(x,t),x)=dydxb,u(x,t)=u[N+1](t),x=1,bc2);

| (12)

The boundary conditions are stored in eq[0] and eq[N+1].

> | eq[0]:=bc1;

| (13)

> | eq[N+1]:=bc2;

| (14)

The governing equations are converted to the finite difference form:

> | for i from 1 to N do eq[i]:=diff(u[i](t),t)= subs(diff(u(x,t),x$2) = subs(m=i,d2ydx2),diff(u(x,t),x) = subs(m=i,dydx),u(x,t)=u[i](t),x=i*h,rhs(ge));od;

| (15)

The boundary values u[0](t) and u[N+0](t) are eliminated:

> | u[0](t):=(solve(eq[0],u[0](t)));

| (16)

> | u[N+1](t):=solve(eq[N+1],u[N+1](t));

| (17)

The governing equations are simplified as:

> | for i from 1 to N do eq[i]:=eval(eq[i]);od;

| (18)

The coefficient matrix (A) is generated using Maple's 'genmatrix' command.

> | eqs:=[seq(rhs(eq[j]),j=1..N)];

| (19)

> | Y:=[seq(u[i](t),i=1..N)];

| (20)

> | A:=genmatrix(eqs,Y);

| (21)

The node spacing, h, is evaluated here:

> | h:=eval(1/(N+1));

| (22)

The A matrix is simplified as:

> | A:=map(eval,A);

| (23)

When more than four node points are used, the entries of the A matrix should be decimals. This problem can be handled by using the 'map(A,evalf)' command as given below:

> | if N > 4 then A:=map(evalf,A);end:

> | evalm(A);

| (24)

The solution is found using the exponential matrix:

> | mat:=exponential(A,t):

> | mat:=map(evalf,mat):

The initial condition is stored in the Y0 vector.

> | Y0:=matrix(N,1):for i from 1 to N do Y0[i,1]:=evalf(subs(x=i*h,rhs(IC)));od:evalm(Y0);

| (25)

> | Y:=evalm(mat&*Y0):

> | Y:=map(simplify,Y);

| (26)

Next, the dependent variables can be stored in ui(t),i = 0..N+1.

> | for i from 1 to N do u[i](t):=evalf((Y[i,1]));od:

> | for i from 0 to N+1 do u[i](t):=eval(u[i](t));od;

| (27)

Hence, an analytical solution in time is obtained for the dependent variables at all of the node points. One can plot the concentration profiles by:

> | pp:=plot([seq(u[i](t),i=0..N+1)],t=0..0.4,thickness=4);

| (28)

> | arw:=arrow(<0.10,0.8>,<-0.09,-0.6>,width=[1/500,relative],head_length=[1/20,relative]): pt:=textplot([[0.2,0.9,"Follow the arrow:"],seq([0.18,0.9-i*0.06,typeset(u[5-i+1],"(t), ",u[6+i-1],"(t)")],i=1..6)]):

Accuracy can be increased by increasing the number of interior node points. Using the program above by increasing N = 10, the following plots are obtained.

> | display({pp,arw,pt},axes=boxed,title="Figure Exp. 5.3",labels=[t,"u"]);

A three dimensional plot can be made by storing the solution in a matrix (PP). Enter the time that you want to use to plot your profiles (this time can be changed depending on the problem):

> | tf:=0.1;

| (29)

Enter the number of time steps (excluding 0):

> | M:=30;

| (30)

The time intervals are stored in T1:

> | T1:=[seq(tf*i/M,i=0..M)];

| (31)

> | PP:=matrix(N+2,M+1);

| (32)

The first column of PP is filled by using the initial condition:

> | for i from 1 to N+2 do PP[i,1]:=evalf(subs(x=(i-1)*h,rhs(IC)));od:

The remaining columns are filled in by using the solution obtained:

> | for i from 1 to N+2 do for j from 2 to M+1 do PP[i,j]:=evalf(subs(t=T1[j],u[i-1](t)));od;od:

Next, data points are stored in plotdata for obtaining a 3D plot using Maple's 'surfdata' command.

> | plotdata := [seq([ seq([(i-1)*h,T1[j],PP[i,j]], i=1..N+2)], j=1..M+1)]:

> | surfdata( plotdata, axes=boxed, title="Figure Exp. 5.4",labels=[x,t,u],orientation=[45,60]);

We observe that the process slowly approaches the steady state. We note that the profiles are symmetrical at about x = 0.5, and, hence, we obtain u[0] = u[N+1], u[1] = u[N], etc.

> |