Example 6.4 Rev 1.mw
Example 6.4
| > |
restart;with(linalg):with(plots): |
| > |
ge:=diff(u(x,y),y$2)=-epsilon^2*diff(u(x,y),x$2); |
 |
(1) |
 |
(2) |
 |
(3) |
The nonlinear boundary condition at y = 0 is entered:
| > |
bc3:=diff(u(x,y),y)-u(x,y)^4; |
 |
(4) |
 |
(5) |
 |
(6) |
 |
(7) |
| > |
dydxf:=1/2/h*(-u[m+2](zeta)-3*u[m](zeta)+4*u[m+1](zeta)): |
| > |
dydxb:=1/2/h*(u[m-2](zeta)+3*u[m](zeta)-4*u[m-1](zeta)): |
| > |
dydx:=1/2/h*(u[m+1](zeta)-u[m-1](zeta)): |
| > |
d2ydx2:=1/h^2*(u[m-1](zeta)-2*u[m](zeta)+u[m+1](zeta)): |
| > |
bc1:=subs(diff(u(x,y),x)=subs(m=0,dydxf),u(x,y)=u[0](zeta),bc1); |
](images/Example 6.4 Rev 1_8.gif) |
(8) |
| > |
bc2:=subs(diff(u(x,y),x)=subs(m=N+1,dydxb),u(x,y)=u[N+1](zeta),bc2); |
, `*`(3, `*`(u[`+`(N, 1)](zeta))), `-`(`*`(4, `*`(u[N](zeta))))))), `*`(h)))](images/Example 6.4 Rev 1_9.gif) |
(9) |
 |
(10) |
](images/Example 6.4 Rev 1_11.gif) |
(11) |
, `*`(3, `*`(u[11](zeta))), `-`(`*`(4, `*`(u[10](zeta))))))), `*`(h)))](images/Example 6.4 Rev 1_12.gif) |
(12) |
| > |
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),diff(u(x,y),y)=epsilon/h*u[N+1+i](zeta),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))); |
 |
(13) |
| > |
u[N+1](zeta):=solve(eq[N+1],u[N+1](zeta)); |
))), `*`(`/`(4, 3), `*`(u[10](zeta))))](images/Example 6.4 Rev 1_14.gif) |
(14) |
| > |
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)]: |
| > |
A:=genmatrix(eqns,Y,'b1'): |
| > |
if N>2 then A:=map(evalf,A):end: |
| > |
b:=matrix(2*N,1):for i from 1 to 2*N do b[i,1]:=-b1[i];od:evalm(b): |
 |
(15) |
| > |
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.4 Rev 1_16.gif) |
(16) |
| > |
for i to N do Y0[i,1]:=p[i];od: |
| > |
for i to N do Y0[N+i,1]:=c[i]:od: |
| > |
Y:=evalm(mat&*Y0+mat3): |
For calculating the constants, the solution is evaluated at y = 0 and y = H.
| > |
sol0:=map(eval,evalm(subs(zeta=0,evalm(Y)))): |
| > |
sol1:=map(eval,evalm(subs(zeta=epsilon*H/h,evalm(Y)))): |
The boundary condition at y = 0 (bc3) yields N nonlinear algebraic equations.
| > |
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; |
The boundary condition at y = H yields N linear algebraic equations.
| > |
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; |
Since the equations are nonlinear Maple's 'fsolve' is used to solve for the constants:
| > |
csol:=fsolve({seq(Eq[i],i=1..2*N)},{seq(c[i],i=1..N),seq(p[i],i=1..N)}); |
When 'fsolve' is used Maple returns values that do not make physical sense. The dependent variable at y = 0 (pi, i=1..N) cannot be negative. Since the equations are nonlinear there can be more than one solution. To get the correct solution that makes physical sense the range should be provided for the constants (see Chapter 1).
| > |
csol:=fsolve({seq(Eq[i],i=1..2*N)},{seq(c[i]=0..1,i=1..N),seq(p[i]=0..1,i=1..N)}); |
| > |
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: |
| > |
for i from 0 to N+1 do p[i]:=plot(u[i](y),y=0..H,thickness=3);od: |
| > |
pp:=plot([seq(u[i](y),i=0..N+1,2)],y=0..H,thickness=3,legend=[seq(typeset(u[i],"(y)"),i=0..N+1,2)]); |
![PLOT(CURVES([[0., 0.], [0.108985770833333330e-1, 0.], [0.203813707291666674e-1, 0.], [0.310457639583333334e-1, 0.], [0.417808477083333324e-1, 0.], [0.524649094791666618e-1, 0.], [0.623704023958333298e...](images/Example 6.4 Rev 1_76.gif) |
(21) |
| > |
display({pp},axes=boxed,title="Figure Exp. 6.10.",labels=[y,"u"]); |
 |
(22) |
| > |
T1:=[seq(evalf(i*H/M),i=0..M)]; |
![[0., .1000000000, .2000000000, .3000000000, .4000000000, .5000000000]](images/Example 6.4 Rev 1_79.gif) |
(23) |
| > |
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,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)},title="Figure Exp.6.11.",labels=[x,u]); |
 |
(24) |
![array( 1 .. 12, 1 .. 30, [ ] )](images/Example 6.4 Rev 1_82.gif) |
(25) |
First, the boundaries x = 0 and y = 1 are defined.
| > |
for i to Ny do PP[1,i]:=0;od: |
| > |
for i to N+2 do PP[i,Ny]:=1;od: |
The temperature inside the rectangle is obtained using the seimanalytical solution:
| > |
for i from 2 to N+2 do for j from 1 to Ny-1 do PP[i,j]:=evalf(subs(y=(j-1)*H/(Ny-1),u[i-1](y)));od;od: |
| > |
plotdata := [seq([ seq([(i-1)/(N+1),(j-1)*H/(Ny-1),PP[i,j]], i=1..N+2)], j=1..Ny)]: |
| > |
surfdata(plotdata,axes=boxed,title="Figure Exp. 6.12.",labels=[x,y,u],orientation=[-120,60] ); |