Example 5.4
Consnider the following heat/mass transfer problem with a time dependent boundary condition,
u(x,0) = 0 (5.1.25)
(0,t) = 0 and u(1,t) = 1 - e-t
This boundary value problem is solved below in Maple by following the procedure described earlier. In this case, the forcing function vector, b(t), is a funtion of time and hence equaiton (5.1.17)a is used to obtain the semianalytical solution. The program used for example 5.3 can be used to solve this ecample by just modifying the boundary conditions.
| > | restart; |
| > | with(linalg):with(plots): |
| > | ge:=diff(u(x,t),t)=diff(u(x,t),x$2); |
| (1) |
| > | bc1:=diff(u(x,t),x); |
| (2) |
| > | bc2:=u(x,t)-1+exp(-t); |
| (3) |
| > | IC:=u(x,0)=0; |
| (4) |
| > | N:=10; |
| (5) |
| > | L:=1; |
| (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): |
| > | eq[0]:=bc1; |
| (7) |
| > | eq[N+1]:=bc2; |
| (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; |
| (9) |
| > | u[0](t):=(solve(eq[0],u[0](t))); |
| (10) |
| > | u[N+1](t):=solve(eq[N+1],u[N+1](t)); |
| (11) |
| > | for i from 1 to N do eq[i]:=eval(eq[i]);od; |
| (12) |
| > | eqs:=[seq(rhs(eq[j]),j=1..N)]: |
| > | Y:=[seq(u[i](t),i=1..N)]; |
| (13) |
| > | A:=genmatrix(eqs,Y,'b1'): |
| > | b:=matrix(N,1):for i to N do b[i,1]:=-eval(b1[i]);od:evalm(b); |
![]() |
(14) |
| > | h:=eval(L/(N+1)); |
| (15) |
| > | A:=map(eval,A): |
| > | if N > 4 then A:=map(evalf,A);end: |
| > | evalm(A); |
![]() |
(16) |
| > | det(A); |
| (17) |
| > | mat:=exponential(A,t): |
| > | mat:=map(evalf,mat): |
| > | mat:=map(simplify,mat): |
| > | Y0:=matrix(N,1):for i from 1 to N do Y0[i,1]:=evalf(subs(x=i*h,rhs(IC)));od:evalm(Y0); |
| (18) |
| > | b2:=subs(t=tau,evalm(b)); |
![]() |
(19) |
| > | mat2:=subs(t=t-tau,evalm(mat)): |
| > | mat3:=evalm(mat2&*b2): |
| > | mat4:=map(int,mat3,tau=0..t): |
| > | Y:=evalm(mat&*Y0+mat4): |
| > | Y:=map(simplify,Y): |
| > | 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; |
| (20) |
| > | for i from 0 to N+1 do
p[i]:=plot(subs(delta=1,u[i](t)),t=0..0.4,thickness=4,color=COLOR(HUE,i/(N+2))); end do: |
| > | arw:=arrow(<0.3,0.02>,<-0.15,0.11>,width=[1/1000,relative=false],head_width=[1/200,relative=false],head_length=[1/20,relative]):
pt:=textplot([[0.12,0.17,typeset("Follow the arrow: ",u[0],"(t), ..., ",u[N+1],"(t).")]]): |
| > | display([seq(p[i],i=1..N),p[0],pt,arw],title="Figure Exp. 5.11.",axes=boxed,labels=[t,"u"]); |
![]() |
| > | for i from 0 to N+1 do p[i]:=plot(subs(delta=0.1,u[i](t)),t=0..0.4,thickness=3);od: |
| > | tf:=0.4; |
| (21) |
| > | M:=30; |
| (22) |
| > | T1:=[seq(tf*i/M,i=0..M)]; |
| (23) |
| > | PP:=matrix(N+2,M+1); |
| (24) |
| > | 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],subs(delta=1,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.12.",labels=[x,t,u],orientation=[-145,45]); |
![]() |
| > | u[0](t); |
| (25) |
| > | plot(evalf(u[0](t)),t=0..10,thickness=4,axes=boxed,labels=['t',typeset(u[0],"(t)")]); |
![]() |
| > | plot(u[N+1](t),t=0..10,thickness=4,axes=boxed,labels=['t',typeset(u[N+1],"(t)")]); |
![]() |
| > | limit(u[0](t),t=4); |
| (26) |
| > |