





















Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!






















Mathematical Software Session
John J. Hwalek, Department of Chemical Engineering
University of Maine, Orono, Me 04469-5737 ([email protected])
This document contains Mathcad solutions for a set of chemical engineering problems developed
for the Use of Mathematical Software Packages in Chemical Engineering Education Session at the
ASEE Chemical Engineering Summer School held in Snowbird, Utah on August 13, 1997. The
problems chosen are representative of numerical problems that are typically found in most
chemical engineering undergraduate courses.
Mathcad is a commercial software package developed by MathSoft, Inc. It is widely used by
engineers, scientists and mathematicians in universities as well as industry. Mathcad allows for the
integration of equations, text and graphics in a WYSIWYG interface. It has built into it a wide
variety of numerical routines to solve problems including simultaneous nonlinear equations,
systems of ordinary differential equations, numerical integration and differentiation, regression
and curve fitting as well as many other powerful features. Complete details of Mathcad's features,
system requirements and academic pricing can be found on the MathSoft Web site
(www.mathsoft.com). The solutions presented here are available at the Chemical Engineering
Mathcad Users' Group Web site
( ftp://ftp.umecheme.maine.edu/mathcad/asee).
Mathcad Solution to Problem 1
Mathcad uses a structure called a solve block to solve non-linear equations. The solve block
starts with a Given statement and ends with a Find which includes the variables to be solved
for. Mathcad requires an initial guess of the solution before the start of the solve block. Note
that Mathcad allows for dimensional variables with automatic units conversion and the final
solution can be expressed in any desired units.
The equation to be solved is the van der Waals equation:
a
2
( V b)
Define the constants to be used in the calculations (units included).
atm liter
mole K
For ammonia: T c
c
111.3 atm
a
2 T c
2 .
c
a 4.
atm liter
2 .
mole
2
= b
c
c
b 0.
liter
mole
a) Specify T and P: P 56 atm
Solve for the molar volume using a solve block
liter
mole
Initial guess of V using Ideal Gas Law:
Given Start of Solve Block
a
2
( V b)
Equation to be solved
V Find V( ) V 0.
liter
mole
= End of Solve Block
In the Find statement above, Mathcad solves for the value of the unknown variable but does
not change the value of the variable (V). Therefore, the value of the solution of the equation is
assigned to the variable (V) so that it can be used in subsequent calculations (e.g., calculation
of the compressibility factor (Z).
Mathcad Solution to Problem 2
There are two approaches to solving this problem in Mathcad. The first is to simply include
all of the equations in a Solve Block and solve for the unknown variables. This simplifies the
formulation of the numerical problem because the problem does not need to be rewritten in
matrix form. In the second method, the problem is broken up into a problem requiring the
solution of 4 simultaneous linear equations followed by a series of simple algebraic equations.
First method solving all of the equations in a solve block
Defined feed rate and mole fractions.
F 70 x FX
0.15 x FS
0.25 x FT
0.4 x FB
x D1X
0.07 x D1S
0.04 x D1T
0.54 x D1B
x B1X
0.18 x B1S
0.24 x B1T
0.42 x B1B
x D2X
0.15 x D2S
0.10 x D2T
0.54 x D2B
x B2X
0.24 x B2S
0.65 x B2T
0.10 x B2B
Guess values of flow rates
and mole fractions:
x DX
0.25 x DS
0.25 x DT
0.25 x DB
x BX
0.25 x BS
0.25 x BT
0.25 x BB
Given
Component balances over entire system
x FX
x D1X
x B1X
x D2X
x B2X
x FS
x D1S
x B1S
x D2S
x B2S
x FT
x D1T
x B1T
x D2T
x B2T
x FB
x D1B
x B1B
x D2B
x B2B
Overall Balances on columns #2 and #
Component balances over column #2 Component balances over column #
x DX
x D1X
x B1X
x BX
x D2X
x B2X
x DS
x D1S
x B1S
x BS
x D2S
x B2S
x DT
x D1T
x B1T
x BT
x D2T
x B2T
x DB
x D1B
x B1B
x BB
x D2B
x B2B
x DX
x DS
x DXT
x DXB
x BX
x BS
x BT
x BB
Find D B, D 1
, x DX
, x DS
, x DT
, x DB
, x BX
, x BS
, x BT
, x BB
Mathcad Solution to Problem 3
There are a variety of ways to solve this problem in Mathcad. To fit a polynomial, the
Mathcad function, linfit, can be used to fit any linear combination of arbitrary functions in the
form y = a 0
coefficients of the linear combination.
Both the Clausius-Clapeyron and Antoine equations can be rewritten in a form so that linear
regression can be used. Otherwise, a non-linear least-squares technique could be applied.
a) To fit an n th order polynomial, an vector containing the n+1 functions is used in the linfit
function. The function also requires the vectors containing the data. To calculate the
variance of the error, the Mathcad function var^ is used. This example shows the calculation
for the polynomial that gave the smallest variance. The variance for other polynomials is
shown in a table below.
Define vectors T and P containing the data:
Define the vector of functions, F(x), to be fit:
F x( )
x
x
2
x
3
x
4
x
5
Use the last function to count the number of data points, ndata, and the number of terms in
the function array. Note that Mathcad starts vectors and matrices with index 0 as the default.
The last^ function actually gives the index of the last term in the vector.
ndata last T( ) i 0 .. ndata n last F 1( ( ))
Results:
Order Variance
c linfit T P( , ,F)
c
Calculate the errors
and then the variance
error i
i
n
j
c j
i
j .
var error( ) =0.
Plot the results for the polynomial fit
P i
0
n
j
c j
T i
j .
=
T i
40 20 0 20 40 60 80 100
0
200
400
600
800
For the Clausius-Clapeyron and Antoine equations the equations can be rearranged into a form
so that linear regression can be used. By multiplying by the denominator of the second term on
the right hand side and rearranging algebraically, the following equations are obtained:
Clausius-Clapeyron: log(P) = A - B/(T+273.15)
Antoine: Tlog(P) = AT - Clog(P) + [AC - B]
For the Clausius-Clapeyron equation linear regression can be used by setting y = log(P) and
x = 1/(T+273.15). The slope = -B and the intercept = A. Mathcad has slope and intercept
functions for linear regression.
For the Antoine equation, least squares is used using a psuedo-inverse calculation.
b) Fitting the Clausius-Clapeyron equation.
x i
i
y i
log P i
A intercept x y( , ) A =8.
B slope x y( , ) B 2.035 10
Calculate the errors
and then the variance
error i
log P i
i
var error( ) 6.073244 10
Mathcad Solution to Problem 4
This problem can be solved directly using a Mathcad Solve Block. The Solve Block includes
the equilibrium equations as well as the equations describing the stoichiometry. An initial
guess must be made for the concentrations. Initial guesses will be used as given.
Given initial concentrations and equilibrium constants: C A
a) First set of initial guesses: C D
Given
Find C A
b) Second set of initial guesses: C D
Given
Find C A
c) Third set of initial guesses: C D
Given
Find C A
Mathcad gives the same results for all sets of starting values.
b) Mathcad has the gravitational acceleration predefined. For this case, g is redefined as 30g.
g 30 g.^ Guess: v t
m
sec
Given
v t
4 g
ρ p
ρ
p
Re v t
ρ
v t
Find v t
Answer: v t
m
sec
= Re v t
Mathcad Solution to Problem 6
Mathcad has built-in a variety of differential equation solvers. In this case, an adaptive
Runge-Kutta method will be used since the solution varies slowly with time and all of the
functions vary on the same time scale (i.e., they are not stiff).
System physical constants and properties kg 1 min 1 kJ 1 C 1
Mass of oil in each tank: M 1000 kg
Oil mass flow rate: W 100
kg
min
Oil heat capacity: C p
kJ
kg C
Temperature of entering oil: T 0
Steam temperature: T steam
Heat transfer coefficient: UA 10
kJ
min C
Calculate the steady state temperature by setting derivatives to zero and solving remaining
equations using a Mathcad Solve Block.
Initial guess for temperatures: T1ss 20 T2ss 20 T3ss 30
Given
p
T1ss
steam
T1ss
p
p
( T1ss T2ss)
steam
T2ss
p
p
( T2ss T3ss)
steam
T3ss
p
T1ss
T2ss
T3ss
Find T1ss T2ss( , ,T3ss)
Steady state temperatures: T1ss = 30.952 C T2ss = 41.383 C T3ss =51.317 C
Mathcad Solution to Problem 7
The solution to this problem will use Mathcad's ability to solve two point boundary value
problems. The solution method has two parts. In the first part, Mathcad estimates the missing
boundary conditions at the first point. These estimated values are then used in the standard ODE
solvers to find the solution between the two boindary points. Check the Mathcad help files for
more details on using this method.
Assign values to the pysical properties and dimensions for the problem
Diffusivity D AB
9 . Reaction rate constant k 10
3
Initial concnetration: C A
0.2 Slab depth: L 10
3
Set position of first and second point and step size: z1 0 z2 L ∆z
Mathcad uses the load and score functions in estimating the missing initial conditions
Initial guess for vector of unknown initial conditions: v 0
Initial conditions (including guess vector): load z1 v( , )
v 0
Vector of functions representing the right hand side of the differential equations:
D z C( , )
1
k
0
Score function is a measure of the difference between the computed and given values at the end
point.
score z2 C( , ) C 1
Function sbval calculates the missing initial conditions:
1
sbval v 0( , , L, D, load,score) C 1
Now solve the differential equation using the estimated value of the inital conditions.
0
z 0
0 z end
L npoints
∆z
Y Rkadapt C z 0
, z end
, , npoints,D
Assign columns of the solution array to vectors for clarity
n 0 .. npoints z n
n 0,^
n
n 1,^
dC A n
n 2,
Verify boundary value at endpoint (dC A /dz = 0)
dC A npoints
= Close enough!
Plot solution and compare with analytical solution
C A n
C A
cosh L
k
D AB
. 1
z n
L
.
cosh L
k
D AB
.
.
z n
0 2 10
4 4 10
4 6 10
4 8 10
4
Numerical solution matches analytical solution very closely.
Now solve the unsteady state material balance equation using the adaptive Runge-Kutta method
Initial condition: L 0
100 mole
Define the function on the right hand side of the differential equation:
D x 2
x 2
k 2
x 2
Set initial and final values x 2i
0.4 x 2f
0.8 ∆x 2
0.01 npoints
x 2f
x 2i
∆x 2
Solve the differential equation: Z Rkadapt L x 2i
, x 2f
, , npoints,D
i 0 .. npoints L i
i 1,^
x 2 i
i 0,
Teq x 2i
= 95.585 C y 2
x 2i
= 0.213 k 2
x 2i
Initial values: L 0
Final conditions :L npoints
= 14.042 Teq x 2f
= 108.572 C y 2
x 2f
= 0.629 k 2
x 2f
Plot of mass of liquid remaining
L i
x 2 i
0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.
0
20
40
60
80
100
Mathcad Solution to Problem 9
This problem involves the solution of 3 simultaneous ODEs and uses the adaptive
Runge-Kutta Method built into Mathcad.
Define auxiliary units: J^ joule^ dm^
m
mole K
Physical properties and other parameters as given in the problem statement
Heat capacities: C PA
mole K
mole K
Heat of reaction: ∆H R
mole
Activation energy: E A
mole K
k 450
dm
6
kg min mole Arrhenius constant at 450 K:
Equilibrium constant at 450 K: K C
dm
3
mole
Heat transfer coefficient: UA^
kg min K
Coolant temperature: T a
Initial flow rate, concentration and pressure: F A
mole
min
mole
dm
3
10 atm
y A
Initial temperature and gas mole fraction of A: T 0
Constant used in calculating pressure drop: α^
0.015 kg
1
Kinetic rate expression: k(^ T^ )
k 450
exp
Equilibrium expression: K C
exp
Concentrations expressed as a function of conversion, vapor mole fraction and temperature
( X y T, , )
y
( X y T, , )
y