Example 7.10.mw
Example 7.10 Heat Transfer in a Rectangle
| > |
 |
| > |
eq:=diff(u(x,t),t)=diff(u(x,t),x$2); |
 |
(1) |
 |
(2) |
 |
(3) |
 |
(4) |
| > |
Eq:=subs(u(x,t)=X(x)*T(t),eq): |
| > |
Eq_T:=lhs(Eq)=-lambda^2: |
| > |
T(t):=rhs(dsolve({Eq_T,T(0)=T0},T(t))); |
 |
(5) |
| > |
Eq_X:=rhs(Eq)=-lambda^2: |
| > |
Eq_X:=expand(Eq_X*X(x)); |
 |
(6) |
The eigenvalue λ is obtained using the shooting technique. The third condition at x = 0 is assumed for
X2 =
| > |
eqlambda:=subs(X(x)=X(x,lambda),Eq_X): |
| > |
eqlambda:=diff(eqlambda,lambda): |
| > |
eqlambda:=subs(diff(X(x,lambda),lambda)=X2(x),eqlambda): |
| > |
eqlambda:=subs(X(x,lambda)=X(x),eqlambda); |
 |
(7) |
The dependent variables are:
 |
(8) |
The initial conditions for X and X2 are:
| > |
ICs:=(X(0)=0,D(X)(0)=1,X2(0)=0,D(X2)(0)=0); |
 |
(9) |
A tolerance 1e - 9 is set. A scaling factor of 1/2 is used for obtaining eigenvalues.
 |
 |
(10) |
Different initial guesses are used to predict the first ten eigenvalues:
| > |
lambdaguess:=[3,6,9,12,15,18,21,24,27,30]; |
![[3, 6, 9, 12, 15, 18, 21, 24, 27, 30]](images/Example 7.10_15.gif) |
(11) |
 |
(12) |
| > |
lambda0:=lambdaguess[i]; |
| > |
eqs:=subs(lambda=lambda0,Eq_X),subs(lambda=lambda0,eqlambda); |
| > |
Sol[i]:=dsolve({eqs,ICs},{vars},type=numeric,output=listprocedure); |
| > |
Xpred:=rhs(Sol[i](1)[2]); |
| > |
X2pred:=rhs(Sol[i](1)[4]); |
| > |
lambda1:=lambda0+rho*(Xexp-Xpred)/X2pred; |
| > |
err:=abs(lambda1-lambda0); |
| > |
lambda0:=lambda1;k:=k+1; |
The first ten eigenvalues are:

 |
(13) |
The number of iterations required to get the eigenvalues are:
 |
(14) |
The error associated with the eigenvalues is:
 |
(15) |
The first ten eigenfunctions are plotted as:
| > |
for i to MM do XX[i]:=subs(Sol[i],X(x)):od: |
| > |
for i to MM do p[i]:=plot(XX[i](x),x=0..1,thickness=3,title="Figure Exp. 7.23.",axes=boxed):od: |
| > |
display({seq(p[i],i=1..MM)},labels=[x,"X"]); |
The first eigenfunction does not cross the x axis. The second eigenfunction crosses the x axis once. Similarly, the nth eigenfunction crosses the x axis n - 1 times.
The solution can be taken as:
| > |
Un:=A[n]*XX[n](x)*exp(-lambda[n]^2*t); |
![`*`(A[n], `*`(XX[n](x), `*`(exp(`+`(`-`(`*`(`^`(lambda[n], 2), `*`(t))))))))](images/Example 7.10_22.gif) |
(16) |
| > |
for i to MM do lambda[i]:=l[i];od: |
| > |
u(x,t):=Sum(Un,n=1..MM); |
![Sum(`*`(A[n], `*`(XX[n](x), `*`(exp(`+`(`-`(`*`(`^`(lambda[n], 2), `*`(t)))))))), n = 1 .. 10)](images/Example 7.10_23.gif) |
(17) |
The constant An is obtained as:
| > |
eq_An:=eval(subs(t=0,u(x,t)))=rhs(IC); |
![Sum(`*`(A[n], `*`(XX[n](x))), n = 1 .. 10) = 1](images/Example 7.10_24.gif) |
(18) |
| > |
I1:=int(X(x)^2,x=0..1): |
 |
(19) |
The coefficient An , n = 1.. .10 are numerically obtained as:
| > |
for i from 1 to N-1 do I1:=I1+XX[j](i/N)^2*2/(2*N);I2:=I2+XX[j](i/N)*2/(2*N)od: |
| > |
I1:=I1+(XX[j](0)^2+XX[j](1)^2)/(2*N): |
| > |
I2:=I2+(XX[j](0)+XX[j](1))/(2*N): |

 |
(20) |
| > |
uu:=piecewise(t=0,rhs(IC),t>0,ua): |
| > |
plot3d(uu,x=1..0,t=0.3..0,axes=boxed,title="Figure Exp. 7.24.",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.25.",thickness=5,labels=[x,"u"],legend=["t=0","t=0.01","t=0.05","t=0.1","t=0.2"]); |