Example 7.4.mw

Example 7.4 Heat Conduction in a rectangle with an Initial Profile 

> 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)=sin(Pi*x);
 

u(x, 0) = sin(`*`(Pi, `*`(x))) (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)
 

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

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

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

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

> 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:=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:=sin(lambda)=0;
 

sin(lambda) = 0 (5)
 

> _EnvAllSolutions := true:
 

> solve(Eq_Eig,lambda):
 

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

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

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

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

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

> r(x):=1:
 

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

> IC;
 

u(x, 0) = sin(`*`(Pi, `*`(x))) (8)
 

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

piecewise(n = -1, -`/`(1, 2), n = 1, `/`(1, 2), `+`(`-`(`/`(`*`(sin(`*`(n, `*`(Pi)))), `*`(Pi, `*`(`+`(`-`(1), `*`(`^`(n, 2))))))))) (9)
 

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

> I1:=subs(vars,I1);
 

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

The coefficient of An is obtained as: 

> A[n]:=I2/I1;
 

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

For n = any integer value other than 1, An is zero: 

> eval(subs(n=2,A[n]));
 

0 (12)
 

> eval(subs(n=3,A[n]));
 

0 (13)
 

> eval(subs(n=100,A[n]));
 

0 (14)
 

> eval(subs(n=1,A[n]));
 

Error, numeric exception: division by zero
 

The limit command is applied to n = 1: 

> A[1]:=limit(A[n],n=1);
 

1 (15)
 

There is only one non zero term in the infinite series: 

> u(x,t):=A[1]*sin(1*Pi*x)*exp(-Pi^2*t);
 

`*`(sin(`*`(Pi, `*`(x))), `*`(exp(`+`(`-`(`*`(`^`(Pi, 2), `*`(t))))))) (16)
 

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

Plot
 

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

Plot_2d
 

>                                                                                                               
 

>