Example 7.8 Diffusion with Reaction
| > |
| > | with(plots): |
| > | eq:=diff(u(x,t),t)=diff(u(x,t),x$2)-Phi^2*u(x,t); |
| (1) |
| > | IC:=u(x,0)=0; |
| (2) |
| > | bc1:=u(x,t)=1; |
| (3) |
| > | bc2:=diff(u(x,t),x)=0; |
| (4) |
| > | eq1:=expand(eval(subs(u(x,t)=g(x,t)+w(x),eq))); |
| (5) |
| > | eqw:=diff(w(x),x$2)-Phi^2*w(x); |
| (6) |
| > | eqg:=diff(g(x,t),t)=diff(g(x,t),x$2)-Phi^2*g(x,t); |
| (7) |
| > | bc1w:=w(x)=1; |
| (8) |
| > | bc2w:=diff(w(x),x)=0; |
| (9) |
| > | dsolve({eqw},w(x)); |
| (10) |
w(x) can be written as:
| > | w(x):=w1*cosh(Phi*x)+w2*sinh(Phi*x); |
| (11) |
| > | eq_bc1w:=eval(subs(x=0,bc1w)): |
| > | eq_bc2w:=eval(subs(x=1,bc2w)): |
| > | w1:=solve(eq_bc1w,w1): |
| > | w2:=solve(eq_bc2w,w2): |
| > | w(x):=eval(w(x)): |
| > | w(x):=combine(w(x)): |
| > | w(x):=cosh(Phi*(1-x))/cosh(Phi); |
| (12) |
| > | Eq:=subs(g(x,t)=X(x)*T(t),eqg); |
| (13) |
| > | Eq:=expand(Eq/X(x)/T(t)); |
| (14) |
For convenience, Φ2 is written to the left hand side.
| > | Eq:=lhs(Eq)+Phi^2=rhs(Eq)+Phi^2;; |
| (15) |
| > | Eq_T:=lhs(Eq)=-lambda^2; |
| (16) |
| > | T(t):=rhs(dsolve({Eq_T,T(0)=T0},T(t))); |
| (17) |
T(t) can be written as:
| > | T(t):=T0*exp(-lambda^2*t)*exp(-Phi^2*t); |
| (18) |
| > | 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:=X(x)=0: |
| > | Bc2:=diff(X(x),x)=0: |
| > | Eq_Bc1:=eval(subs(x=0,Bc1)): |
| > | c[2]:=solve(Eq_Bc1,c[2]): |
| > | Eq_Bc2:=eval(subs(x=1,Bc2)): |
| > | Eq_Eig:=cos(lambda)=0: |
| > | solve(Eq_Eig,lambda): |
| > | _EnvAllSolutions := true: |
| > | solve(Eq_Eig,lambda): |
| > | G1:=eval(X(x)*T(t)): |
| > | Gn:=subs(c[1]=A[n]/T0,lambda=lambda[n],G1): |
| > | g(x,t):=Sum(Gn,n=1..infinity): |
| > | g(x,t):=subs(lambda[n]=(2*n-1)/2*Pi,g(x,t)); |
| (19) |
| > | u(x,t):=g(x,t)+w(x); |
| (20) |
| > | eq_An:=eval(subs(t=0,u(x,t)))=rhs(IC); |
| (21) |
| > | phi[n]:=sin((2*n-1)/2*Pi*x): |
| > | r(x):=1: |
| > | I1:=int(phi[n]^2*r(x),x=0..1): |
| > | I2:=int((rhs(IC)-w(x))*phi[n]*r(x),x=0..1): |
| > | vars:={sin(n*Pi)=0}: |
| > | I1:=subs(vars,I1): |
| > | I1:=simplify(I1); |
![]() |
(22) |
| > | I2:=subs(vars,I2): |
| > | I2:=simplify(I2); |
| (23) |
I2 is simplified further:
| > | I2n:=numer(I2): |
| > | I2d:=denom(I2): |
| > | I2d:=expand(I2d): |
| > | I2:=I2n/I2d; |
| (24) |
| > | A[n]:=I2/I1: |
| > | A[n]:=simplify(A[n]): |
| > | u(x,t):=eval(u(x,t)); |
![]() |
(25) |
| > | u(x,t):=subs(infinity=N,u(x,t)): |
| > | ua:=subs(N=20,u(x,t)): |
| > | uu:=piecewise(t=0,rhs(IC),t>0,ua): |
| > | plot3d(subs(Phi=1,uu),x=1..0,t=0.5..0,axes=boxed,title="Figure Exp. 7.19.",labels=[x,t,"u"],orientation=[-45,60]); |
![]() |
| > | plot([subs(t=0,Phi=1,uu),subs(t=0.05,Phi=1,uu),subs(t=0.1,Phi=1,uu),subs(t=0.2,Phi=1,uu),subs(t=0.5,Phi=1,uu)],x=0..1,axes=boxed,title="Figure Exp. 7.20.",thickness=5,labels=[x,"u"],legend=["t=0","t=0.05","t=0.1","t=0.2","t=0.5"]); |
![]() |
| > |