Example 6.2 Rev 1b.mw
Example 6.2 b
| > |
restart;with(plottools):with(linalg):with(plots): |
 |
(1) |
| > |
ge:=diff(u(x,y),y$2)=-epsilon^2*diff(u(x,y),x$2); |
 |
(2) |
 |
(3) |
 |
(4) |
Now, the boundary condition at y = 0 is redefined.
| > |
bc3:=diff(u(x,y),y)-u(x,y); |
 |
(5) |
 |
(6) |
 |
(7) |
| > |
dydxf:=1/2/h*(-u[m+2](zeta)-3*u[m](zeta)+4*u[m+1](zeta)); |
), `-`(`*`(3, `*`(u[m](zeta)))), `*`(4, `*`(u[`+`(m, 1)](zeta)))))), `*`(h)))](images/Example 6.2 Rev 1b_8.gif) |
(8) |
| > |
dydxb:=1/2/h*(u[m-2](zeta)+3*u[m](zeta)-4*u[m-1](zeta)); |
, `*`(3, `*`(u[m](zeta))), `-`(`*`(4, `*`(u[`+`(m, `-`(1))](zeta))))))), `*`(h)))](images/Example 6.2 Rev 1b_9.gif) |
(9) |
| > |
dydx:=1/2/h*(u[m+1](zeta)-u[m-1](zeta)); |
, `-`(u[`+`(m, `-`(1))](zeta))))), `*`(h)))](images/Example 6.2 Rev 1b_10.gif) |
(10) |
| > |
d2ydx2:=1/h^2*(u[m-1](zeta)-2*u[m](zeta)+u[m+1](zeta)); |
, `-`(`*`(2, `*`(u[m](zeta)))), u[`+`(m, 1)](zeta))), `*`(`^`(h, 2)))](images/Example 6.2 Rev 1b_11.gif) |
(11) |
| > |
bc1:=subs(diff(u(x,y),x)=subs(m=0,dydxf),u(x,y)=u[0](zeta),bc1); |
](images/Example 6.2 Rev 1b_12.gif) |
(12) |
| > |
bc2:=subs(diff(u(x,y),x)=subs(m=N+1,dydxb),u(x,y)=u[N+1](zeta),bc2); |
](images/Example 6.2 Rev 1b_13.gif) |
(13) |
 |
(14) |
](images/Example 6.2 Rev 1b_15.gif) |
(15) |
](images/Example 6.2 Rev 1b_16.gif) |
(16) |
| > |
for i from 1 to N do eq[N+1+i]:=diff(u[N+1+i](zeta),zeta)= subs(diff(u(x,y),x$2) = subs(m=i,d2ydx2),diff(u(x,y),x) = subs(m=i,dydx),u(x,y)=u[i](zeta),x=i*h,rhs(h^2/epsilon^2*ge));od; |
| > |
u[0](zeta):=(solve(eq[0],u[0](zeta))); |
 |
(18) |
| > |
u[N+1](zeta):=solve(eq[N+1],u[N+1](zeta)); |
 |
(19) |
| > |
for i from 1 to N do eq[i]:=diff(u[i](zeta),zeta)= u[N+1+i](zeta);od; |
| > |
for i from 1 to N do eq[i]:=eval(eq[i]);od;for i from 1 to N do eq[N+1+i]:=eval(eq[N+1+i]);od; |
| > |
eqns:=[seq(rhs(eq[j]),j=1..N),seq(rhs(eq[N+1+j]),j=1..N)]; |
| > |
Y:=[seq(u[i](zeta),i=1..N),seq(u[N+1+i](zeta),i=1..N)]; |
, u[2](zeta), u[3](zeta), u[4](zeta), u[5](zeta), u[6](zeta), u[7](zeta), u[8](zeta), u[9](zeta), u[10](zeta), u[12](zeta), u[13](zeta), u[14](zeta), u[15](zeta), u[16](zeta), u[17](zeta), ...](images/Example 6.2 Rev 1b_63.gif)
, u[2](zeta), u[3](zeta), u[4](zeta), u[5](zeta), u[6](zeta), u[7](zeta), u[8](zeta), u[9](zeta), u[10](zeta), u[12](zeta), u[13](zeta), u[14](zeta), u[15](zeta), u[16](zeta), u[17](zeta), ...](images/Example 6.2 Rev 1b_64.gif) |
(23) |
| > |
A:=genmatrix(eqns,Y,'b1'); |
 |
(24) |
| > |
if N>2 then A:=map(evalf,A):end; |
 |
(25) |
 |
(26) |
| > |
b:=matrix(2*N,1):for i from 1 to 2*N do b[i,1]:=-b1[i];od:evalm(b); |
 |
(27) |
 |
(28) |
| > |
mat:=evalm(S&*exponential(J,zeta)&*inverse(S)): |
| > |
mat1:=evalm(subs(zeta=zeta-zeta1,evalm(mat))): |
| > |
b2:=evalm(subs(zeta=zeta1,evalm(b))): |
| > |
mat2:=map(expand,mat2): |
| > |
mat3:=map(int,mat2,zeta1=0..zeta): |
![array( 1 .. 20, 1 .. 1, [ ] )](images/Example 6.2 Rev 1b_90.gif) |
(30) |
| > |
for i to N do Y0[i,1]:=p[i];od: |
| > |
for i to N do Y0[N+i,1]:=c[i]:od: |
![array( 1 .. 20, 1 .. 1, [( 5, 1 ) = p[5], ( 12, 1 ) = c[2], ( 17, 1 ) = c[7], ( 8, 1 ) = p[8], ( 19, 1 ) = c[9], ( 13, 1 ) = c[3], ( 4, 1 ) = p[4], ( 2, 1 ) = p[2], ( 7, 1 ) = p[7], ( 6, 1 ) = p[6], (...](images/Example 6.2 Rev 1b_91.gif) |
(31) |
| > |
Y:=evalm(mat&*Y0+mat3): |
| > |
sol0:=map(eval,evalm(subs(zeta=0,evalm(Y)))): |
| > |
sol1:=map(eval,evalm(subs(zeta=epsilon/h,evalm(Y)))): |
| > |
bc3:=diff(u(x,y),y)-u(x,y); |
 |
(32) |
| > |
for i to N do Eq[i]:=subs(diff(u(x,y),y)=epsilon/h*c[i],u(x,y)=p[i],x=i*h,bc3);od; |
| > |
for i to N do Eq[N+i]:=evalf(subs(diff(u(x,y),y)=epsilon/h*sol1[N+i,1],u(x,y)=sol1[i,1],bc4));od: |
The new sets of constants are:
| > |
csol:=solve({seq(Eq[i],i=1..2*N)},{seq(c[i],i=1..N),seq(p[i],i=1..N)}); |
Using the new values of constants the semianalytical solution is recalculated and following plots are obtained.
| > |
for i from 1 to N do u[i](zeta):=eval((YY[i,1]));od: |
| > |
for i from 0 to N+1 do u[i](zeta):=eval(u[i](zeta));od: |
| > |
for i from 0 to N+1 do u[i](y):=eval(subs(zeta=epsilon*y/h,u[i](zeta)));od; |
The constants are unassigned.
| > |
for i to N do unassign('c[i]'):unassign('p[i]'):od: |
| > |
for i from 0 to N+1 do
pl[i]:=line([0.3,0.98-abs(i-5.25)*0.14],[0.6,evalf(subs(y=0.6,u[i](y)))],thickness=1,linestyle=dot);
pt[i]:=textplot([0.3,0.98-abs(i-5.25)*0.14,typeset(u[i],"(y)")],align=left):
end do: |
| > |
for i from 0 to N+1 do p[i]:=plot(u[i](y),y=0..1,thickness=3);od: |
| > |
pp:=plot([seq(u[i](y),i=0..N+1)],y=0..1,thickness=3): |
| > |
display([pp,seq(pl[i],i=0..N+1),seq(pt[i],i=0..N+1)],title="Figure Exp. 6.4.",axes=boxed,labels=[y,"u"]); |
 |
(36) |
| > |
T1:=[seq(evalf(i/M),i=0..M)]; |
![[0., .200000000000, .400000000000, .600000000000, .800000000000, 1.]](images/Example 6.2 Rev 1b_182.gif) |
(37) |
| > |
for j from 1 to M do P[j]:=plot([seq([h*i,evalf(subs(y=T1[j],evalf(u[i](y))))],i=0..N+1)],style=line,thickness=3,axes=boxed,view=[0..1,0..1.1]):od: |
| > |
P[M+1]:=plot([seq([h*i,evalf(subs(x=i*h,1))],i=0..N+1)],style=line,thickness=3,title="Figure Exp. 6.5.",axes=boxed): |
| > |
for j from 1 to M+1 do
pt[j]:=textplot([0.5,evalf(subs(y=T1[j],u[5](y))),typeset(y,sprintf("=%4.2f",T1[j]))],align=above);
od: |
| > |
display({seq(P[i],i=1..M+1),seq(pt[i],i=1..M+1)},labels=[x,u]); |
 |
(38) |
![array( 1 .. 12, 1 .. 20, [ ] )](images/Example 6.2 Rev 1b_185.gif) |
(39) |
For the three dimensional plot, first the boundaries, x = 0, x = 1, and y = 1 are defined.
| > |
for i to Ny do PP[1,i]:=0;PP[N+2,i]:=0;od: |
| > |
for i to N+2 do PP[i,Ny]:=1;od: |
The temperature inside the rectangle is obtained using the semianalytical solution.
| > |
for i from 2 to N+1 do for j from 1 to Ny-1 do PP[i,j]:=evalf(subs(y=(j-1)/(Ny-1),u[i-1](y)));od;od: |
| > |
plotdata := [seq([ seq([(i-1)/(N+1),(j-1)/(Ny-1),PP[i,j]], i=1..N+2)], j=1..Ny)]: |
| > |
surfdata(plotdata,axes=boxed,title="Figure Exp.6.6.", labels=[x,y,u],orientation=[-120,60] ); |