Example 7.1.mw

Example 7.1  Heat Conduction in a Rectangle 

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

> Typesetting:-mrow(Typesetting:-mi(
 

> with(plots):
 

The gorging equation is entered here: 

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

diff(u(x, t), t) = diff(diff(u(x, t), x), x) (1)
 

The initial condition is entered here: 

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

u(x, 0) = 1 (2)
 

The boundary conditions are entered here: 

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

u(x, t) = 0 (3)
 

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

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

diff(`*`(X(x), `*`(T(t))), t) = diff(diff(`*`(X(x), `*`(T(t))), x), x) (5)
 

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

`/`(`*`(diff(T(t), t)), `*`(T(t))) = `/`(`*`(diff(diff(X(x), x), x)), `*`(X(x))) (6)
 

The governing equation for T is: 

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

`/`(`*`(diff(T(t), t)), `*`(T(t))) = `+`(`-`(`*`(`^`(lambda, 2)))) (7)
 

T can be solved as; 

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

`*`(T0, `*`(exp(`+`(`-`(`*`(`^`(lambda, 2), `*`(t))))))) (8)
 

The gorging equation for X is: 

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

`/`(`*`(diff(diff(X(x), x), x)), `*`(X(x))) = `+`(`-`(`*`(`^`(lambda, 2)))) (9)
 

X can be solved as: 

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

{X(x) = `+`(`*`(_C1, `*`(sin(`*`(lambda, `*`(x))))), `*`(_C2, `*`(cos(`*`(lambda, `*`(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)));
 

`+`(`*`(c[1], `*`(sin(`*`(lambda, `*`(x))))), `*`(c[2], `*`(cos(`*`(lambda, `*`(x)))))) (11)
 

The boundary conditions for X are: 

> Bc1:=X(x)=0;
 

`+`(`*`(c[1], `*`(sin(`*`(lambda, `*`(x))))), `*`(c[2], `*`(cos(`*`(lambda, `*`(x)))))) = 0 (12)
 

> Bc2:=X(x)=0;
 

`+`(`*`(c[1], `*`(sin(`*`(lambda, `*`(x))))), `*`(c[2], `*`(cos(`*`(lambda, `*`(x)))))) = 0 (13)
 

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

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

c[2] = 0 (14)
 

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

0 (15)
 

The second boundary condition at x = 1 gives: 

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

`*`(c[1], `*`(sin(lambda))) = 0 (16)
 

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

> Eq_Eig:=sin(lambda)=0;
 

sin(lambda) = 0 (17)
 

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

> solve(Eq_Eig,lambda);
 

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

`*`(Pi, `*`(_Z1)) (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));
 

`*`(c[1], `*`(sin(`*`(lambda, `*`(x))), `*`(T0, `*`(exp(`+`(`-`(`*`(`^`(lambda, 2), `*`(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);
 

`*`(A[n], `*`(sin(`*`(lambda[n], `*`(x))), `*`(exp(`+`(`-`(`*`(`^`(lambda[n], 2), `*`(t)))))))) (21)
 

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

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

Sum(`*`(A[n], `*`(sin(`*`(lambda[n], `*`(x))), `*`(exp(`+`(`-`(`*`(`^`(lambda[n], 2), `*`(t)))))))), n = 1 .. infinity) (22)
 

The values of the eigenvalues can be substituted as: 

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

Sum(`*`(A[n], `*`(sin(`*`(n, `*`(Pi, `*`(x)))), `*`(exp(`+`(`-`(`*`(`^`(n, 2), `*`(`^`(Pi, 2), `*`(t))))))))), n = 1 .. infinity) (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);
 

Sum(`*`(A[n], `*`(sin(`*`(n, `*`(Pi, `*`(x)))))), n = 1 .. infinity) = 1 (24)
 

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

piecewise(n = 0, 0, `+`(`/`(`*`(`/`(1, 2), `*`(`+`(`-`(`*`(cos(`*`(n, `*`(Pi))), `*`(sin(`*`(n, `*`(Pi)))))), `*`(n, `*`(Pi))))), `*`(n, `*`(Pi))))) (25)
 

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

piecewise(n = 0, 0, `+`(`-`(`/`(`*`(`+`(cos(`*`(n, `*`(Pi))), `-`(1))), `*`(n, `*`(Pi)))))) (26)
 

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

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

{sin(`*`(n, `*`(Pi))) = 0} (27)
 

> I1:=subs(vars,I1);
 

piecewise(n = 0, 0, `/`(1, 2)) (28)
 

> A[n]:=I2/I1;
 

`/`(`*`(piecewise(n = 0, 0, `+`(`-`(`/`(`*`(`+`(cos(`*`(n, `*`(Pi))), `-`(1))), `*`(n, `*`(Pi))))))), `*`(piecewise(n = 0, 0, `/`(1, 2)))) (29)
 

The dimensionless temperature profile is given by: 

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

Sum(`/`(`*`(piecewise(n = 0, 0, `+`(`-`(`/`(`*`(`+`(cos(`*`(n, `*`(Pi))), `-`(1))), `*`(n, `*`(Pi)))))), `*`(sin(`*`(n, `*`(Pi, `*`(x)))), `*`(exp(`+`(`-`(`*`(`^`(n, 2), `*`(`^`(Pi, 2), `*`(t)))))))))... (30)
 

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

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

Sum(`/`(`*`(piecewise(n = 0, 0, `+`(`-`(`/`(`*`(`+`(cos(`*`(n, `*`(Pi))), `-`(1))), `*`(n, `*`(Pi)))))), `*`(sin(`*`(n, `*`(Pi, `*`(x)))), `*`(exp(`+`(`-`(`*`(`^`(n, 2), `*`(`^`(Pi, 2), `*`(t)))))))))... (31)
 

N = 20 is enough for this problem: 

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

Sum(`/`(`*`(piecewise(n = 0, 0, `+`(`-`(`/`(`*`(`+`(cos(`*`(n, `*`(Pi))), `-`(1))), `*`(n, `*`(Pi)))))), `*`(sin(`*`(n, `*`(Pi, `*`(x)))), `*`(exp(`+`(`-`(`*`(`^`(n, 2), `*`(`^`(Pi, 2), `*`(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)"]);
 

Plot_2d
 

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

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

Sum(`/`(`*`(piecewise(n = 0, 0, `+`(`-`(`/`(`*`(`+`(cos(`*`(n, `*`(Pi))), `-`(1))), `*`(n, `*`(Pi)))))), `*`(sin(`*`(n, `*`(Pi, `*`(x)))), `*`(exp(`+`(`-`(`*`(`^`(n, 2), `*`(`^`(Pi, 2), `*`(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)"]);
 

Plot_2d
 

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

piecewise(t = 0, 1, `<`(0, t), Sum(`/`(`*`(piecewise(n = 0, 0, `+`(`-`(`/`(`*`(`+`(cos(`*`(n, `*`(Pi))), `-`(1))), `*`(n, `*`(Pi)))))), `*`(sin(`*`(n, `*`(Pi, `*`(x)))), `*`(exp(`+`(`-`(`*`(`^`(n, 2),... (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]);
 

Plot
 

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

Plot_2d
 

>