You are on page 1of 5

CHE 3167 Transport Phenomena and Numerical Methods

SOLUTION TO COMPUTER LAB EXAM - 1.1


14-03-2011 25 marks
1. A gas A dissolves in liquid B in a beaker, and diuses isothermally into the liquid phase.
As it diuses, A also undergoes an irreversible rst-order homogeneous reaction: A+B
AB. It can be shown that the concentration of A in the liquid, from the surface of the
liquid in the beaker, at z = 0, to the bottom of the beaker, at z = L, is given by the
expression:
c
A
c
A0
=
cosh

(1 (z/L)

cosh

where, c
A0
is the concentration of A at the surface of the liquid in the beaker, and
is a dimensionless group known as the Thiele modulus. Write an M-le that computes
the dimensionless concentration c
A
/c
A0
as a function of the dimensionless distance z/L
and . Use the linspace function to generate 100 equally spaced values of z/L within
the interval [0, 1]. Plot c
A
/c
A0
versus z/L for three dierent values of namely, = 1,
= 10 and = 120. Use the hold on command to display all the plots on the same
graph. Use dierent colours for the dierent curves corresponding to dierent values of
. Give the gure a title, and display legends using the legend command, and label the
x-axis and y-axis.
10 Marks
Solution:
M-File: concentration.m
function concentration
zoverL=linspace(0,1,100);
phi=[1,10,120];
clf
c=cosh(sqrt(phi(1))*(1-zoverL))/cosh(sqrt(phi(1)));
plot(zoverL,c,r)
hold on
c=cosh(sqrt(phi(2))*(1-zoverL))/cosh(sqrt(phi(2)));
plot(zoverL,c,b)
c=cosh(sqrt(phi(3))*(1-zoverL))/cosh(sqrt(phi(3)));
plot(zoverL,c,k)
title(Diffusion with a homogeneous chemical reaction)
legend(phi=1,phi=10,phi=120)
xlabel(Dimensionless distance from top surface)
ylabel(Dimensionless concentration)
end
1
This function can be invoked on the command line, and would lead to g.1 below:
>> concentration
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Diffusion with a homogeneous chemical reaction
Dimensionless distance from top surface
D
i
m
e
n
s
i
o
n
l
e
s
s

c
o
n
c
e
n
t
r
a
t
i
o
n
phi=1
phi=10
phi=120
Figure 1: Problem 1
2. In the problem above, the nondimensional molar ux N
Az
=
d(c
A
/c
A0
)
d(z/L)
, at z = 0, can
be found to be:
N
Az
|
z=0
=

tanh

(1)
Modify the M-le in problem 1 to compute the nondimensional molar ux at the surface,
using equation (1), as a function of . The molar ux can also be estimated numerically
by using its denition as a derivative of the concentration gradient. A simple way of
estimating a derivative in MATLAB is to use the di function. Given a one dimensional
array of length n, the di function returns a vector of length n 1 containing dierences
between adjacent elements. For an array of elements x, if for some function y = f(x), the
array y is evaluated by y = f(x), then di(y)./di(x) gives the approximate value of the
derivative of f(x) at the midpoint between adjacent elements of x. For each of the values
of from problem 1, use the di function to obtain an approximate numerical estimate
of the derivative of the concentration prole in the beaker. Note that the numerical
derivative evaluated at the value of z which is closest to z = 0 is approximately equal to
the molar ux at the surface. Compare the value of the ux obtained with the analytical
expression with the numerical value, and nd the percentage relative error. Use the fprintf
2
command to display the analytical and numerical uxes, and the relative error for each
value of .
10 Marks
Solution:
M-File: concandux.m
function concandflux
zoverL=linspace(0,1,100);
phi=[1,10,120];
clf
c=cosh(sqrt(phi(1))*(1-zoverL))/cosh(sqrt(phi(1)));
plot(zoverL,c,r)
hold on
c=cosh(sqrt(phi(2))*(1-zoverL))/cosh(sqrt(phi(2)));
plot(zoverL,c,b)
c=cosh(sqrt(phi(3))*(1-zoverL))/cosh(sqrt(phi(3)));
plot(zoverL,c,k)
title(Diffusion with a homogeneous chemical reaction)
legend(phi=1,phi=10,phi=120)
xlabel(Dimensionless distance from top surface)
ylabel(Dimensionless concentration)
%
%CALCULATION OF FLUX AT THE SURFACE
%
n=length(phi);
for i=1:n
c=cosh(sqrt(phi(i))*(1-zoverL))/cosh(sqrt(phi(i)));
deriv = - diff(c)./diff(zoverL);
numflux =deriv(1);
anflux = sqrt(phi(i))*tanh(sqrt(phi(i)));
relerr = ((anflux -numflux)/anflux)*100.0;
disp( )
fprintf(phi = %8.4f \n, phi(i))
fprintf(analytical flux = %8.4f \n, anflux)
fprintf(numerical flux = %8.4f \n, numflux)
fprintf(relative error = %8.4f \n, relerr)
end
This function can be invoked on the command line and would lead to:
>> concandflux
3
phi = 1.0000
analytical flux = 0.7616
numerical flux = 0.7566
relative error = 0.6615
phi = 10.0000
analytical flux = 3.1510
numerical flux = 3.1010
relative error = 1.5860
phi = 120.0000
analytical flux = 10.9545
numerical flux = 10.3701
relative error = 5.3340
3. Consider the following M-le:
tstart = 0;
tend = 20;
ni = 5;
t(1) = tstart;
y(1) = 10+5*cos((2*pi*t(1))/(tend-tstart));
for i = 2:ni+1
t(i) = t(i-1)+(tend-tstart)/ni;
y(i) = 10+5*cos((2*pi*t(i))/(tend-tstart));
end
Write a function M-le that is a vectorized version of this code. Pass the values of ttsart,
tend, and ni in the argument list of the function.
5 Marks
Solution:
M-File: vectorcode.m
function vectorcode(tstart,tend,ni)
t=tstart:(tend-tstart)/ni:tend;
y=10+5*cos(2*pi*t/(tend-tstart));
fprintf(y = %8.4f \n, y)
end
This function can be invoked on the command line and would lead to:
4
>> vectorcode(0,20,5)
y = 15.0000
y = 11.5451
y = 5.9549
y = 5.9549
y = 11.5451
y = 15.0000
5