Example 5.2.4 Exothermal Reaction in a Sphere
| > | restart; |
| > | with(linalg):with(plots): |
| > | ge:=diff(u(x,t),t)=diff(u(x,t),x$2)+2/x*diff(u(x,t),x)+beta*exp(-E/R/(u(x,t)+273.16));; |
| (1) |
| > | bc1:=diff(u(x,t),x);; |
| (2) |
| > | bc2:=u(x,t)-158; |
| (3) |
| > | IC:=u(x,0)=25; |
| (4) |
| > | N:=10; |
| (5) |
| > | L:=1; |
| (6) |
| > | beta:=6.699e17;E:=30800;R:=1.987; |
| (7) |
| > | dydxf:=1/2*(-u[2](t)-3*u[0](t)+4*u[1](t))/h; |
| (8) |
| > | dydxb:=1/2*(u[N-1](t)+3*u[N+1](t)-4*u[N](t))/h; |
| (9) |
| > | dydx:=1/2/h*(u[m+1](t)-u[m-1](t)); |
| (10) |
| > | d2ydx2:=1/h^2*(u[m-1](t)-2*u[m](t)+u[m+1](t)); |
| (11) |
| > | bc1:=subs(diff(u(x,t),x)=dydxf,u(x,t)=u[0](t),x=0,bc1); |
| (12) |
| > | bc2:=subs(diff(u(x,t),x)=dydxb,u(x,t)=u[N+1](t),x=1,bc2); |
| (13) |
| > | eq[0]:=bc1; |
| (14) |
| > | eq[N+1]:=bc2; |
| (15) |
| > | 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))); |
| (16) |
| > | u[N+1](t):=solve(eq[N+1],u[N+1](t)); |
| (17) |
| > | h:=L/(N+1); |
| (18) |
| > | for i from 1 to N do eq[i]:=eval(eq[i]);od: |
| > | eqs:=seq((eq[j]),j=1..N): |
| > | Y:=seq(u[i](t),i=1..N); |
| (19) |
| > | ICs:=seq(u[i](0)=rhs(IC),i=1..N); |
| (20) |
| > | sol:=dsolve({eqs,ICs},{Y},type=numeric,stiff=true,output=listprocedure); |
| (21) |
| > | for i to N do U[i]:=subs(sol,u[i](t));od: |
| > | U[0]:=subs(u[1](t)=U[1],u[2](t)=U[2],u[0](t)); |
| (22) |
| > | U[N+1]:=subs(u[N](t)=U[N],u[N-1](t)=U[N-1],u[N+1](t)); |
| (23) |
| > | for i from 0 to N+1 do p[i]:=plot(U[i](t),t=0..0.4,thickness=3,color=COLOR(HUE,i/(N+2)));od: |
| > | arw:=arrow(<0.15,70>,<-0.06,100>,width=[1/1000,relative=false],head_width=[1/200,relative=false],head_length=[1/20,relative]):
pt:=textplot([[0.27,65,typeset("Follow the arrow: ",u[0],"(t), ..., ",u[N+1],"(t).")]]): |
| > | display([seq(p[i],i=0..N+1),arw,pt],axes=boxed,title="Figure Exp. 5.2.7.",labels=[t,"u"]); |
![]() |
| > | tf:=0.3784; |
| (24) |
| > | M:=30; |
| (25) |
| > | T1:=[seq(tf*i/M,i=0..M)]; |
| (26) |
| > | PP:=matrix(N+2,M+1); |
| (27) |
| > | 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.2.8.",labels=[x,t,u],orientation=[-45,60]); |
![]() |
| > | plot(U[0](t),t=0..1,thickness=3,title="Figure 5.2.9.",axes=boxed,labels=[t,"u[0]"]); |
![]() |
| > | px[0]:=plot([seq([i*h,subs(x=i*h,rhs(IC))],i=0..N+1)],thickness=3): |
| > | for j from 2 to M+1 do px[j]:=plot([seq([i*h,U[i](T1[j])],i=0..N+1)],thickness=3,color=COLOR(HUE,(j+1)/(M+4))):od:; |
| > | display([seq(px[j*2],j=0..(M+1)/2)],title="Figure 5.2.10.",axes=boxed,labels=[x,u],caption="Time increasing from the bottom to the top of the figure."); |
![]() |
| > |