Example 7.11.mw

Example 7.11 Heat Transfer in a Rectangle 

> restart:
 

> with(plots):
 

Derivatives in y are entered on the left hand side and derivatives in x are entered on the right hand side. 

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

diff(diff(u(x, y), y), y) = `+`(`-`(diff(diff(u(x, y), x), x))) (1)
 

The boundary conditions at x = 0 and x = 1 are entered: 

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

u(x, y) = 0 (2)
 

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

u(x, y) = 0 (3)
 

The boundary conditions at y = 0 and y = 1 are entered: 

> bc3:=u(x,y)=0;
 

u(x, y) = 0 (4)
 

> bc4:=u(x,y)=1;
 

u(x, y) = 1 (5)
 

The dependent variable is separated as: 

> Eq:=subs(u(x,y)=X(x)*Y(y),eq);
 

diff(diff(`*`(X(x), `*`(Y(y))), y), y) = `+`(`-`(diff(diff(`*`(X(x), `*`(Y(y))), x), x))) (6)
 

> Eq:=expand(Eq/X(x)/Y(y));
 

`/`(`*`(diff(diff(Y(y), y), y)), `*`(Y(y))) = `+`(`-`(`/`(`*`(diff(diff(X(x), x), x)), `*`(X(x))))) (7)
 

> Eq_Y:=lhs(Eq)=lambda^2:
 

> Eq_Y:=eval(Eq_Y*Y(y));
 

diff(diff(Y(y), y), y) = `*`(Y(y), `*`(`^`(lambda, 2))) (8)
 

> dsolve(Eq_Y,Y(y));
 

Y(y) = `+`(`*`(_C1, `*`(exp(`*`(lambda, `*`(y))))), `*`(_C2, `*`(exp(`+`(`-`(`*`(lambda, `*`(y)))))))) (9)
 

Y(y) can be written as: 

> Y(y):=C[1]*sinh(lambda*y)+C[2]*cosh(lambda*y);
 

`+`(`*`(C[1], `*`(sinh(`*`(lambda, `*`(y))))), `*`(C[2], `*`(cosh(`*`(lambda, `*`(y)))))) (10)
 

The homogeneous boundary condition in y (at y = 0) is used to eliminate one of the constants. 

> Bc3:=Y(y)=0;
 

`+`(`*`(C[1], `*`(sinh(`*`(lambda, `*`(y))))), `*`(C[2], `*`(cosh(`*`(lambda, `*`(y)))))) = 0 (11)
 

> Eq_Bc3:=eval(subs(y=0,Bc3));
 

C[2] = 0 (12)
 

> C[2]:=solve(Eq_Bc3);
 

0 (13)
 

> Y(y):=eval(Y(y));
 

`*`(C[1], `*`(sinh(`*`(lambda, `*`(y))))) (14)
 

X(x) is obtained as in example 7.1: 

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

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

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

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

{X(x) = `+`(`*`(_C1, `*`(sin(`*`(lambda, `*`(x))))), `*`(_C2, `*`(cos(`*`(lambda, `*`(x))))))} (16)
 

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

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

> Bc1:=X(x)=0;
 

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

> Bc2:=X(x)=0;
 

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

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

c[2] = 0 (20)
 

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

0 (21)
 

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

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

> Eq_Eig:=sin(lambda)=0;
 

sin(lambda) = 0 (23)
 

> _EnvAllSolutions := true:
 

> solve(Eq_Eig,lambda);
 

`*`(Pi, `*`(_Z1)) (24)
 

> U:=eval(X(x)*Y(y));
 

`*`(c[1], `*`(sin(`*`(lambda, `*`(x))), `*`(C[1], `*`(sinh(`*`(lambda, `*`(y))))))) (25)
 

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

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

The dimensionless temperature is: 

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

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

The constant An is obtained using the nonhomogeneous boundary condition at y = 1: 

> eq_An:=eval(subs(y=1,u(x,y)))=rhs(bc4);
 

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

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

sin(`*`(n, `*`(Pi, `*`(x)))) (28)
 

> r(x):=1;
 

1 (29)
 

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

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

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

> I1:=subs(vars,I1):
 

> I2:=subs(vars,I2):
 

> A[n]:=I2/I1/sinh(n*Pi);
 

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

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

Sum(`/`(`*`(piecewise(n = 0, 0, `+`(`-`(`/`(`*`(`+`(cos(`*`(n, `*`(Pi))), `-`(1))), `*`(n, `*`(Pi)))))), `*`(sin(`*`(n, `*`(Pi, `*`(x)))), `*`(sinh(`*`(n, `*`(Pi, `*`(y))))))), `*`(piecewise(n = 0, 0,... (31)
 

> u(x,y):=subs(infinity=N,u(x,y)):
 

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

> uu:=piecewise(y<0.99,ua,y>0.99,1);
 

piecewise(`<`(y, .99), Sum(`/`(`*`(piecewise(n = 0, 0, `+`(`-`(`/`(`*`(`+`(cos(`*`(n, `*`(Pi))), `-`(1))), `*`(n, `*`(Pi)))))), `*`(sin(`*`(n, `*`(Pi, `*`(x)))), `*`(sinh(`*`(n, `*`(Pi, `*`(y))))))), ... (32)
 

> plot3d(evalf(uu),x=0..1,y=1..0,axes=boxed,title="Figure Exp. 7.26.",labels=[x,y,"u"],orientation=[-120,60]);
 

Plot
 

> plot([subs(y=0,uu),subs(y=0.4,uu),subs(y=0.6,uu),subs(y=0.8,uu),subs(y=0.9,uu),subs(y=1,uu)],x=0..1,title="Figure 7.27.",axes=boxed,thickness=5,labels=[x,"u"],legend=["y=0","y=0.4","y=0.6","y=0.8","y=0.9","y=1.0"]);
 

Plot_2d
 

>