We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 162
UNIVERSIDAD NACIONAL DE JUJUY
BIBLIOTECA
invent. ING.6445
Top. 66.0:004.4
Mathcad for
Chemical Engineers
Second Edition
Hertanto Adidharma
University of Wyoming
Valery Temyanko
University of Arizona
TOP: 66.0:004.4 ADI 2.e. - N° Inventario: ING.6445
IVACUContents
Preface to the Second Edition
Chapter 1. Introduction
Chapter 2. Getting Started with Mathcad
2.1. Mathcad Worksheet and User Interface
2.2. Variables and Functions
2.3. Arrays: Vector and Matrix
2.4. Working with Units
2.5. Graphics Features
2.6. Symbolic Math Capabilities
Example set 2.1
Problems
Chapter 3, Non-Linear Equation
3.1. Polynomial
Example set 3.1
3.2. Non-Polynomial
Example set 3.2
Problems
Chapter 4. System of Equations
4.1. System of Linear Equations
Example set 4.1
4.2, System of Non-Linear Equations
Example set 4.2
4.3, System of Equations with Constraints
Example set 4.3Contents
Problems
Chapter 5. Curve Fitting
5.1. Interpolation
5.1.1. Linear Interpolation
5.1.2. Cubic Spline
Example set 5.1
5.2. Regression
5.2.1. Linear Regression
5.2.2. Polynomial Regression
5.2.3, Non-Linear Regression
Example set 5.2
Problems
Chapter 6, Differentiation and Integration
6.1. Differentiation
Example set 6.1
6.2. Integration
Example set 6.2
Problems
Chapter 7. Optimization
7.1. Extreme Value Problem
7.1.1. Unconstrained Function
7.1.2. Constrained Function
Example set 7.1
7.2. Linear Programming
Example set 7.2
7.3. Non-Linear Programming
Example set 7.3
Problems
52
61
61
61
62
65
67
70
71
7a
79
79
82
91
91
91
94
96
97
98
101
102
104Contents
Chapter 8. Differential Equation
8.1. Ordinary Differential Equation
8.1.1. First Order ODE
8.1.2. System of First Order ODEs
8.1.3. Higher Order ODE — Initial Value
Problem
8.1.4. Higher Order ODE ~ Boundary
Value Problem
8.1.5. Second Order ODE ~ Cylindrical/
Spherical Coordinate
8.1.6. System of Higher Order ODEs
Example set 8.1
8.2. Partial Differential Equation
8.2.1. Parabolic PDE
8.2.2. System of Parabolic PDEs
8.2.3. Elliptic PDE
Example set 8.2
Problems
Chapter 9. Miscellaneous
9.1. Data Handling
9.2. Data Exchange with Excel
93. Introduction to Mathcad Programming
9.3.1. Conditional (ifStatement)
9.3.2. Loops (fox/ while Statement)
Example set 9.1
Problems
Index.
109
109
109
113
114
116
118
119
121
124
125
127
128
129
131
141
141
141
144
145
147
154Chapter 1 + Introduction 1
hapter 1
troduction
The profession of chemical engineering officially started as ear-
ly as 1888, when Professor Lewis Norton of the Massachusetts Institute
of Technology introduced “Course X” and united chemical engineers
with a formal degree. Soon after that, Tulane University and the Univer
sity of Pennsylvania followed the suit by adding four-year program to
their curriculum. The first programs were the combination of mechani-
cal engineering and chemistry with an emphasis on the industrial needs
of that time. Indeed, the challenges at that time required very different
logics compared to what modern chemical engineers are facing today.
‘The complexity of the logics grew as the process requirement became
more demanding due to economical, environmental, and/or technologi-
cal considerations.
Nowadays, in performing their tasks, such as operation, equip-
ment design, process design, process control, and process analysis, chem-
ical engineers utilize more sophisticated mathematical frameworks. As
shown in Figure 1.1, the problem solving in chemical engineering in-
volves several steps. First, the physical problem with all of the con-
straints must be clearly defined. At this stage, it is also very important to
properly state the final goal. Second, a mathematical model of the sys-
tem of interest has to be formulated using fundamental theories such as
force balance, momentum, heat, and mass balance, thermodynamics, and
rate laws (momentum, heat, and mass transfer, kinetics). This is a critical
step in problem solving. If a model is incorrectly formulated, one will
obtain erroneous results although the mathematical solution of the mod-
elis perfect. fo
Third, after a mathematical model has been correctly formulated,
the task is reduced to how to solve it fast and reliably. Before the com-
puter era, mathematical models had to be simple enough so that analyti-
cal or numerical solutions can be obtained in a reasonable period of time.
Since numerical solutions in the past were very time consuming, if
achievable at all, chemical engineers sacrificed the accuracy of the solu-
tions by oversimplifying the problems. Fortunately, modern computing
allows us to perform such tasks much faster and deal with more and
more complex mathematical formulations. This means that unnecessary2 Chapter 1 + Introduction
assumptions in developing mathematical models could be removed, op-
timization of an integrated system could be performed, and what-if anal-
ysis could be easily done, When a numerical method or procedure is de-
veloped, it must be carefully and rigorously checked for errors and tested
on some problems of known solutions.
Due to the advanced improvement on the mathematical software
packages, many basic numerical methods, such as routines (functions) for
solving non-linear equations and ordinary differential equations, have
been at our fingertips, Thus, the errors originated from numerical me-
thods used can be minimized.
Fourth, after a mathematical solution has been obtained, result
verification must be performed to ensure the correctness of the problem
solution. This can be done by critically analyzing the results and/or
comparing with the available experimental data. Of course, in analyzing
the results, logical thinking, good sense, and deep understanding of the
fundamental theories underlying the physical problem are needed. If the
results violate theories, do not make sense, or do not agree with experi-
mental data, a revision of the model or numerical approach should be
considered.
Figure 1.1, Problem solving in chemical engineering
The success of problem solving in chemical engineering is clearly
determined by the accuracy of the model, the versatility of the computa~
tion, and the capacity of analysis. The first factor calls for a thorough
understanding of the fundamental theories underlying the physical
problem, the second calls for a versatile and powerful computational
tool, and the third calls for both understanding theories and computa-
tional tool. Therefore, learning a computational tool is critical in chemi-
cal engineering.
We need a computational tool for a certain problem not only to
solve the mathematical model obtained, but also to learn the behavior of
the system, for which what-if analysis is usually performed. We intui-Chapter 1 + Introduction 3
tively like to experiment, by varying parameters and variables and ana-
lyzing their effects, to obtain a better understanding of the system beha-
vior. Learning by doing, experiencing, and observing is usually very ef-
fective.
‘The desired computational tool should therefore provide us with
not only robust numerical tools, but also easy ways to interpret and ana-
lyze the results of different scenarios. Mathcad is one of such tools that
we will learn in this book.Mathcad Worksheet and User Interface
Chapter 2 * Getting Started with Mathcad
apter 2
tting Started with Mathcad
As in learning other software packages, in learning Mathcad,
before we can develop more complicated procedures to solve mathemat-
ical problems, we need to understand Mathcad’s basic features, such as
definition and syntax. The effort needed for this purpose is minimal and
much less than that needed for learning other software packages because
Mathead’s basic features, as we will find later, are very intuitive. Howev-
er, one should not overlook the details to avoid unnecessary mistakes.
Keep in mind that bad input or instruction produces bad output or result
(garbage in, garbage out).
If we are familiar with other program packages run on Windows,
such as Microsoft Word or Excel, we will find the Mathcad user inter-
face very familiar. As shown in Figure 2.1, Mathcad has Menu Bar, Stan
dard Toolbar, Formatting Toolbar, and Math Toolbar. A tool bar that is
different from that in many Windows applications is the Math Toolbar.
This Math Toolbar makes mathematical calculations very easy and con-
venient to perform. The Math Toolbar allows a user to access all mathe-
matical symbols and operations. If we click on any button on this bar we
will see an expanded toolbar under the specified category on the screen.
The following buttons are available from the Math toolbar:
Calculator Toolbar
Graph Toolbar
Vector and Matrix Toolbar
Evaluation Toolbar
Calculus Toolbar
Boolean Toolbar
Programming Toolbar
Greek Symbol Toolbar
ye PN any es wp yo
Symbolic Keyword Toolbar6 Chapter 2 « Getting Started with Mathcad
eau Bat
6 1 Star Toot
‘= Farting Totter
Plug Flow Reactor Design
“hie werksheet i an example how ocesign a plug lew rector using Matnese
Fate constant: ogois #*! Concenraton ef Alnthe reed: Ca
ene rt eprint) =k Gy (1-Xa)
omonratecreacanthaterennes: ig, <2
on sutton for ug How etre dered rommal balance:
Ygsaltne| ya For Me08) yaaa oar?
“0 Ma=O8: VotCos) = 643807
Figure 2.1, Mathcad Worksheet and Liser Interface
We can find out the name of each toolbar by letting the mouse
pointer rest on a button, The function of each toolbar is pretty much
self-explanatory. For example, the Calculator Toolbar contains all of the
basic arithmetic operators we usually find in a calculator. Some of them
can also be directly typed through the computer keyboard, for example
“for multiplication, ‘/* for division, “*” for power, etc. We will learn
and use most of the toolbars as needed in the subsequent sections and
chapters,
Mathcad is essentially a worksheet for calculations. If we look at
Figure 2.1 once again, one of the nicest features of Mathcad becomes ob-
vious ~ we could develop a solution procedure just as we would do it on
paper. We type the problem statement and variable definitions, then va-
riable assignments, function definitions, and mathematical equations of
the solution, and finally, graphical representation of the solution. Note
that we can type math equations just as we would write them on paper.
This is a natural and intuitive way to develop a problem solution, making
it very easy to read and debug if necessary. Text, tables, equations, and
graphs can be mixed on the same worksheet. To insert a text region, for
example, type a double quotation mark (") (or click Insert, Text Region
from the Menu Bar) and type the text we want. Thus, we can use Math-
cad not only to obtain the results but also to elegantly present them..2 Variables and Functions
Chapter 2+ Getting Started with Mathcad
The power and versatility of Mathcad become evident from the
use of variables and functions. Mathcad has several built-in variables,
such as x (3.14159), e (2.71828), and g (9.807 m/s*), which can be directly
used once we open a worksheet. However, most of the time we will use
our own variables, which are called user-defined variables. A variable is
defined by assigning a quantity to a variable name, for example:
xis3
ys2x+1
z= 112.5
Note that by default any assignment in Mathcad is done by typing a co-
Jon (“:”), not an equal sign (when we type a colon, Mathcad will show a
colon and an equal sign). This assignment is sometimes called the “define
as equal to” operator. In fact, we can override the default operator dis-
play in the Worksheet Options in the Tools menu, but this is not rec-
ommended for beginners.
‘As we can see, a number, an expression of other previously de-
fined variables, or a range of values might be assigned to a variable. In
the next section, we will learn that a matrix/vector can also be assigned
toa variable and in the last chapter, we will learn that a component can
also be assigned to a variable. Thus, the type of a variable is directly de-
termined by the type of the value assigned.
An equal sign (“=”) is used when we want Mathcad to display the
value of a defined variable or evaluate an expression (or a function) and
display the result. From the example above, if we want to display the
value of variable y, then we type “y” and “=
y=7
The following examples show the use of equal sign for evaluating an ex-
pression and a defined variable:
3-y-1=20
Wisxt+ 5=8
‘The variable z in the example is defined as a range variable, which has a
range of values. In this assignment, the initial value is typed first, fol-
lowed by a comma (“,”) and the second value, then a semi-colon (“;”),8 Chapter 2 » Getting Started with Mathcad
and the last value. If the second value is omitted, the default interval is 1
(interval = the difference between the second and the first values).
Names in Mathcad can be a combination of alphanumeric, Greek
letters, prime symbol, subscript (literal subscript), and underscore, but it
should start with an alphabet or a Greek letter, which can be accessed
from the Greek Toolbar. Mathcad distinguishes uppercase and lowercase
letters, This name convention holds for any names including names for
functions, matrices, and vectors.
Variable names may also contain operator symbols, as shown
[eal
This can be done by pressing [Ctrl][Shift]] to insert a pair of brackets
Thus, the term on the left side is in fact the name of the variable, which
has been defined to have a value of 1.
below
Mathcad has a huge array of built-in functions readily available
once we open a worksheet. Click on the 43) icon on the Standard Tool-
bar to see all of the built-in functions. We can also define our own func
tions (user-defined functions), for example:
2.4
f0) = 3X + =~ 5 + sin(x)
x
(iy x
wn-(" 2 i
h(x, ) = x+ £09
-1 (34
P(M):=M + ( ; ;)
The variables in the bracket on the left side are called arguments. The
choice of argument(s) for a function in a certain problem could be the
Key to problem solving. The argument(s) can be of any type, ie, scalar,
vector, matrix, or function. In the example above, f and g have scalar
arguments; h has scalar and function arguments, while p has a matrix
argument, Similar to variable assignment, the type of a function is also
determined by the type of the assigned value resulted from the expres-
sion defining the function. Thus, fand hare scalar functions while g and
P are matrix functions. See the next section for information on vec-
tor/matrix,Chapter 2 = Getting Started with Mathcad
Mathcad always performs the calculations from left to right and
from top to bottom, which is intuitive. This means that before a user-
defined variable/function can be used for a certain mathematical opera-
tion, it should have been defined, i.e. given a value or an expression,
somewhere above or on the left side of the operation. There is an excep-
tion for this general rule of the calculation flow, as described in the later
section.
There are two other things that should be remembered when de-
fining a variable/function. First, if the user-defined name is the same as
one of the built-in names, then the user-defined variable/function will
override the built-in variable/function. Second, variable names and func-
tion names in a worksheet are not distinguishable. It means that if we
define a function y(x) and later we define a variable y, then we will not
be able to use y(x) anywhere below the definition of the variable y.
When we redefine a variable or a function, Mathcad will warn us by
flagging it with a green wavy underscore, It is always a good idea to
avoid this green wavy underscore by just changing the name of the vari-
able/function,
Arrays: Vector and Matrix
Mathcad can also handle arrays. Thus, variables can also be de-
fined as array variables, such as vectors and matrices. A vector is a matrix
with a single row or column. The initialization (assignment) of an array
can be done in three different ways:
(1) Using the Vector/Matrix icon from the Vector/Matrix Toolbar
The assignment is done by typing the name of the array and a colon,
and then followed by choosing Matrix from the Matrix Toolbar or
pressing [Ctrl-M]. Examples of this initialization are shown below:
140 2
fe) & 1 8 B=] 1
“102 5
If the number of elements of an array is more than 600, the assign-
ment must be done using other ways described below.
(2) Using a range variable as an array subscript (index variable)
This type of initialization is shown in the following examples:10 Chapter 2 = Getting Started with Mathcad
2 Bs 0.4 G psiti
2 2 o1234
B=|1| C=/12345
L 5 23456
Here, i and j are range variables. The index of B, shown as a sub-
script, is typed using the left square bracket (“[*) key followed by the
name of the range variable, which is “i” in this case. After typing a
colon, the values of elements of B, i.e., Bu, Bi, and Bz, are then en-
tered, From one element to the next, we type a comma (",”) and
Mathcad automatically creates an empty placeholder. In this exam-
ple, we define Bo = 2, Bi = 1, and Br =5
This initialization is handy when the elements of an array have a
certain pattern, such as those of matrix C above, and the number of
elements is large. The index of C is also typed using the left square
bracket key followed by the name of the first range variable, a com-
ma, and the name of the second range variable.
(3) Using data table
If we use data table, click Insert, Data, Table from the Menu Bar, and .
then type the name of the array. An example of this initialization is
shown below:
0 1 2
0 1 & 0
2 1 3
2 “i 0 2
Note that the default starting index in Mathcad is in fact 0, not 1
Thus, for example, the first element of A is
a)
To set the starting index of arrays to 1, click Tools, Worksheet Options
in the Menu Bar and change the Array Origin to 1, or by redefining the
built-in variable ORIGIN on the worksheet:
ORIGIN= |
where symbol “=” means that the redefinition is globally applied
throughout the worksheet (this symbol can be accessed in the EvaluationChapter 2 « Getting Started with Mathcad 1
Toolbar). This global assignment clearly overrides the rule of calculation
process (from left to right and from top to bottom).
Please be aware that if we use a range variable to initiate an array
and we still use the default starting index, the range variable must start
from 0, otherwise the initialization will be incorrect, as shown below:
0
2
7 1
5
which means we created a 4x1 vector (Bo will automatically be set to 0
when it is not defined)!
In general, an index of an array can be a variable, a number, or
an arithmetic expression. The following examples are legitimate indexed
variables (again the subscripts are created using the left square bracket
key):
By Ses Pr.3-1)
This index should not be confused with a literal subscript that is used as
a part of the variable name. A literal subscript can be typed using a pe-
tiod (“.”) key. The following are examples of variables with literal sub-
script:
Psat %
‘We cannot have an arithmetic expression for this subscript because liter-
al subscript is not a variable/number. Note that r2 here is a variable
name, not an element of an array r.
Many array operations can be done easily in Mathead, such as
array addition and subtraction, dot product, cross product, matrix mul-
tiplication, matrix inversion and transposition, and calculation of deter-
minant. For example:
3,2 51
As Be
14 02
0.09 ae
c=(aBy ! ( Det = |C| = 0.0112 Chapter 2 * Getting Started with Mathcad
-1
usvxwe| 13
9
‘There is a unique type of array operator, i.e., vectorize operator,
which is very handy for calculations involving a lot of data. This vector-
ize operator applies any arithmetic operator and/or function element-
wise (clement by element). To apply vectorize operator, we use an arrow
sign above the operation or function, which can be accessed from the
Matrix Toolbox. For example:
4 ———> (0.082
wis] 3 sale ou
2 0.139,
19
yi —
0) ex +3 few) =| 12
2
‘Although many functions and operators, when applied to vectors, auto-
matically perform operations on the elements of those vectors (arrays),
the use of vectorize operator is recommended to avoid unnecessary mis-
takes, An example below shows a potential problem:
16
(w-w) =| 9 wew=29
4
The second operation (without the vectorize operator) is in fact a dot
product of two vectors.
2.4 Working with Units: Built-in and User-defined
—_—— Ss
In Mathcad, although there are some restrictions, physical units
can be incorporated into most of calculations. Built-in and user-defined
units can be considered as built-in and user-defined variables. When we
want to incorporate a physical unit with a value, we just multiply the
value with the name of the unit, such as shown in the example of area
calculation below:
D=2.Sin
A==D
4Chapter 2 « Getting Started with Mathcad 13
If the unit isa built-in unit, the name of the unit can be typed directly or
inserted by clicking Insert, Unit from the Menu Bar. Knowing the exact
names of the built-in units we will be using is important to avoid unne-
cessary error. One example of common mistake: the name of unit ‘gram’
in Mathcad is incorrectly thought as ‘g’, but the correct one is in fact
‘gm’. If we forget about this, Mathcad will not warn us because ‘g’ is a
built-in variable (gravitational acceleration). Therefore, use Insert, Unit
from the Menu Bar if we are not sure about the unit names. If the unit is
a user-defined unit, the unit should have been previously defined in
term of built-in units and the name of the unit is also typed directly
when it is used. The following is an example how we define and use a
user-defined unit:
kbar := 1000bar P
kbar
Mathcad always stores values and displays all results in SI units
(the default unit system is SI system). Changing the default unit system is
possible but not recommended. For the example above, if we evaluate A,
we get
A=3.167x 103m? a
Note that an empty unit placeholder appeared on the right side (a small
black solid box). We can easily change any unit displayed to the desired
unit by typing the unit name in the empty unit placeholder. For exam-
ple, if area in ft? is desired, we type “ft” in the unit placeholder:
A= 0.0348
If another area unit is then desired, for example mm®, just replace “fe”
with “mm”. There is no unit placeholder anymore once the unit place-
holder has been filled.
Calculations that incorporate °C and °F as the temperature units
can also be performed. For example:
t= 25°C = 298.15K_ t=77°F t= 30°C
cal
op =
AH :=ep-(tl ay a2
gm A°C ° em
Note that there are two types of Celsius and Fahrenheit built-in units,
ie., temperature unit (°C or °F) and temperature difference unit (AeC or
ASE), which should be distinguished from each other. These temperature
units can be inserted by clicking Insert, Unit from the Menu Bar. The
temperature unit °C or °F is in fact a postfix operator/function, for which,
unlike the temperature difference units and other units, a multiplication14 Chapter 2 * Getting Started with Mathcad
operator (“dot”) must not be used. If we use absolute temperature units,
both temperature and temperature difference units are the same, i.e., K
orR.
Remember that units are treated like variables. Consequently, if
we define a variable named m, this will confuse ourselves with the unit
“meter”. Thus, if units are incorporated in our calculations, we need to
avoid using unit names as the names of our user-defined va-
riables/functions, particularly when the unit will be used. If this should
happen, i.e., if a unit name needs to be used as a user defined varia~
ble/function, we need to insert a namespace operator to differentiate the
unit name from the user-defined variable. For example:
m3 = 0.5- Meni
The namespace operator [unit] is created by pressing [Ctrl][Shift]N and
typing the word “unit”. The m in the definition of r above is the unit
“meter”, not the variable m, which has been defined to have a value of 3.
Since some Mathcad built-in functions do not support or fully
support units, as we will find in the subsequent chapters, the unit incor-
poration in the calculations is in fact recommended for advanced users.
For beginners, the units of all variables can be made consistent before
calculations, which can be easily done in Mathcad, and then the calcula~
tions could be performed without incorporating any units
2.5 Graphics Features: x-y Plot of Data and Functions
Mathcad has many graphic features, including 3-D plot, contour
plot, and animation. In this section, we discuss only x-y plot because it is
the most widely used graphic representation. We will learn other plots
in later chapters as needed. Data and functions can be plotted easily in
Mathcad after inputting the data or defining the functions. Data pairs
should be inputted in the forms of vectors of the same size. For example,
if we want to plot two quantities obtained from an experiment, where x
is the independent variable and y is the dependent variable, we need to
create vectors x and y first. A graph frame is created by clicking the
Graph Toolbar from the Math Toolbar and choosing x-y plot (scattered
plot). To let Mathcad know what we want to plot, we have to type the
variable/function names in the empty central placeholders of the abscissa
and ordinate (x- and y-axes). The other empty placeholders are for scale
adjustment. Mathcad will automatically plot the data once we hit [enter]Chapter 2 « Getting Started with Mathcad 15
or click any region outside the graph region. If we want to plot a second
experimental data z measured at the same set of independent variable x,
we need to create the vector z before the graph region (remember that
Mathcad processes any calculations from left to right and from top to
bottom). To incorporate this second dependent variable in the existing
graph, we click on the name of the first dependent variable on that
graph and type a comma (“,”) immediately after the last letter of the
name of the first dependent variable. Then we type “z” in the second
placeholder that just appeared. If the second set of data is measured at a
different set of independent variables, say xl, the vector x1 has to be
created first along with the vector z and remember that x1 and z must be
vectors of the same size. Besides inserting z at the y-axis on the graph,
we also insert x1 at the x-axis by typing a comma (“,”) immediately after
the last letter of the name of the first independent variable.
Below is an example of how to create x-y plot:
0 0
1 1 1 5
t=] 2 His] 4 x=] 2 y:=| 8
3 9 4 14
4 16
T
1s a
d00
lor 1
9% x S
Aaa
yf 6 I
2 1 L
0 1 2 3 4
OF course, the vectors can also be created using other methods as de-
scribed in Section 2.3.
Sometimes we need to format our graph to obtain a better pres-
entation. For example, we can change the symbols from circles to
squares or change the symbol plot to line plot. We can also type the plot
title, axis labels, and legends. To format a graph, double click the graph
and a new window for formatting pops up. The formatting features are
straightforward and the readers are encouraged to try by themselves. If16 Chapter 2 + Getting Started with Mathcad
we need to know the values of the independent and dependent variables
for a certain point in the graph, we can trace the plot by right clicking
on the graph and choose Trace from the pop-up menu.
For plotting functions, it is a good practice to define the func-
tions as described in section 2.2 before we create a graph frame, although
we can directly type the expressions in the empty placeholder of the y-
axis. To create the graph, again a graph frame is created by clicking the
Graph Toolbar from the Math Toolbar and choosing x-y plot (scattered
plot). For Quick Plot, we type the independent variable name on the x-
axis, the function name on the y-axis placeholder, and hit [enter] or click
any region outside the graph region. Mathcad plots the function at an
independent variable range of [-10,10] by default. To plot the function at
different independent variable range, the minimum and maximum val-
ues in the range must be typed in the empty placeholder of the x-axis. In
plotting a function, in fact, Mathcad calculates the function at points of
certain interval, which is, by default, a thousandth of the width of the
independent variable range. To plot the function at a different interval,
the independent variable must be defined as a range variable before the
graph region, Other functions can also be plotted on the same graph by
defining the functions before the graph region and inserting the function
names at the y-axis (a comma after the first function name is also used to
create an empty placeholder)
Recall that when we redefine a variable or a function, Mathcad
will warn us by flagging it with a green wavy underscore. However,
Mathcad will not warn us when we use a defined variable or built-in
variable/unit as the independent variable in a plot because we in fact do
not redefine that variable. The following example illustrates this poten-
tial problem:
AR) = 9-R?
0.971 T 0.971) T
A(R) 0.977 7 AR) a97F 4
= 000
0.9 t 0.965 i
‘i 555 0.556 0.557 0.555 0.556 0.557
R R
In this example, R is a built-in temperature unit (Rankine), which is
equal to (5/9)-K. Therefore Mathcad only plot one point, as shown in theChapter 2 « Getting Started with Mathcad 17
right graph, which cannot be seen if the plot format is line plot (left
graph). To plot the function A properly, we can use R1 instead of R for
the independent variable or redefine R as a range variable.
Before we proceed to the next section, it is important to know
how to control the units used in x-y plot when units are incorporated in
our calculations. It has been mentioned in the previous section that
Mathcad stores values and displays all results in SI units. This also applies
to the graphical features. Mathcad displays x-y plots with x and y values
in SI units. The following example illustrates the use of units in x-y plot:
AG) snr r= 2in,2.1in., 8in
0.1 —1—T 0.1
or 4 aw oP 4
Ao as
0.057 4 _™_0.05- a
er roa
05 0.1 O15 0.2 0.25 0.05 0.1 0.15 0.2 0.25
r r
m
In the example above, we want to plot A(z) in the r range of 2 to 8 in.
The independent variable r should be defined as a dimensional range
variable, i.e., a range variable that has a unit. When we define a dimen-
sional range variable, we must provide the second value to inform Math-
cad about the step. Although both graphs represent the same plot, the
right graph is the recommended plot because one will immediately un-
derstand that the units of r and A(r) are m and m®, respectively. The
units are entered as if they are divisors, for example, for the x-axis, we
type [][/l[m]. To display the plot in different units, replace the units in
the denominators with the desired units:18 Chapter 2 = Getting Started with Mathcad
2.6 Symbolic Math Capabilities
Mathcad has some symbolic math capabilities. This means that in
some cases, we can use Mathcad to analytically or symbolically solve
math calculations. For example, in engineering we frequently need to
perform differentiations, integrations, or matrix inversions analytically,
which can be done easily in Mathcad (of course, if analytical solution
does exist), This symbolic math could be done using a live symbolic
equal sign, ie., “>”, or a symbolic keyword and a live symbolic equal
sign. For example:
Evaluating a definite integral
b
xt]
dx > atan(b) — atan(a)
2
x +l
a
Evaluating the inverse of a matrix
3x+5 3x45
Bxt5 3x45
1 xt x
Bx+5 3x+5 3x45
Simplifying an expression
at.
x-2
simplify >
X 3x42
Collecting coefficients of a polynomial
~aib
2 2 a
P.(y — b)-v? = R-Tev" + ar(v —b) coeffs,v >
-RT-Pb
Poo)
Solving an equation symbolically
{RUT + 4BPRT-RT
(sy =1+B °| solve,p > DBRT
pa _RT+YRTGBPSRD
2BR-TChapter 2 « Getting Started with Mathcad 19
These symbolic keywords and equal sign are available in the
Symbolic Keyword Toolbar from the Math Toolbar. A symbolic keyword
is needed to perform a certain operation or give an additional con-
straint/condition. In the examples above, the symbolic keyword “simpli-
fy” is used to simplify an arithmetic expression, “coeffs” is used to collect
the coefficients of a polynomial in v, and “solve” is used to obtain the
expression for p from the given equation (note that to type an equation,
the equal sign is the bold equal sign, which can be obtained from the
Evaluation Toolbar or by pressing [Ctrl][=
All examples in this chapter clearly demonstrate the synergy of
power and elegance with which Mathcad performs its basic operations.
There is no intention to cover all features or functions of Mathcad here,
but rather to create an impression about what Mathcad can do and how
easily math operations and plotting can be done. Various other impor-
tant functions will be demonstrated in the following chapters and how
to-use them in solving chemical engineering problems is also presented.
Example set 2.1
1, Shell-and.-tube heat exchangers are widely used in industries to exchange oat between hot
‘and cold fuids, The effectveness-NTU methad is a caloulaion approach commoniy applied for
hheat exchanger design and performance analysis.
For 24 shel-and-tube heat exchanger:
(@) Calculate the effectiveness (:) for a heat capacity ratio (C,) of 0.8 when the number of
transfer units (NTU) is 2
(6) Create a plot of heat exchanger effectiveness &) as a function of tha numberof transfer
‘units (NTU) in the range of 0 = NTU = Stor heat capacity ratios (C,) of 0, 0.25, 0.5, 0.75,
and 1.0.
For a 2+ shelhand-tube heat exchanger, the effectiveness can be obtained from:
(et
here is the effectiveness for one shel ofthe heat exchanger given by
[ oe Pees)
a
{@) We need to define C, and NTU before we can calculate, and
8 Note that r here is just a iteral subscript, not an index.
NTU=-2Chapter 2 + Getting Started with Mathcad
‘Since ¢ is dependent on e,,calaulate c first then et
Not that 1 hoo also a iteral subse, not an index
fees es
ie
(b} To croate a plot, we need to oreate the function , which is dependent on another function
‘Of course, we can use this function to soWve part (a): e(0.8,2) = 068
os
£(0,N
H{025,NTUL) 9,
(05,NTU!)
HQIS.NTUI) 0,
2(099999,NTUL)
0g
qui
(On the plot, the name of the independent variable is changed to NTUI because NTU has
‘been defined to have a value of an part (a). II we used NTU on the plot, Mathcad wou
plot only one paint at NTU = 2 for each C,.
Note that for C, =, the numerator and denominator ofthe equation of « become 2670.
“Thats why om the plot we use C, = 0.99009 for an approximation. We can also take the
limit and assign the result to a diferent function:
afi refer VERTU
seq(NTU)= tim. {C,.NTU) > Boleseinfed
got ! xtu
Fis oan EN,
In Mathcad, the limit operator, which can be accessed in the Calculus Toolbar, ean only
be used with the symbolic equal sign.
“The function then can be used to plot or calculate the effectiveness for any NTU. For
‘exampie, for NTU = 2:
eqn(2) 0623 compared (0.999982) = 0.618Chapter 2+ Getting Started with Mathcad 21
2. lr at 80°C (T,) flows over a long, 25-mm diameter cyinder wth embedded electrical heater.
Ina series of tast, measurements were made ofthe power per unit length, required to
‘maintain the cyinder surlace temperature at 300°C (T,) or ciferentiroe-stream velociyV of
the air. From energy balance, this power per unit lena isin fact the convection heat rate por
Unit length. The results are as fliows:
Airvebcity, Yims) 1 | 2 | 4 | 8 | 2
Heat ate,g"(Wimy 310 | 438 | «25 880 | 1080
Determine the convection coeticient (h] foreach velocity and display your resuts graphically,
‘The convection heat rate per unit length is given by
‘A(T, Tha)
‘where Ais the circumferential area of the cylinder per unit length
Solution: We define all ofthe known variables and paramotors:
T= 300c = 25mm
310
438
ei=| 025 | The prime is typed by pressing [CtifF7)
80 | ™
2 1080,
‘The circumierential area af the cyinder per unit length needs to be calculated frst:
Ar nd=0079m
‘The convection coeticient is calculated from the gven equation:
16446)
23297
as.is7|— By using vectorize operator, al values of
= lsat hat cillerent velocities can be calculated
5] mk
‘ee atonce.
57.296,
h(x.)
ho)
2. Explain the difference between the following ORIGIN redefinitions:
ORIGIN=
ORIGIN= 122 Chapter 2 * Getting Started with Mathcad
3. Implicit multiplication, i.e., the omission of “.” (multiplication opera
tor), in mathematics is very common, e.g., 2x, 34 etc. In fact, in
Mathcad we are also not required to use this operator to type such ex-
pressions. However, this feature is not recommended. In other words,
use the multiplication operator in any multiplications to avoid unne-
cessary mistakes. Explain the difference between the following ex-
pressions:
hi=y(x+ 2)
hi=y(x+ 2)
4. Fibonacci sequence is a sequence of numbers in which each number
equals the sum of the two preceding numbers (of course, except the
first two numbers, which are both equal to 1):
1,135, 5.8. TS
Use Mathcad to enlist the first 30 numbers of this sequence. Hine
Create a range variable i from 3 to 30 and an array (indexed variable)
£, where fi and f are both set to 1. Then, create a recursive formula
for & representing the i-th element in the Fibonacci sequence. Math-
cad will automatically calculate the i-th element using the formula for
all values of i. Note that this calculation is similar to “do loop” con-
taining only one formula in FORTRAN or other computer languages.
5. A constant that is commonly used in chemical engineering is the gas
constant R. The value of R can be obtained from Mathcad. Click Help,
Reference Tables from the Menu Bar to open Mathcad Resources:
Reference Tables window. Click on Fundamental Constants under
Basic Science category and R can be found in Physico-Chemical Con-
stants group and copied to an active Mathcad worksheet. The value is
R= 8.314472
mole K
Using Mathcad, calculate R for the following units:
a. _atm-cm*/(mole-K)
b. bar-m’/(mole-K)
c. torr-m/(kmole-K). Hint. create a user-defined unit: kmole.
6. Second virial coefficient (B) is an important gas property. In fact, this
property is related to the molecular interaction between two mole-
cules. If we know the second virial coefficient of a gas, for a given
pressure (/) and temperature (7) we can estimate the molar density
(p) of that gas using the virial equation of state:Chapter 2 * Getting Started with Mathcad 23
4B
pRT
where R is the gas constant. Note that the second term on the right
side can be considered as a correction term, because for an ideal gas:
P{pRT= 1; an ideal gas is a gas that does not have any molecular inte-
ractions.
‘The second virial coefficient can be estimated from statistical thermo-
dynamics, for example for a square-well fluid, which is a model for
more realistic fluid, it is given by
B-l og
ana 2 on)
2
aN = the second virial coefficient of a hard-
sphere fluid
o= the diameter of the molecule
= the well depth of the molecular potential
A=a dimensionless parameter related to the well width
of the molecular potential
A= the Boltzmann constant
Ni = the Avogadro number
a. Plot the second virial coefficient of CO: as a function of tempera-
ture, say from 200 to 1200 K. The square-well parameters for CO?
are o= 3.917 A, A= 1.83, and ¢/k= 119.0 K.
b. Plot on the same graph the second virial coefficient of CHs as a
function of temperature. The square-well parameters for CHs are
= 3.40 A, A= 1.85, «/k= 88.8 K.
c. Calculate the molar density (in mol/cm!) of CO» at 7’= 680 K and
P= 40 bar using this virial equation of state.
d. To investigate the behavior of a real gas, plot vs. T (400 < T=
700 K) at P= 60 bar and pvs. P(0 < Ps 60 bar) at T= 400 K for
CO using this virial equation of state, On those graphs, also plot
the molar density of an ideal gas. By analyzing these graphs, at
what conditions would a real gas behave like an ideal gas? Do you
know why? Write your comments.
A first order reaction is carried out in a series of N equal-size mixed
flow reactors, The total conversion (X) achieved for this system is
given by24
Chapter 2 * Getting Started with Mathcad
=(l+kz)”
Xx
where &is the reaction constant (= 0,075 hr) and ris the mean resi-
dence time in a single mixed reactor.
a. Plot the total conversion of this reaction as a function of z (0 < z<
40 hrs) for N= 4.
b. Plot on the same graph the total conversion as a function of for
N=2,
¢. Calculate the total conversion if the number of equal-size mixed
reactors is 6 and the residence time of the fluid in a single reactor
is 5 hrs.
d. Suppose we allocate a total of 10 hrs for this reaction (}t, = 10
hrs, the summation is over all reactors) and a large conversion is
desired, would you suggest having a lot of small mixed reactors or
a few large mixed reactors? Explain your reasoning using some
calculations. Hint. a larger reactor has a larger fluid residence
time
8. In chemical industry, the cost of piping system (pipes and fittings) and
pumping are important costs that should be considered. ‘The annual
cost of a pipeline with a standard carbon steel pipe and a motor-
driven centrifugal pump is given by:
C=0.45L +0.245LD" +325VP +61.6P"* +102
where J is the length of the pipeline in ft, Dis the pipe diameter in
inch, and Pis the power of the pump in hp, which can be calculated
from:
, ia
P= 4av10* 2 a1.92%10° a
In the above equation, Q is the volumetric flow rate of the fluid in
ams
a. Plot the annual cost as a function of pipe diameter, say from 0.25
to 6 in, for 1000 ft pipeline with a fluid rate of 20 gpm.
b. What is the annual cost needed if a pipe with a diameter of 1 in is
used? Is there an optimum diameter for this pipeline? Explain
why it is expensive when a very small pipe diameter is used.Chapter 2 * Getting Started with Mathcad 25
9, In petroleum industries, it is common that the molecular weight of an
oil fraction is unknown and thus must be estimated by using a corre-
lation. A correlation that is widely used is developed by Riazi and
Daubert, which is also referred to as the API (American Petroleum
Institute) method. The correlation can be applied to hydrocarbons
with molecular weight ranging from 70-700, which is nearly equiva-
lent to boiling point range of 300-850 K, and the API gravity range of
14.4-93. This molecular weight (4 correlation is given as a function
of the average boiling point (73) and the specific gravity at 60°F (SG)
of the oil fraction of interest as follows:
M = 42.965 exp(2.097 x10“T, —7.78712SG +
2.08476 x 107 7, SG)T, 70" SG#988
where his in K and SGis related to the API gravity (AP):
_ 14s
API +1315
a. Estimate the molecular weight of an oil fraction that has an aver-
age boiling point of 344.7C and an API gravity of 50.
b. Plot on the same graph Mvs. 7 (400 < Ti< 600 K) with API grav-
ity = 20, 40, and 60.Chapter 3 * Nonlinear Equation 27
apter 3
mlinear Equation
Nontinear equations, both polynomial and non-polynomial, are
commonly encountered in chemical engineering applications. In solving
a nonlinear equation, it is well known that we may have more than one
root, For a polynomial equation of order n, there are exactly 12 roots that
satisfy the equation. IF complex roots do exist, they must appear in pairs,
ie., complex numbers and their conjugates. For a non-polynomial equa-
tion, it is uncertain whether we have only one toot or more. In many
cases, we are only interested in real roots and most of the time only one
real root has physical meaning, which is the solution of that particular
physical condition. However, obtaining two or more real roots that have
physical meaning is not uncommon, such as found in the phase equili-
brium calculations. In chemical engineering, complex roots are impor-
tant for process control analysis. Mathcad provides us with easy and
simple procedures to solve a nonlinear equation.
In this chapter, we also introduce a procedure, referred to as pa~
rametric procedure, which is very useful in solving many parametric
problems in chemical engineering, In a parametric problem, the un-
known to be calculated is dependent on some parameters, the values of
which will be varied. This parametric problem often occurs in what-if
analysis.
lynomial
Mathcad has two built-in functions that can be used to find roots
of a polynomial, i.e., polyroots and root, In fact, find function with a
Given block can also be used to find roots of polynomials or other nonli-
near equations, but it will be discussed in the next chapter. The proce-
dures of using polyroots and root functions are described in Procedures
3.1 and 3.2, respectively.
As can be concluded from Procedure 3.1, if the variable x of a
polynomial f(x) has a unit, each coefficient of the polynomial will have
different units. Thus, each element of the vector c should have different
unit, which is not allowed in Mathcad. Therefore, polyroots function
does not support units.28 Chapter 3 * Nonlinear Equation
Procedure 3.1 ; polyroots
“The potyraots function isthe best function for finding al roots without provicing any iil guesses.
For example, we want to find the roots ofa eubie polynomial
fh 22+ 3x- 50D S
In other words, we want to solve f(x) = 0
4 Collec al coetficients of the polynomial using the symbolic math for collecting coefficients and
assign them to an array variable (vector)
( 3
3
eM) coal § | ;
1
Remember that when we do this, the variable x must have never been defined (no value Nas
‘een assigned to x), olnernise f(x) is not considered as a polynomial, but a number,
a: ee pyott fd aloo ve musth tee 0 aac ool
os
sepa (0)=| 23-2480
(srs 2a)
313
=0284 5 489%, = 2373+ 2.4821
» x
i
Inthis case, we have one real root and two complex roots,
Parametric procedure for _polyroots
For example, we want to find the roots ofa cubic polynomial with ane parameter a:
flay) ent 3y-30.—D2 +3? Now he parameter a must be ineused 25
‘an argument in all functions and dependent
variables i the procedure that are
aos
- B dependent on the parameter.
fay = Hayy) eoetts,y > |
(a) = polyoots (otal)
Fora=2: Fora=16
asa (1082-2408!) The ooteforany a
2ana- 24821 yet | 1052 2anxi| can be calculated
(srs 2a ones) ae
‘As noted in Procedure 3.2, root function requires an initial guess
to find the root. In fact, the success of using this function depends on
how close the provided initial guess to the real root is. Ifthe initial guess
is not close enough to the desired root, the root function may give
another root or fail to converge. If the root function fails to converge, it
‘will be colored in red and an error message will be shown when one
dlicks on it, Plotting the function that is being solved is therefore very
important to obtain a good initial guess for a real root. Unlike polyroots
function, root function does support units.Chapter 3 + Nonlinear Equation 29
Procedure 32: root
‘oot function can oniy find one root ata time. Although root function can also find imaginary root:
by using complex number as intial guess, root function is mainly used to find the real rts of a
polynormial
For example, we want to find the rots ofa cubic polynomial:
Hoyen tS ex-3
Incther words, we want to solve f(x) = 0
1. Plot the function to get the idea about the number of real roots and the initial guess.
vvalues of x) that make fs) = 0.
T
' {~~ [7] Byanaiyaing thie plot, we know that
/ \/ there are thre real rots (oo
08 06
2. Detine an initial quess: .~1
3. Use the root function to find one of the roots that is close to the initial guess
2 = root a) ,3) = 0.646
4, Repeat stop 2 and 3 for other roots
Inilval ques:
y= root fls).9) ==
Initial guess: x. -s
35 = Foot 1).m) = 4.646
“The parametric procedure forroot function or any ether function is similar to that for polyroots
function, where the parameters should be included as arguments in all functions and
‘dependent variables that are dependent on the parameters. See Example 2 of Example set
‘31 inthis chapter as an example.
Example set 3.1
1, Caleulate the molar volume of carbon cioxide at 400 K and 50 bar using Peng-Robinson
equation of state:
Rr
wo
Veabv-b
Uunere Fis the gas constant, Tis the ansolute temperature, V is the molar volume, and a
and b are the parameters calculated trom:
waseire|. s os?
PASTE | (osr464e 1 seaie-a2om)|1-() |
ouvrzr90R Fe
where Teis the eitcal temperature, Pcis the critical pressure, and « isthe accenitic factor.
Data for carbon dioxide: Te = 304.2 K, Pe = 73.83 bar, m= 0.224
Solution:
‘As we can see irom the equation above, to calculate the molar volume V, we are dealing
with a polynomial. Since polyroot willbe used here, we cannot incorporate units in cur
Calculations and thus the unit of the gas constant from the Reference Table should be
‘made consistent fist30 Chapter 3 + Nonlinear Equation
Fromihe Maen Plone Table: = sate SE 4s
elma eines
Ritoses ream Pest
For 004: eer
Calculate parameters a and b
a. os?
a tess asnie ae vane [i-(2)"]
Pe Te
Te
= 0077T96R
e Pe
Collect the coefficients of the polynomial we want to solve
voy cabv-w)—erls aev—0) + avo
A=
-6.026418195e7) The symbolic Keyword "oat is used to
limit the number of significant figures in a
coats. 515
e=hY) "| 120880151525 | result. In this case, we limit the number
Moat,10°” | -31925.43086 | of significant figures to 10 for defining the
500 coelficents
Volume calculation using polyroats
‘V-=polyroots(e) =| 20.108- 40.1271
598.292
Volume:=V, = 598292 emémol
20,108 40. =|
2. A brick wall of 0.2 m thick (L) separates a hot combustion gas ofa furnace trom the ambient
‘ir and its surtouncings. Under steady-state condition, the temperature ofthe inner surface of
the brick wal (T,) is 628 15 K and of the ambient air (T,) is 293.15 K. Free convection heat
\ransfor tothe aris characterized by @ convection coeflicient (h) of 15 Wim? K. Thermal
‘conductivity ofthe brick wal (k) is 1.2 Wim.K andits suriace emissivity (<) of 07. The
temperature ofthe surrounding (T,) can also be assumed 293.15 K.
a. What isthe brick outer surface temperature (T,)?
Plot the brick outer surface temperature (T,) a8 a function ol the brickinner surface
temperature (T) asumming all of the other parameters constant (400 < 800K)
From energy balance:
Energy transfered tothe outer surface = Energy transtered trom the outer surlace
F774 -1,) +¢0(1,4-1,4)
‘where ¢= Boltzmann constant = 5.67 10-8 Wim®.K#
‘Solution,
8 1 @BISK =02m
300K,301K..600K
iia guess: +
Torwouern.n=seomw A)
3004000060Chapter 3 + Nonlinear Equation 31
». We can repeat the calculation in part (a) above several times for illerent and plot the
‘results manually. However, parametric procedure isthe best way to do this, ie., by making
7T, as a function of,
Include in the funaion (1,
amet) +€0( Ty! -1y') A
tolt)=wa((r1).1) Now ator aint vss,
of ) a p ) we use the value of T in part (a).
tics, hao apne on preter
rtd 1 Foret) T the conesponn vale of,
z