An Introduction To Mathcad by Young Et Al 2000
An Introduction To Mathcad by Young Et Al 2000
An Introduction To Mathcad by Young Et Al 2000
by
Sidney Young
Department of Chemistry
University of South Alabama
Mobile AL 36688-0002
and
[email protected]
[email protected]
Copyright Sidney H. Young and Theresa Julia Zielinksi, 1996, 1997, 1998, 2000. All rights reserved. You are
welcome to use this document in your own classes but commercial use is not allowed without the permission of
the author.
This depends on the type of computer you have and what you have available. This document was
written and saved as a Mathcad 6.0+ document. You can open it with any higher version of Mathcad.
Higher versions may have some differences in how higher powered features are performed. For simple
applications encountered by students version 6.0 is adequate. However, if you have a choice you
should use the highest version you have available. Macintosh computer users only have Mathcad
6.0+ available for their use.
Note to users of this document. The methods and procedures of this document may be different in you
version of Mathcad. This may be an obstacle if you let it be one. However, instances of version
incompatibility should be few. Every effort has been made to keep the exercises here in a form that
crosses most levels of Mathcad. You may need to refer to your Mathcad manual for details for
performance of certain operations on your particular version of Mathcad.
notes.mcd
page 1
notes.mcd
page 2
3. Variables
Variables are easily defined in MATHCAD. If you wish to set x to 10 type x:10.
The colon acts as the PASCAL operator := , which is what you see on the screen.
This operation assigns the values 10 to the variable x.
Now enter y:= 2*x^2 +15.
This defines y in terms of x. Next evaluate y by typing y= ; the answer 215 should appear on the screen.
Each entry that you typed should lie below the previous one to form a column of expressions.
MATHCAD evaluates expressions from top to bottom and left to right on the screen.
Sequential entries of equations and data must follow the order for MATHCAD to give the result that you
desire. Syntactically incorrect entries will result in various types of MATHCAD error messages.
If you want a function y which changes as x is changed, one must use a function definition. The
following examples are functions, and you can see that as the variable changes the value of the function
changes. Try the following functions and evaluate them at different values of x.
y(x):=6+x
(What is z(1,1)?)
i:= 0...9
xxi := 2(i+1)
type
type
i:0;9
xx [ i := 2 * ( i + 1 )
Notice how the colon acts as the assignment operator, and the semicolon sets the end of the range, so that i
ranges from 0 to 9. If one wanted to have a range such as 0, 2, 4, 6, 8, 10, one would type i:=0,2;10 . Here the
initial value is 0; the 2 tells the program to change the values of i by increments of 2 by telling Mathcad the
next integer in the series ending at 10. Range values can also go in descending order by making the second
number smaller than the first as in I:=0, -2;-20. We can also use range variables for a noninteger series of
numbers.
notes.mcd
page 3
xx [ 10 :=20
The left bracket [ is used as a subscript operation key for range variables.
Type xx =
see that the range variable has been extended to include the new value of xx.
A.ini
the result Aini appears on the screen. This is an example of a literal subscript. These are part of the of the
variable name. On the other hand an array subscript represents a reference to an array element in a vector
or matrix. This distinction is important for work in quantum chemistry.
5. Graphics
MATHCAD has a strong graphics program, which plots range variables against each other or against
an index. Suppose we wish to graph x2 from -2 to +2 by increments of 0.04. This involves 101 points.
Set up the range variables for t going from -2 to +2 and define a range variable xsq in which each
element is equal to t2 .
Enter:
j shift: 0;100
t[j shift: - 2 + j / 25
xsq[j shift: t[j^2
note: enclose the t[j in a blue selection box before typing ^2
Now use the graphics pull-down Menu bar and choose XY plot. A square appears on the screen.
Click on the black dot at the middle of the vertical axis and enter xsq[j
Click on the dot at the middle of the horizontal axis and enter t[j
(Other dots are used for manually entering upper and lower limits for the ordinate and abscissa of the
graph). It is possible to graph two- and three-dimensional functions. Some of the sample exercises
obtained from the WWW show this feature. You will see more of these later.
notes.mcd
page 4
D:100
a: 6/r.e and
r:0.5,0.53;3.0
notes.mcd
page 5
82.05
23.7
4.2
a
4
3.41. 10
Next we write the van der Waals equation. Notice how we write the equation with P as a function of V.
R. T
P( V )
a
V
0 .. 100
Vi
35
Pi
P Vi
( 200
35 ) .
i
100
notes.mcd
page 6
Exercise: Prepare a graph for the variation of pressure as a function of volume with the
Redlich-Kwong equation of state for the same data range used in the van der Waals sample given
above. Practice changing the range of the calculation and the range shown in the plot for the x and
y axis. What units of volume do you have here?
Note to students: By now you have the rudimentary skills to do many homework problems in
physical chemistry. Most of these require a function and values for the variables. You can also
prepare graphs of data and annotate a worksheet like this one using Mathcad's text feature.
This means that you can write lab reports using this software.
8. Units: Units are easy to use in Mathcad. You will need to look in the Mathcad manual to see the
correct spelling of the many units you will use in physical chemistry. It is important to note that the
mole unit is not supported in Mathcad 6.0+ so all calculations should be done for one mole and then
adjusted later to account for the number of moles you need for the answer to a problem. Higher
versions of Mathcad support the mole. To see the correct spelling of the unit names you can pull down
the menu for units and select insert units (check your manual for the location of the Units menu). This
opens a window in which the current system of units is identified and a scroll of types of units
available. Find the energy entry. In the square brackets you will see that Joules are written as joule
when included as a unit in a calculation. More information about units is given in the Mathcad manual
in Chapter 8 or use the Help menu. Here we review only a few of the basics.
mass
acc
25. kg
m
9.81.
2
sec
mass. acc
F = 245.25 kg m sec
time
5 . sec
momentum
F
time
mass
acc
incompatible units
Exercise: Calculate the pressure when 200 grams of CO2 are confined to a volume of 2 liters at 400 oC.
Include all required units. repeat the exercise using the van der Waals equation.
Created: Jan. 20, 1996
Updated: August 15, 2000
notes.mcd
page 7
9. Integrals: Numerical integrals are easily performed using MATHCAD. To evaluate an integral
open the calculus palette and choose the definite integral symbol. Clicking this produces an integral
sign with place holders for the upper and lower limits, the function and variable. Fill in this so that you
evaluate the integral of exp(-x2) from 0 to 2. When you enter this expression be sure to remember that
exp means e . Notice how the power in a power is handled by MATHCAD.
2
e
dx = 0.882
Exercise: Evaluate the work that an ideal gas would do if it expanded reversibly and isothermally
from 1.0 liters to 5.0 liters at 27 oC. Check your text for the requisite integral to evaluate.
More extensive exercises with integrals will wait for a future tutorial worksheet. Many of
the Mathcad documents on the Mathcad web page give examples of integrals and
differentials that you can add to your collection of examples of techniques.
10. Iterations: Sometimes we want to do a whole of set of steps in a single calculation. In this
case you must create a vector in order to get a sequential set of iteration steps. You already
examined examples of using an index in previous sections of this set of notes. Here we extend
that idea.
F0
F1
0 .. 10
Fi
Fi
Fi
notes.mcd
page 8
11. Solving equations. In physical chemistry we are often asked to solve equations by finding
the roots that satisfy the equation. Here we see some simple examples of solving equations.
Mathcad will even let you solve differential equations but that is a story for later.
When solving an equation with Mathcad we must help the software get started. We do this by
providing an initial guess for the root in which we are interested.
f( x )
4.x
notes.mcd
page 9
3.5
0.5
ans
ans
root( f( x ) , x )
root( f( x ) , x )
4. x
3 0
Now we will use symbolic menu to find the roots in a more
direct way. Place the blue cursor next to the x and highlight
the x with a blue selection box r editing lines. From the
Symbolic dropdown menu choose solve for variable. The
answer should immediately appear.
3
1
x
x. e
g( x )
x
.5
ans
root( g( x ) , x )
ans = 0.567
x
0 x. e
1
Here we try the symbolic approach. High light the x with a
blue selection box and choose solve for variable. You should
observe what is shown here to the left.
W( 1 ) =
.5
gg( x)
ans
root( gg( x ) , x )
We define a new function and ask for the root. Don't forget to
give a new initial guess or else Mathcad will use what ever was
left over from calculations done above.
ans = 1.587
Vary the initial value for x to see what latitude you have in your
initial guess in this case. Try small, large, negative and decimal
values.
notes.mcd
page 10
12. An Equation with two variables. Using a solve block to find the values of x and y that
satisfy a set of equations in x nd y. A solve block is a group of commands and equations in
which the instructions for solving a system of equations is contained. Within the solve block
you provide the initial guess for the solution, the the word given, the constraints (equalities
and inequalities etc. the function to be operated upon, and the method of operation to be
applied to the function. The procedure is outlined here below for the system of simultaneous
equations shown below.
Given
xval
yval
xval
yval
10
Find( x , y )
y 1
2.679
1.679
Given
2
xval
yval
10
Find( x , y )
y 5
Another example. In this case I chose a different
second equation. Here we see that you get notice,
either a message or red version of the expression, if
the software can't solve the equations. I wonder why
this happens. What do you think?
notes.mcd
page 11
x. e
2
x
This yields:
2
2
2 . x . exp x
exp x
2
x
This time highlight the variable and then choose integrate on variable from
the Symbolic menu.
1.
exp x
2
Substitution
2
x. e
2
x
1 . exp
notes.mcd
page 12
14. Some preliminary remarks on matrices. Matrices are powerful mathematical tools. One primary use is to solve a set
simultaneous equations. You may learn more about this later in your physical chemistry course.
1 2 4 1
AA
2 0 1 0
BB
1 0 1 1
4
2
1
2 1 0 2
Matrices are created using the Matrices symbol from the math
palette or by choosing Matrices from the Math menu.
1.643
xx
1
AA . BB
xx =
1.571
0.714
0.357
Acknowledgment: TJZ acknowledges the National Science Foundation for support of the
1997 NSF-UFE Workshop on "Numerical Methods in the Undergraduate Chemistry Curriculum Using
the Mathcad Software" and the organizers (Jeff Madura, Andrzej Wierzbicki and Sidney Young,
University of South Alabama).
notes.mcd
page 13