Example 7.1.mw

Example 7.1 Heat Conduction in a Rectangle

The Maple program used to solve example 7.1 is given below:

> |

> | with(plots):

The gorging equation is entered here:

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

| (1)

The initial condition is entered here:

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

| (2)

The boundary conditions are entered here:

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

| (3)

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

| (4)

Next, u is separated as u = XT (equation 7.1.5)):

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

| (5)

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

| (6)

The governing equation for T is:

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

| (7)

T can be solved as;

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

| (8)

The gorging equation for X is:

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

| (9)

X can be solved as:

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

| (10)

Maple sometimes attaches _C1 with the sine function and sometimes with the cosine function. To avoid this, we can specify the initial conditions for X and its derivative:

> | X(x):=rhs(dsolve({Eq_X,D(X)(0)=c[1]*lambda,X(0)=c[2]},X(x)));

| (11)

The boundary conditions for X are:

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

| (12)

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

| (13)

The constant c2 is solved using the boundary condition at X = 0:

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

| (14)

> | c[2]:=solve(Eq_Bc1,c[2]);

| (15)

The second boundary condition at x = 1 gives:

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

| (16)

If c1 is zero, then we get the trivial solution X = 0. Hence, sin(λ) should be zero:

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

| (17)

The eigenvalue equation can be solved to get the eigenvalue, λ:

> | solve(Eq_Eig,lambda);

| (18)

By default, Maple picks only one eigenvalue. We can ask Maple to find all the eigenvalues using the following command:

> | _EnvAllSolutions := true:

> | solve(Eq_Eig,lambda);

| (19)

_Z1 means the integer plane. Hence, the eigenvalues can be taken as λ = nπ, n = 1, 2, 3,...∞. The solution for u can be written as:

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

| (20)

The constants c1 and T0 can be combined as a single constant An:

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

| (21)

Hence, the solution can be written as an infinite series:

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

| (22)

The values of the eigenvalues can be substituted as:

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

| (23)

The constant An is obtained by applying the initial condition and by using the orthogonal property of the eigenfunction:

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

| (24)

> | I1:=int((sin(n*Pi*x))^2,x=0..1);

| (25)

> | I2:=int(sin(n*Pi*x),x=0..1);

| (26)

The integrals can be simplified by substituting sin(nπ) = 0:

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

| (27)

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

| (28)

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

| (29)

The dimensionless temperature profile is given by:

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

| (30)

For plotting purposes, we replace ∞ by, N, an integer:

> | u(x,t):=subs(infinity=N,u(x,t));

| (31)

N = 20 is enough for this problem:

> | ua:=subs(N=20,u(x,t));

| (32)

The solution obtained is plotted at t = 0. We observe oscillations about initial condition 1. This is called Gibb's phenomenon. Theoretically it will take N = ∞ for this profile to become u = 1 at t = 0.

> | plot(eval(subs(t=0,ua)),x=0..1,axes=boxed,title="Figure Exp. 7.1.",thickness=3,labels=[x,"u(x,0)"]);

Next, the initial condition is predicted using N = 100 terms in the series:

> | ua2:=subs(N=100,u(x,t));

| (33)

> | plot(eval(subs(t=0,ua2)),x=0..1,axes=boxed,title="Figure Exp. 7.2.",thickness=3,labels=[x,"u(x,0)"]);

We observe better predictions as the number of terms increase. However, we need more terms at t = 0. For values of t > 0, N = 20 is enough. Hence, a piecewise polynomial can be used to define the initial condition at t = 0 and the separation of variables solution obtained can be used for values of t > 0.

> | uu:=piecewise(t=0,rhs(IC),t>0,ua);

| (34)

A three dimensional plot can be made as:

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

The profiles across the slab at different times can be plotted as:

> | 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.4.",thickness=5,labels=[x,"u"],legend=["t=0","t=0.01","t=0.05","t=0.1","t=0.2"]);

> |