Example 7.3.mw

Example 7.3 Mass Transfer in a Spherical Pellet

> |

> | with(plots):

> | eq:=diff(u(x,t),t)=diff(u(x,t),x$2)+2/x*diff(u(x,t),x);

| (1)

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

| (2)

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

| (3)

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

| (4)

> | Eq:=subs(u(x,t)=X(x)*T(t),eq):

> | Eq:=expand(Eq/X(x)/T(t)):

> | Eq_T:=lhs(Eq)=-lambda^2;

| (5)

> | T(t):=rhs(dsolve({Eq_T,T(0)=T0},T(t)));

| (6)

> | Eq_X:=rhs(Eq)=-lambda^2:

> | Eq_X:=expand(Eq_X*X(x));

| (7)

> | dsolve({Eq_X},X(x));

| (8)

The solution for X(x) can be taken as:

> | X(x):=c[1]*sin(lambda*x)/x+c[2]*cos(lambda*x)/x;

| (9)

> | Bc1:=diff(X(x),x)=0;

| (10)

> | Bc2:=X(x)=0;

| (11)

x = 0 cannot be substituted. Hence, the limit at x = 0 is obtained:

> | Eq_Bc1:=eval(subs(x=0,Bc1));

Error, numeric exception: division by zero |

> | limit(Bc1,x=0);

| (12)

So the constant c2 should be zero.

> | c[2]:=0;

| (13)

> | Eq_Bc2:=eval(subs(x=1,Bc2)):

> | Eq_Eig:=sin(lambda)=0;

| (14)

> | _EnvAllSolutions := true:

> | solve(Eq_Eig,lambda);

| (15)

> | U:=eval(X(x)*T(t)):

> | Un:=subs(c[1]=A[n]/T0,lambda=lambda[n],U):

> | u(x,t):=Sum(Un,n=1..infinity):

> | u(x,t):=subs(lambda[n]=n*Pi,u(x,t));

| (16)

> | eq_An:=eval(subs(t=0,u(x,t)))=rhs(IC);

| (17)

The eigenfunction is:

> | phi[n]:=sin(n*Pi*x)/x;

| (18)

The weighting function is:

> | r(x):=x^2;

| (19)

Next, the integrals are calculated to obtain An:

> | I1:=int(phi[n]^2*r(x),x=0..1):

> | IC;

| (20)

> | I2:=int(rhs(IC)*phi[n]*r(x),x=0..1):

> | vars:={sin(n*Pi)=0}:

> | I1:=subs(vars,I1):

> | I2:=subs(vars,I2):

> | A[n]:=I2/I1;

| (21)

The dimensionless concentration profile is given by:

> | u(x,t):=eval(u(x,t)):

> | 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);

| (22)

> | plot3d(uu,x=1..0,t=0.3..0,axes=boxed,title="Figure Exp. 7.7.",labels=[x,t,"u"],orientation=[60,60]);

> | plot([subs(t=0,uu),subs(t=0.01,uu),subs(t=0.05,uu),subs(t=0.1,uu),subs(t=0.2,uu)],x=0..1,axes=boxed,title="Figure Exp. 7.8.",thickness=5,labels=[x,"u"],legend=["t=0","t=0.01","t=0.05","t=0.1","t=0.2"]);

> |