Example 3.7a
Consider the convective diffusion problem (Finlayson,1980)[11]
(3.65)
An analytical solution can be obtained using the exponential matrix method described in section 3.1.2:
This particular problem was chosen as the finite difference solution for this equation and shows oscillations for high Peclet numbers when the central difference expression is used for the first derivative. This equation is solved below using the procedure described above.
| > |
with(linalg):with(plots): |
 |
(1) |
 |
(2) |
| > |
eq:=diff(y(x),x$2)-Pe*diff(y(x),x); |
 |
(3) |
 |
(4) |
 |
(5) |
Central difference expressions for the second and first derivatives are
| > |
d2ydx2:=(y[m+1]-2*y[m]+y[m-1])/h^2; |
![`/`(`*`(`+`(y[`+`(m, 1)], `-`(`*`(2, `*`(y[m]))), y[`+`(m, `-`(1))])), `*`(`^`(h, 2)))](images/Example3.7a rev 1_10.gif) |
(6) |
| > |
dydx:=(y[m+1]-y[m-1])/2/h; |
![`+`(`/`(`*`(`/`(1, 2), `*`(`+`(y[`+`(m, 1)], `-`(y[`+`(m, `-`(1))])))), `*`(h)))](images/Example3.7a rev 1_11.gif) |
(7) |
The governing equation in finite difference form is:
| > |
Eq[m]:=subs(diff(y(x),x$2)=d2ydx2,diff(y(x),x)=dydx,y(x)=y[m],x=m*h,eq); |
![`+`(`/`(`*`(`+`(y[`+`(m, 1)], `-`(`*`(2, `*`(y[m]))), y[`+`(m, `-`(1))])), `*`(`^`(h, 2))), `-`(`/`(`*`(`/`(1, 2), `*`(Pe, `*`(`+`(y[`+`(m, 1)], `-`(y[`+`(m, `-`(1))]))))), `*`(h))))](images/Example3.7a rev 1_12.gif) |
(8) |
A 'for loop' can be written for the interior node points as
| > |
for i to N do Eq[i]:=subs(m=i,Eq[m]);od; |
![y[0] = 1](images/Example3.7a rev 1_17.gif) |
(10) |
![y[5] = 0](images/Example3.7a rev 1_18.gif) |
(11) |
| > |
y[0]:=solve(Eq[0],y[0]); |
 |
(12) |
| > |
y[N+1]:=solve(Eq[N+1],y[N+1]); |
 |
(13) |
 |
(14) |
| > |
for i to N do Eq[i]:=eval(Eq[i]);od; |
| > |
eqs:=[seq(Eq[i],i=1..N)]; |
![[`+`(`*`(25, `*`(y[2])), `-`(`*`(50, `*`(y[1]))), 25, `-`(`*`(`/`(5, 2), `*`(Pe, `*`(`+`(y[2], `-`(1))))))), `+`(`*`(25, `*`(y[3])), `-`(`*`(50, `*`(y[2]))), `*`(25, `*`(y[1])), `-`(`*`(`/`(5, 2), `*`...](images/Example3.7a rev 1_26.gif)
![[`+`(`*`(25, `*`(y[2])), `-`(`*`(50, `*`(y[1]))), 25, `-`(`*`(`/`(5, 2), `*`(Pe, `*`(`+`(y[2], `-`(1))))))), `+`(`*`(25, `*`(y[3])), `-`(`*`(50, `*`(y[2]))), `*`(25, `*`(y[1])), `-`(`*`(`/`(5, 2), `*`...](images/Example3.7a rev 1_27.gif) |
(16) |
| > |
vars:=[seq(y[i],i=1..N)]; |
![[y[1], y[2], y[3], y[4]]](images/Example3.7a rev 1_28.gif) |
(17) |
| > |
A:=genmatrix(eqs,vars,'B1'); |
 |
(18) |
 |
(19) |
Maple generates a row vector, which can be converted to a column vector as:
| > |
B:=matrix(N,1):for i to N do B[i,1]:=B1[i]:od:evalm(B); |
 |
(20) |
The solution is obtained as:
| > |
X:=evalm(inverse(A)&*B); |
 |
(21) |
| > |
for i to N do y[i]:=X[i,1];od; |
| > |
y[0]:=eval(y[0]);y[N+1]:=eval(y[N+1]); |
 |
 |
(23) |
Next, the result obtained is compared with the exact analytical solution:
| > |
ya:=(exp(Pe)-exp(Pe*x))/(exp(Pe)-1); |
 |
(24) |
| > |
p1:=plot([seq([i*h,subs(Pe=1,y[i])],i=0..N+1)],thickness=4,color=blue,axes=boxed): |
| > |
p2:=plot(subs(Pe=1,ya),x=0..1,thickness=8,color=brown,axes=boxed,linestyle=2): |
| > |
display({p1,p2},title="Figure Exp. 3.1.9.",labels=[x,"y"]); |
We observe that both the finite difference solution and the analytical solution match exactly when the Peclet number is 1. New plots can be obtained for different values of the Peclet number as follows:
| > |
p1:=plot([seq([i*h,subs(Pe=50,y[i])],i=0..N+1)],color=blue,thickness=4,axes=boxed): |
| > |
p2:=plot(subs(Pe=50,ya),x=0..1,thickness=5,color=brown,axes=boxed,linestyle=2): |
| > |
display({p1,p2},title="Figure Exp. 3.1.10.",labels=[x,"y"]); |
This shows that for Pe = 50, four interior node points are not enough and we observe oscillations.[11][12] This happens usually when central difference approximations are used for the convective term
. Use a forward approximation for the first derivative to solve this problem. Only dydx in the Maple program needs to be changed: