Вы находитесь на странице: 1из 8

19.02.

2013

CHE 204(03) Chemical Engineering Thermodynamics I
Mathcad Tutorial 1

Introduction

Mathcad is a symbolic and numerical computation software with a spreadsheet-like
interface. It is capable of basic and advanced function evaluations and simple
programming. This tutorial is intended as a short introduction to its capabilities. Follow
the exercises step-by-step. Text in comic sans corresponds to keys like space and return.

Tasks:

1. To start: Double-click the Mathcad 15 icon on your desktop screen. Spend a few
moments to look around the interface the palette toolbar, other toolbars and the menus.

2. Moving around: The little red plus indicates where your next entry will display on the
page once you start typing. By moving the mouse pointer and left-clicking you can move
this cursor anywhere you wish. You can also use the arrow keys or enter to move around.

3. Entering comment lines: To enter comments that are not evaluated by Mathcad, but
serve to inform users reading your worksheet, we use a text-region. To start, type a
double-quote (). You will see a rectangular text area. Type: Hello World! (or whatever
you would like to tell the world). Click on a blank area to finish. Alternatively, select
Insert Text Region from the menu bar to start.

4. Simple calculations: Hit enter 2-3 times to create some space and then type:
8^(1/3) [space] + 2*ln(2) + \cos(t) =
Answer: 3.386 + i
Tip: To enter the square-root, click its icon from the calculator palette (if not displayed,
activate it from the palette toolbar) or type backslash (\ ). The value of t is built-in; type
the symbol using the Greek palette. Note all angles should be radians!
5. Editing lines: Click to the right of the in the expression you typed in task 4 and tap
space twice on the keyboard. A small rectangle will frame the entire \cos(t) region

. Hit
backspace twice to delete it and you will see a little black square indicating that region is
now blank. Type 9 in that placeholder and hit enter to recalculate.
Answer: 12.386
Tips: Selecting the exact region you wish to edit or delete or continue from can be tricky.
Try inserting the cursor at different locations in the expression and tap the left or right
arrow, or the space bar several times to experiment with different ways of selecting
regions. Pressing the insert key on the keyboard will switch the cursor position from the
start of the region to its end and vice versa.

6. Moving regions around: Move the mouse pointer to the slight upper left of the text
you entered. Left-click and drag until you see both the text and the calculation framed by
dashed lines. When you hover over the expression you should now see the pointer change
to a little hand icon. Left-click and drag to carry the expressions to a new location.

7. Define variables: Type P:10^5. Press Tab twice (well need the space later) to move
to the right, then type R:8.314. Repeat with V:0.0224 and n:1. Definitions are displayed
with a colon followed by an equals sign, that is P:=1 etc.
Tip: You may note a green wiggly line under the R, V and T variables. This is no cause
for concern; I will explain what this means when discussing units.

8. Combine variables: Type T:P*V/(n*R). To display the result, hit tab and then type T=
Answer: 269.425
Tips: You can add an equals sign to evaluate T right after defining it, that is,
T:P*V/(n*R)=. It is important to note that Mathcad always evaluates left-to-right and top-
to-bottom. For instance if you carry P:=10^5 under the T = you will notice an error
message, because P will not be read before the evaluation line is reached.

9. Format results: Double click the 269.425 result of the previous exercise. From the
result format box, select the number of decimal places as 1. Right-click the same region,
click on Properties and then check the Highlight Region checkbox on the window that
pops up. When you close this window, the background of the result should now be
yellow.

10. Insert units: For each of the definitions P, V, R and n, insert the cursor at the right of
the last character. We will insert Pa for P, m
3
for V, J/(mol*K) for R and mol for n.
To insert the units, click the little beaker icon on one of the toolbars and pick a unit
from the pop-up box to insert. Alternatively, if you know what abbreviation Mathcad
uses for that unit, you can type * right after the numerical result and enter the unit
yourself.

Tip: Mathcad can combine different units provided they have the same dimension. E.g.:





!!! The third calculation cannot be done because the units are not consistent with each
other.
Tip: Some unit abbreviations you might be used to may not be the same in Mathcad,
because they are reserved for something else. For example, in Mathcad the abbreviation
for grams is gm not g, since the latter is reserved for the gravitational acceleration (type
g = to confirm this). On a related note, if you define a variable with a name that
corresponds to the abbreviation of a unit (e.g. T(esla), V(olt)) Matchcad will complain,
but this will not result in an error.
Tip: You can define your own units.

11. Define a range variable: Type j:1,1.5;5. This defines the range variable j = 1, 1.5, 2,
2.5, 3, 3.5, 4, 4.5, 5.

12. Define and evaluate a function: Type f(x):x^2[space]+3*sin(x) to define a
function. If you now type f(j)= it should evaluate the function at the points of the range
variable we defined above.
Answer: f(j) = 3.524, 5.242, , 22.123
13. Plot a graph: To plot a 2D (y vs x) graph, type @ or select Insert Graph X-Y
Plot or select the first icon in the graph palette. You will see an empty graph with
placeholders. Enter the values and variables as indicated in these empty placeholder. If
you leave the upper and lower limits blank, Mathcad will autoscale the axes, which may
or may not .

5ft 25in + 1.2m + 0.6yd 2.81m =
3hr 4min + 68s 1.097 10
4
s =
5ft 3s + = 3s
Answer:

ADDITIONAL TOPICS


Numerical and Analytical Integration (calculus palette)

Definite Integral










Indefinite Integral

While calculating the indefinite integrals, use Symbolic Evaluation instead of Equal
Sign. The symbolic evaluation sign () can be entered by clicking its icon in the
symbolic palette.














!!! If you want to evaluate the above integral at different r values, you can define an I(r)
function such as;







0
t
x sin x ( )
(
(
]
d 2 =
0

x exp x
2

( )
(
(
]
d 0.886 =
x sin x ( )
(
(
]
d cos x ( )
a
b
x x
3
(
(
]
d
b
4
4
a
4
4

0
2 t
u
0
r
r 1 4 r
2
+ r
(
(
]
d
(
(
]
d
t 4 r
2
1 +
( )
3
2
1

(
(
(

6

I r ( )
0
2 t
u
0
r
r 1 4 r
2
+ r
(
(
]
d
(
(
]
d
t 4 r
2
1 +
( )
3
2
1

(
(
(

6
:=
I 2 ( ) 36.177 =
Differentiation (calculus palette)





Summation and Multiplication (calculus palette)










Limit (calculus palette)




Some Symbolic Operations (symbolic palette)

To simplify a complex equation;




To analytically find the roots of an equation;




To combine a long equation into a single parenthesis;







To rewrite an equation with a different form:



x
x
cosh x ( )
d
d
1
cosh x ( )
x sinh x ( )
cosh x ( )
2

0
6
n
n
2
1 +
( )

=
98 =
1
3
n
2
n
[
=
64 =
x
x
2
2 +
3 x 6 +
lim

1
3
0.333 =
x 1 ( )
2
2 x
2
+ 4 x + 1 simplify x 3 x 2 + ( )
2 x
3
2 x 3 x
2
3 + factor 2 x 3 ( ) x 1 ( ) x 1 + ( )
sin x ( ) cos x ( ) combine sincos ,
sin 2 x ( )
2

ln x ( ) ln 2 ( ) + 3 ln
3
2
|

\
|
|
.
+ combine ln , ln
27 x
4
|

\
|
|
.

exp x ( ) rewrite sinhcosh , cosh x ( ) sinh x ( ) +
Finding and Correcting Errors

Mathcad does have rudimentary debugging capabilities but they are limited compared
to full-fledged scripting languages. When Mathcad catches an error, it will indicate the
offending region in red text, and display a descriptive bubble text when clicked on, e.g.:


Sometimes the error occurs at a previous step, but the error message is further
downstream, e.g.:

Here it is easy to see that the actual error occurs in the function evaluation to the left but
in complex spreadsheets the location of the error may not be so obvious. To troubleshoot
such errors, right click at the error site, select Trace error, and backtrack to find out the
initial point of the error.

Watch out for the worst kind of error Mathcad does not report any errors but the
answer is completely wrong! Can you figure out what happened below?


To avoid errors in the first place, here are a few precautions:
- Make sure all of the variables are defined as you intend them to. Mathcad has a
number of built-in units and constants. If you use a variable that corresponds to
the built-in name without assigning a value to it, Mathcad will substitute its own
built-in value.
- Dont forget that Mathcad operates left to right and top to bottom. If you place a
precursor calculation slightly below your final one you will get an error.
- If you use a built-in function of Mathcad, double-check the arguments from its
help file. Fewer arguments, incorrect argument type etc. will result in error.
- Many built-in functions like root depend on good initial guesses, i.e. you need to
have an educated guess on what the answer will be before you actually use the
function.
Exercise 1: Calculate the Nusselt Number with Re=8.46*10
4
and Pr=0.714.




















Exercise 2: User-defined functions






















Re 8.46 10
4
:=

Pr 0.714 :=
Nu 0.3
0.62 Re
1
2
Pr
1
3

1
0.4
Pr
|

\
|
|
.
2
3
+

(
(
(
(

1
4
1
Re
282000
|

\
|
|
.
5
8
+

(
(
(
(

4
5
+ :=
Nu 193.117 =
f x ( ) x
2
:=
f 2.5 ( ) 6.25 =
A x ( ) 3 x 2 + :=
B x ( ) x :=
C x ( )
A x ( )
B x ( )
:=
C 1 ( ) 5 = C 2 ( ) 5.657 =
Exercise 3a: The Maxwell distribution for N
2
at various temperatures.


0 500 1000 1500 2000
0
0.001
0.002
0.003
0.004
f co T1 , ( )
f co T2 , ( )
f co T3 , ( )
co


Exercise 3b: Note that the y axis does not correspond to the number of particles, unlike
what was written in class. Rather, f(c) is a probability distribution function that has values
between 0 and 1. Show that for any of the temperatures, the integral of the function f(c,T)
from 0 to infinity is unity.

This concludes the tutorial. The optional second part of this tutorial (available on metu-
online) introduces some advanced functionality such as vectors, solution of nonlinear
equations and curve-fitting. Youre encouraged to go through that by yourself.
T1 300 := T2 1000 := T3 100 :=
R 8.314 := Mw 28 :=

f c Tf , ( ) 4 t c
2

Mw
1000
2 t R Tf
|

\
|
|
|
.
3
2
exp
Mw
1000
c
2

2 R Tf
|

\
|
|
|
.
:=

Вам также может понравиться