Example 6.3 Rev 1 N 2.mw
Example 6.3
| > |
restart;with(linalg):with(plots): |
The governing equation is entered in the following form:
| > |
ge:=diff(u(x,y),y$2)=2*Pe*(1-x^2)*diff(u(x,y),y)-diff(u(x,y),x$2)-1/x*diff(u(x,y),x); |
 |
(1) |
 |
(2) |
For this example, Digits has to be set to 30 for accurate predictions. The boundary conditions are entered as:
 |
(3) |
 |
(4) |
 |
(5) |
 |
(6) |
Parameters are entered here:
 |
(7) |
 |
(8) |
Note that epsilon is given as 1 for this example since L and H are taken care of separately.
 |
(9) |
 |
(10) |
| > |
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),x=0,bc1): |
| > |
bc2:=subs(diff(u(x,y),x)=subs(m=N+1,dydxb),u(x,y)=u[N+1](zeta),x=1,bc2): |
 |
(11) |
), `-`(`*`(3, `*`(u[0](zeta)))), `*`(4, `*`(u[1](zeta)))))), `*`(h)))](images/Example 6.3 Rev 1 N 2_12.gif) |
(12) |
, `-`(1))](images/Example 6.3 Rev 1 N 2_13.gif) |
(13) |
The governing equation is converted to finite difference form here. Note that the first derivative with respect to 'y' is replaced by u[N+1+i], i= 1..N.
| > |
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; |
, zeta) = `+`(`-`(`*`(`^`(h, 2), `*`(`+`(`/`(`*`(2.0, `*`(`+`(1, `-`(`*`(`^`(h, 2)))), `*`(u[4](zeta)))), `*`(h)), `-`(`/`(`*`(`+`(u[0](zeta), `-`(`*`(2, `*`(u[1](zeta)))), u[2](zeta)))...](images/Example 6.3 Rev 1 N 2_14.gif) |
, zeta) = `+`(`-`(`*`(`^`(h, 2), `*`(`+`(`/`(`*`(2.0, `*`(`+`(1, `-`(`*`(4, `*`(`^`(h, 2))))), `*`(u[5](zeta)))), `*`(h)), `-`(`/`(`*`(`+`(u[1](zeta), `-`(`*`(2, `*`(u[2](zeta)))), u[3]...](images/Example 6.3 Rev 1 N 2_15.gif) |
(14) |
| > |
u[0](zeta):=(solve(eq[0],u[0](zeta))); |
))), `*`(`/`(4, 3), `*`(u[1](zeta))))](images/Example 6.3 Rev 1 N 2_16.gif) |
(15) |
| > |
u[N+1](zeta):=solve(eq[N+1],u[N+1](zeta)); |
 |
(16) |
| > |
for i from 1 to N do eq[i]:=diff(u[i](zeta),zeta)= -u[N+1+i](zeta);od; |
, zeta) = `+`(`-`(u[4](zeta)))](images/Example 6.3 Rev 1 N 2_18.gif) |
, zeta) = `+`(`-`(u[5](zeta)))](images/Example 6.3 Rev 1 N 2_19.gif) |
(17) |
 |
(18) |
| > |
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[4](zeta), u[5](zeta)]](images/Example 6.3 Rev 1 N 2_25.gif) |
(20) |
| > |
A:=genmatrix(eqns,Y,'b1'): |
 |
(21) |
| > |
for i to Nrow do
lambda[i]:=II[i];
end do: |
| > |
Id:=Matrix(Nrow,Nrow,shape=identity): |
| > |
X:=matrix(Nrow,1,[seq(beta[i],i=1..Nrow)]): |
| > |
for k to Nrow do
G:=evalm((A-lambda[k]*Id)&*X);
eqx[1]:=beta[1]=1:
for i from 2 to Nrow do
eqx[i]:=G[i-1,1]:
end do:
cons:=fsolve({seq(eqx[i],i=1..Nrow)},{seq(beta[i],i=1..Nrow)}):
assign(cons):
XX[k]:=map(eval,evalm(X)):
for i to Nrow do
unassign('beta[i]'):
end do:
end do: |
| > |
PV:=Matrix(Nrow,Nrow,[seq(evalm(XX[i]),i=1..Nrow)]): |
| > |
expD1:=Matrix(1..Nrow,1..Nrow,shape=diagonal): |
| > |
for i to Nrow do
expD1[i,i]:=exp(lambda[i]*zeta):
end do: |
| > |
mat:=evalm(PV&*expD1&*inverse(PV)): |
| > |
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): |
 |
(22) |
| > |
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 .. 4, 1 .. 1, [ ] )](images/Example 6.3 Rev 1 N 2_28.gif) |
(23) |
| > |
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 .. 4, 1 .. 1, [( 4, 1 ) = c[2], ( 1, 1 ) = p[1], ( 2, 1 ) = p[2], ( 3, 1 ) = c[1] ] )](images/Example 6.3 Rev 1 N 2_29.gif) |
(24) |
| > |
Y:=evalm(mat&*Y0+mat3): |
The solution should be evaluated at y = H to find the constants.
| > |
sol0:=map(eval,evalm(subs(zeta=0,evalm(Y)))): |
| > |
sol1:=map(eval,evalm(subs(zeta=epsilon*H/h,evalm(Y)))): |
| > |
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; |
![p[1]](images/Example 6.3 Rev 1 N 2_30.gif) |
![p[2]](images/Example 6.3 Rev 1 N 2_31.gif) |
(25) |
| > |
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: |
Constants are found as:
| > |
csol:=solve({seq(Eq[i],i=1..2*N)},{seq(c[i],i=1..N),seq(p[i],i=1..N)}); |
![{p[1] = 0., p[2] = 0., c[1] = -.858108358579488322991339031491, c[2] = -1.26533280909404939637330945180}](images/Example 6.3 Rev 1 N 2_32.gif) |
(26) |
| > |
for i from 1 to N do u[i](zeta):=eval((Y[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 following plots are obtained using N = 10 interior node points. Digist = 30 is required for N = 10 interior node points. For N = 3 node points, the default number of Digits = 10 is enough.
| > |
for i from 0 to N+1 by 2 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.12e-28], [0.435943083333333333333333333334e-1, 0.93182594458345703053701763918e-1], [0.815254829166666666666666666667e-1, .171183100476791492485971162412], [.124183055833333333333...](images/Example 6.3 Rev 1 N 2_33.gif) |
(27) |
| > |
display(pp,axes=boxed,title="Figure Exp.6.7.",labels=[y,"u"]); |
 |
(28) |
| > |
T1:=[seq(evalf(i*H/M),i=0..M)]: |
| > |
P[1]:=plot([seq([h*i,0.],i=0..N+1)],style=line,thickness=3,axes=boxed): |
| > |
for j from 2 to M+1 do P[j]:=plot([seq([h*i,evalf(subs(y=T1[j],evalf(u[i](y))))],i=0..N+1)],style=line,thickness=3,title="Figure Exp. 6.8.",axes=boxed):od: |
| > |
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,left});
od: |
| > |
display({seq(P[i],i=1..M+1),seq(pt[i],i=1..M+1)},labels=[x,u]); |
| Error:TEXT location must be numeric; received: [.5, u[5](1.60000000000000000000000000000)] |
|
| > |
a:=convert(T1[2],string); |
 |
(29) |
| > |
a1:=sprintf("%4.2f",T1[2]); |
 |
(30) |
 |
(31) |
![array( 1 .. 4, 1 .. 30, [ ] )](images/Example 6.3 Rev 1 N 2_39.gif) |
(32) |
| > |
for i from 1 to N+2 do for j from 1 to Ny do PP[i,j]:=evalf(subs(y=(j-1)*H/(Ny-1),u[i-1](y)));od;od: |
 |
(33) |
| > |
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.9.", labels=[x,y,u],orientation=[-150,45] ); |