Introduction to Mathcad, written by Prof. Dubson

advertisement
1
Mathcad 5.0 Primer by M. Dubson, 7/6/98.
This is a Mathcad document. To get to Mathcad, turn on the computer, wait for the Windows
screen to appear, and double-click on the Mathcad icon with the mouse. With Mathcad, you can
make a document that combines calculations, graphs, and text. Equations appear on the screen
exactly as you would write them by hand.
A
3
If you type "A : 3", you get the equation to the left, which defines the symbol A to
mean the number 3. The "colon-equals" sign , which you get by typing " : "
means "is defined as". Anywhere below or to the right of this equation, Mathcad
understands that wherever it sees the symbol A, it means 3. A is called a scalar
variable; it has one value.
B
4
We have now defined B to mean 4.
A
B  7.000
I just typed "A + B = " and hit either F9 or the "equals" icon on the top tool bar.
The equals sign (=) in an equation means "evaluate this expression". F9 or
the equals icon means "update this Mathcad document by performing all
calculations called for".
Mathcad documents are made up of regions. There are three kinds: equation regions, text
regions, and graph regions. So far, in this document, I have typed 3 equation regions and several
text regions. To open a text region, place the cursor in any blank area and type ( " ) or click on
the "A" icon in the menu bar. To open a equation region, place the cursor in any blank area and
just begin typing. When done, click anywhere away from where you were typing.
z B z
2
f( z)
A 100
I just defined a new function f(z). Type "*" for multiplication, "/"
for division. z in this equation is a dummy variable. I could
have written f(x) = x + ... Editing equations involves some use of
the up and down arrows. But it's hard to describe; you just
have to see how in class.
z 1
Let's graph this function. First I have to define a range of z or x values..
x
0  0.5  10
The format here is: first value, second value .. last value. This is called a
range variable. Type semicolon ( ; ) to make the ( .. ) symbol. Mathcad
now interprets the symbol z to mean the 21 values 0, 0.5,...10.
To make this graph, I clicked on the
graph icon (on the left side toolbar). An
empty graph appeared with blank boxes
on the x- and y-axes for me to fill in.
400
f( x)
200
0
0
02/18/16
5
x
10
I typed "x" on the x-axis and "f(x)" on
the y-axis and hit F9 or the "equals"
icon on the top tool bar. If I don't enter
max-min values of x, Mathcad plots the
full range of defined x-values and scales
the axes appropriately.
2
If I wanted to change various features of the graph, I would first "select" it by clicking anywhere
on it. A blue box appears around a "selected" region. Then I would click on the XY PLOT menu
above, which opens a window with various menu items which allow me to change the symbol
type, linear, log, etc. I could change the displayed range by editing max-min boxes which appear
when I select the graph.
If I wanted to change the size of this graph on the page, I would click just outside the graph and
drag the mouse over the graph, which causes a dotted line (not a blue line) to surround the
graph. I then would drag the edges of the dotted box with the mouse to re-scale. (You have to
do this yourself to appreciate how simple and cool it is.)
Remember: Blue box around a region to edit; click on a region to get the blue box. Dotted box
around a region to move or resize. To get the dotted box, start away from the region, then click
and drag over the region .
N
We are going to plot 5 data points.
5
i
1  2  N
xi
yi
2
4
6
8
10
4.2
8.1
11.9
16.3
19.5
x and y here are array variables. The index ( i ) on an array variable MUST
start at 1 and increase in increments of 1. I entered a table of x values by
typing " x [ i : 2 , 4 , 6 , 8 , 10 ". The ( [ ) keystroke means "index". Table
values are separated by comma's when entering. Mathcad now knows that
the symbol "x" means all the values of the x-array from x1 to x5. If you type
"x=", you will get all 5 values listed. Try typing " y ] 3 = ", then update (F9)
to see what happens.
To make this graph, I clicked on the graph
icon, typed " y [ i " in the y-axis box, typed " x
[ i " in the x-axis box, and hit F9 or the
"equals" icon.
20
y
i
10
In a graph, the indices must match. You can't
plot yi vs. xk.
0
2
4
6
x
i
8
10
It's about time I saved this document to disk so I don't lose it in the event of a power failure. Click
on the FILE menu, then select SAVE AS... , select drive a:, and enter a filename.
Use FILE, SAVE AS... the first time you save something (since you have to give it a filename).
Later on, just use FILE, SAVE to update your saved document. SAVE frequently or risk losing
your work. A filename consists of 8 (or less) alphanumeric characters, a dot, and a three
letter/number extension. Mathcad files always have the extension .mcd. The first character of
the filename must be a letter, not a number. For instance, a file might be named Lab1.mcd.
02/18/16
3
More examples.
N
10
j
1  2  N
xj
5.1
4.8
5.0
5.7
4.0
4.5
4.5
4.6
6.2
5.5
N
xj
x_avg
j=1
x_avg  4.990
N
Note that the first eqn above defines the variable x_avg, the second eqn
evaluates it.
N

xj
x_avg
N
1
2
j=1
  0.657
To make the Greek letter , I clicked on the icon bar to the left. There are 5 icon bars to the left,
which you scroll through by clicking on the number above the bar. Greeks are in bars 4 and 5.
Or, you can type the corresponding English letter, followed by [Ctrl]G.
Other useful things:
The EDIT menu and the tool bar have CUT, COPY, and PASTE commands. These are
extremely useful for making a graph or equation which is similar to one you have already entered.
Just make of copy of the old equation and then edit it, rather than type it all in again.
The tool bar has icons for aligning regions either horizontally or vertically - very useful for making
your document tidy.
SHIFT-F1 turns the mouse pointer into a big question-mark. Clicking on any icon or command
with the question-mark brings up a help window, explaining that feature. Hit ESC to turn off the
question mark.
The EDIT menu has commands for separating over-lapping regions, inserting or deleting blanking
lines (to make or remove room in your document).
MATH, NUMERICAL FORMAT... allows you to change the displayed precision. The internal
precision is always 15 places. Select the number you want to change (click on it), then go MATH,
NUMERICAL FORMAT...
This is necessary when you want to change the number of
significant figures.
Ctrl-R redraws the screen if something looks goofy
Insert headers and footers with EDIT, HEADERS/FOOTERS..
02/18/16
4
Mathcad has scads of built-in functions: sin, cos, exp, ln, log... Click on MATH, BUILT-IN
FUNCTIONS... to get a scrolling list from which you can select. If you know the name of the
function, just type it in.
g( x)
1
x sin
x
0  0.001  0.3
x
You'd think this would cause a divide-by-zero error. But Mathcad knows that x sin(1/x) is wellbehaved in the limit x goes to zero. (!).
0.1
1
xsin
x
0
0.1
0.2
0.3
0
0.05
0.1
0.15
0.2
0.25
0.3
x
When graphing a function, set the increment of the range variable carefully. Increment too large
and the graph will look jagged. Increment too small and Mathcad will take too long to compute all
those points.
Notice how I entered the function on the y-axis of the graph; I could have used g(x), but instead I
typed out the function. Either way is OK.
The following is actual data of period vs. amplitude for a simple pendulum.
i
1  2  10
angle(degrees)
period(sec)
ai
Ti
4
12
24
38
45
61
66
75
29
50
2.156
2.162
2.179
2.211
2.238
2.314
2.338
2.396
2.189
2.256
02/18/16
2.4
2.3
T
i
2.2
2.1
0
20
40
a
i
60
80
5

i
ai
L
1.152
Length of pendulum in meters.
g
9.797
acceleration of gravity in m/sec2.
Convert the angle from degrees to radians.
180
[The tool bar has icons for making supers and subs in text regions.]
T_theory( x)

L
2   1
g
0  0.02  1.56
2
x
16
11  4
x
3072
First three terms in the power series solution of
the (non-linear) simple pendulum.
A range variable for a range of angles in radians.
Simple Pendulum: Theory and Experiment
2.6
period (sec)
2.5
T
i
2.4
T_theory ( )
2.3
2.2
2.1
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
 i 
angle (rad)
You can make several plots (several traces) on the same graph - just separate the variables on
the x and y axis by comma's.
You can get axes labels, a title, and more by selecting the graph and going to the X-Y PLOT
menu. The X-Y PLOT menu item only appears on the top menu bar when you select a graph.
02/18/16
6
Mathcad is great for repetitive calculations. Use array variables in equations to do the calculation
for every value of the index.
a
2.5 m/s2
i
1  2  5
Acceleration.
5 measurements.
time(sec)
ti
xi
1.02
1.24
1.67
1.97
2.20
vi
1  2
a ti
Distance traveled at time ti.
2
a  ti
Speed at time ti.
distance (m) speed (m/s)
xi
vi
1.301
1.922
3.486
4.851
6.050
2.550
3.100
4.175
4.925
5.500
To get the x-column,type "x [ i =" and then update (F9).
Likewise for the y-column.
To place headers and footers on your printout, go to EDIT, HEADERS/FOOTERS. The header
should be: filename on the left, your name and sec. number in the center, and page number on
the right. The footer should be date and time on the left.
When you are all done and want to print out your document, first check the appearance of the
final print-out with FILE, PRINT PREVIEW... Then take your diskette to one of the printer stations
and FILE, PRINT...
Please close your document with FILE, CLOSE before removing your diskette from the computer
If you turn off the computer first exit Mathcad, then exit Windows. When you see the DOS
prompt, C:\>, you can turn off the computer.
02/18/16
7
REVIEW:
Mathcad reads from top to bottom, left to right.
A range variable has the format: first value, second value .. last value.
i
An array variable has an index that starts one, two,..
q
1  0.9  6
1  2  5
A function definition has the format: function name(dummy variable) is
defined as...
F ( r)
2
r
6
Use commas to separate items in a list, as when entering values of an array variable or listing xor y-variable on a graph.
zi
50
2.2
3.3
4.6
5.3
6.3
40
z
i
2
30
F( q )
q
2
20
2
10
0
2
0
2
4
z qq
i
2.200
3.300
z
4.600
5.300
6.300
02/18/16
6
8
1
Avoid using the same variable name for different things. The symbol z means
this array of 5 values, entered above when z was defined. Don't use z as a
variable name again, or risk confusion.
Download