Example 5.2 rev1.mw
Example 5.2
Consider the heat conduction/mass transfer problem in a cylinder.[6] [9] [10] The governing equation in dimensionless form is
u(x,0) = 0 (5.1.19)
(0,t) = 0 and u(1,t) = 1
The nonhomogeneous boundary condition at x = 1 contributes to the forcing function vector b. However, in this case the b vector is a constant, and hence, equation (5.1.18) can be used. (Note that equation (5.1.17) is valid even when the b vector is a constant.) When the governing equation is applied at x = 0 in cylindrical or spherical coordinate, we have singularity at x = 0.[11] [12] This singularity is avoided in our semianalytical technique as we use the boundary condition at x = 0 (symmetry boundary condition) to eliminate the dependent variable. Equation (5.1.19) is solved in Maple below using the procedure described above.
| > |
with(linalg):with(plots): |
| > |
ge:=diff(u(x,t),t)=diff(u(x,t),x$2)+1/x*diff(u(x,t),x); |
 |
(1) |
 |
(2) |
 |
(3) |
 |
(4) |
 |
(5) |
 |
(6) |
| > |
dydxf:=1/2*(-u[2](t)-3*u[0](t)+4*u[1](t))/h: |
| > |
dydxb:=1/2*(u[N-1](t)+3*u[N+1](t)-4*u[N](t))/h: |
| > |
dydx:=1/2/h*(u[m+1](t)-u[m-1](t)): |
| > |
d2ydx2:=1/h^2*(u[m-1](t)-2*u[m](t)+u[m+1](t)): |
| > |
bc1:=subs(diff(u(x,t),x)=dydxf,u(x,t)=u[0](t),x=0,bc1): |
| > |
bc2:=subs(diff(u(x,t),x)=dydxb,u(x,t)=u[N+1](t),x=1,bc2): |
), `-`(`*`(3, `*`(u[0](t)))), `*`(4, `*`(u[1](t)))))), `*`(h)))](images/Example 5.2 rev1_9.gif) |
(7) |
, `-`(1))](images/Example 5.2 rev1_10.gif) |
(8) |
| > |
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: |
| > |
u[0](t):=(solve(eq[0],u[0](t))); |
))), `*`(`/`(4, 3), `*`(u[1](t))))](images/Example 5.2 rev1_11.gif) |
(9) |
| > |
u[N+1](t):=solve(eq[N+1],u[N+1](t)); |
 |
(10) |
| > |
for i from 1 to N do eq[i]:=eval(eq[i]);od; |
| > |
eqs:=[seq(rhs(eq[j]),j=1..N)]: |
| > |
Y:=[seq(u[i](t),i=1..N)]; |
, u[2](t), u[3](t), u[4](t), u[5](t), u[6](t), u[7](t), u[8](t), u[9](t), u[10](t)]](images/Example 5.2 rev1_23.gif) |
(12) |
| > |
A:=genmatrix(eqs,Y,'b1'): |
| > |
b:=matrix(N,1):for i to N do b[i,1]:=-eval(b1[i]);od:evalm(b); |
 |
(13) |
 |
(14) |
| > |
if N > 4 then A:=map(evalf,A);end: |
| > |
Y0:=matrix(N,1):for i from 1 to N do Y0[i,1]:=evalf(subs(x=i*h,rhs(IC)));od:evalm(Y0); |
![array( 1 .. 10, 1 .. 1, [( 10, 1 ) = 0., ( 4, 1 ) = 0., ( 6, 1 ) = 0., ( 3, 1 ) = 0., ( 2, 1 ) = 0., ( 7, 1 ) = 0., ( 9, 1 ) = 0., ( 5, 1 ) = 0., ( 8, 1 ) = 0., ( 1, 1 ) = 0. ] )](images/Example 5.2 rev1_36.gif) |
(16) |
The nonhomogeneous solution (equation (5.17b)) is found and added to the homogeneous solution.
| > |
s1:=evalm(Y0+inverse(A)&*b): |
| > |
Y:=evalm(mat&*s1-inverse(A)&*b): |
The number of digits is decreased to five for brevity. However, for accuracy, one has to use a minimum of 10 digits, which is the default in Maple.
 |
(17) |
| > |
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; |
Hence, we have obtained a semianalytical solution (analytical in time and numerical in x). Next, plots are made:
| > |
for i from 0 to N+1 do
p[i]:=plot(u[i](t),t=0..0.4,color=COLOR(HUE,i/(N+2)),thickness=3):
end do: |
| > |
arw:=arrow(<0.26,0.6>,<-0.2,0.3>,width=[1/300,relative],head_width=[5,relative],head_length=[1/20,relative]):
pt:=textplot([[0.3,0.55,"Follow the arrow:"],seq([0.26,0.5-i*0.05,typeset(u[i],"(t)")],i=0..2),[0.26,0.35,"..."],[0.265,0.3,typeset(u[11],"(t)")]]): |
| > |
display([seq(p[i],i=0..11),arw,pt],axes=boxed,labels=[t,"u"],title="Figure Exp. 5.5."); |
 |
(19) |
 |
(20) |
| > |
T1:=[seq(tf*i/M,i=0..M)]; |
![array( 1 .. 12, 1 .. 31, [ ] )](images/Example 5.2 rev1_73.gif) |
(22) |
| > |
for i from 1 to N+2 do PP[i,1]:=evalf(subs(x=(i-1)*h,rhs(IC)));od: |
| > |
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: |
| > |
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.6.",labels=[x,t,u],orientation=[-145,45]); |
It is some times important to know how the temperature or concentration at the center of the cylinder changes with time. Analytical solutions for cylinders involve Bessel functions and an infinite series. With our semianalytical method, we can find how the temperature varies analytically with time. The time dependent variable at the center of the cylinder varies with time as:

 |
(23) |
We can find the time taken for the center of the cylinder to reach 0.5 (i.e., 50% of the steady state):
| > |
fsolve(u[0](t)-0.5,t=0..2); |
 |
(24) |
In this example temperature (or concentration) at the surface is fixed (u(1,t) = 1). With our semianalytical solution we can find how the flux at the surface varies as a function of time. This flux is given bya three point backward difference at x = 1.

 |
(25) |