Introduction to Mathcad
The basic operations of Mathcad are very easy to learn, and the result on the screen looks pretty much like normal mathematics as you would type it. The catch is that what you see on the screen is not always what you type to acheive that result. Nonetheless, what you need to know is quickly learned, and this is our first objective.
First, take a look around the screeen. At the top, you will see a series of menus (File, Edit, Menu, etc.) - click on each to see what commands appear. You will also see a series of eight buttons - these toolbars are used to perform mathematical operations and to make plots, etc. Included are the Calculator, Graphing, Vector and Matrix, Evaluation, Calculus, Boolean, Greek Symbols, and Symbolic Keyword toolbars. If you move the mouse cursor over one of them, a description will appear. To open a toolbar, left-click on it; to close the toolbar, left-click on the small 'x' in the upper right hand corner of the open toolbar.
Getting Started
When you start Mathcad, you are presented with a blank document (or worksheet) on which to do your calculations. You may create other documents by pulling down the File menu and selecting New. To open an existing worksheet, pull down the File menu, and select Open. In the Open dialog box, select the disk drive where your document is. You may have several documents open at the same time, but these do not share information. After you have done a small amount of work on your document, save it by pulling down the File menu and selecting Save. If you are saving for the first time, give your document a file name which is no more than 8 characters long - the file name may not contain spaces, commas, periods or special characters (like &,$, #, etc.) If you want to save your worksheet to a diskette, you must change drives when the Save dialog box pops up. In the SOU student lab, the 3.5" diskette drives are the a: drives. If you are working on a lengthy worksheet, it is strongly recommended that you save the document every couple of minutes as a hedge against power failures and other assorted catastrophes. Once you have named and saved your worksheet, you can save your work quickly by clicking on the icon in the toolbar which looks like a diskette.
Text and math modes
A. Text mode
Mathcad has two modes: text and math. To place text in a worksheet, locate the mouse cursor where you want the text to appear, and left-click the mouse. Now, type a double quote ("). Note that a text box appears; text may be typed in the box. To leave the text mode, move the mouse cursor away from the text box and and left-click; the cursor turns back into a red crosshair. Note that text in Mathcad is blue, while mathematical commands are in black.
In the region below this text, left-click and type a double-quote to create a text box. In the text box, type your name and the date.
Text may be moved around in a worksheet in the following way. Move the mouse cursor near where you typed your name. Click and hold the left mouse button and drag the mouse cursor towards your name; the text will be surrounded by a dotted box. Release the left mouse button. Move the mouse cursor along the right edge of the dotted box; the cursor turns into a small hand. When the cursor appears as a hand, click the left mouse button, hold it down, and drag the text block to its new location. Also, you can position the mouse cursor over the text and right-click the mouse to activate the cut-copy-paste, etc. menu. You can superscript/subscript text in this way.
Drag the text box with your name and the date so it appears below this line of text.
text
B. Math mode: making calculations and plots with Mathcad
In this tutorial, what you are to type into the worksheet will be shown in quotes; do not type the quotes (unless explicitly told to do so). Examples of calculations will be shown on the left side of the screen as a guide; type in your response to the right, and be sure that you get the same result. Move below this text, left-click the mouse in the workspace, and type "22.3+4.5/14.5=". (Do not go into text mode; just left click and type).
You should have obtained a result of 22.61 (if, after typing the expression no result was obtained, pull down the Math menu and make certain that there is a check mark next to "automatic mode").
Next, put the cursor below this text and left click. Type "22.3+4.5(spacebar)/14.5=" (use the up-arrow cursor control key where required):
Here, you should have gotten a result of 1.848. When you press the spacebar, you surround portions of the expression with a selection box; this determines the level of the expression to which the next operation applies (divide, in this case). The number of times to press the spacebar depends on the situation; you will be able to tell by observing the screen when you have the correct level.
Numbers can be assigned to symbols that represent names of constants or mathematical variables. Place the cursor in the workspace below and type "a:1.234"
Note that you typed a colon, but ":=" was the result. You have assigned a value of 1.234 to the variable a. We say that a is defined as 1.234. To see this, go below this text block and type "a="
We can perform all manner of mathematical manipulation on the variable a; for example, place the cursor in the workspace below and define a new variable b as 2 times a (type "b:2*a). (The multiplication operator in Mathcad is the asterisk, shift 8). Then print the value of b (type "b="):
Editing Mathcad statements is fairly simple; for example, to change 2 to 2.5 in the statement above, click just to the right of the 2 and type ".5"; note that the changes in subsequent statements are taken care of automatically.
As you probably noticed, Mathcad statements can be entered at any place in the document. However, location is important because Mathcad executes statements from top to bottom and left to right. Thus, all variables must be defined before they can be used. For instance, in the space below, define d as 2 times c (type "d:c*2); move the mouse cursor away from the statement and click. Notice that the variable c, which is undefined, appears in reverse video:
Now, place the mouse cursor above or to the left of this statement, and define c as 3 (type "c:3"); what happens? Screen print the variable d (type "d="). Notice that math mode statements can be moved in the same way as text (click the left mouse button near the statement and drag towards the statement to surround it with a dashed box, then click and drag).
Mathcad knows most of the usual functions such as log (base 10 logarithm), ln (base e logarithm), sin, cos, and so forth. The arguments to these functions are enclosed in parenthesis:
To display these results (or any results) to more digits, double-click on the number you wish to change (e.g., double-click the left mouse button on the 4.605). The Result Format dialog box pops up, and you can change the number of displayed digits if you wish.
To raise numbers to a power, use the caret (^), shift 6. For example, type "2.456^4.333="):
You should obtain a result of 49.075.
On-line help in Mathcad
You have probably noticed that there is a Help menu at the top of the screen and a Question button in the toolbar above; either can be used to access on-line help. Less obvious is the following: if you press shift F1 (hold down the shift key and hit F1), the cursor turns into a question mark; by clicking with this cursor on any button or command on the screen, you can get help. Press the escape key (Esc) to return to the normal cursor.
Examples
In this section, a number of sample calculations are presented, primarily as vehicles to help you use Mathcad.
Example 1. Unit Conversion
Mathcad is very good at handling units and dimensions. Pull down the Math menu above, and select Options. Select Unit System and make sure that the SI system is selected.
In the space below, type "gal="; you should see a result in m3. To get other units, click in the space just after the unit; a unit placeholder appears as a solid black square. Click on the placeholder (it becomes a black square surrounded by blue) and type in the unit you want (alternatively, type ctrl u to see a selection of the available units for volume).
Change the units from m3 to liters (type "liter" at the placekeeper and press ENTER); you should find that gal=3.785 liter. Note that for volume you can select the cube of any length. Click at the end of the "r" in liter in the statement above, backspace, and type "in^3"; you should find that gal=231 in3.
Example 2. Ideal Gas Law
The ideal gas law is PV = nRT. Here, we show a calculation in which we define a number of constants and solve the ideal gas law using units.
Here we want to solve for V given P, n, R, and T. Mathcad can do this for you, but it is not worth the trouble for a simple calculation such as this.
In the space below, define R as 0.082057 L atm / mole K. Type "R:0.082057*liter*atm(spacebar)/mole*K"
Mathcad knows about the most common units; the only problem is in guessing which are abbreviated and which are spelled out. Note that the joule and the mole are spelled out but kelvin (K) is abbreviated. You can always type ctrl u and look at the list of legal units.
To calculate the volume we must define the number of moles (n), the pressure (P), and the kelvin temperature. You can use any units which Mathcad supports, but looking at the units of R, we want P in atm and T in K to get units of liters. In the space below, define P as 1 atm ("P:1*atm"), T as 273.15 K ("T:273.15*K), and n as 1 mole ("n:1*mole"). Notice that variables in Mathcad are case-sensitive - pressure defined as P IS NOT the same thing as pressure defined as p.
now we solve the ideal gas law for V: type "V:n*R*T(spacebar)/P
now screen print the volume (type "V=")
Change the units from m3 to liters (click on the placekeeper to the right of m3 and type "liter" at the placekeeper and hit ENTER); you should get V=22.414 liter.
Example 3. Square roots and the arithmetic palette
Click the calculator toolbar to open it. Among other stuff, there is a button for a square root. Click in the space below, and then click the square root button. Note the placeholder under the radical; type a 5 in this placekeeper, then type "=" to see the result (you should get 2.236):
now define a variable a as 3 (type "a:3" below):
suppose we want the square root of the quantity (5-a): how do we get this? Below, click the mouse and then press the square root button on the calculator toolbar; type "5-a" at the placekeeper, and then hit an equal sign (you should get 1.414)
what if we want the subtaction after the radical? Click below, get the radical from the arithmetic palette, and type "5(spacebar) - a ="; see the difference?
Example 4. Functions and graphs
Mathcad allows you to define your own functions by placing the arguments of the functions in parenthesis following a variable name. For example, let us construct a simple quadratic function. In the space below, type "f(x):2.5*x^2(spacebar)+1.3*x-0.5"
We can evaluate this function for any value of x by typing the variable name (in this case, f) and giving a numerical value of x as an argument. In the space below, type "f(0.550)="
you should get a value of 0.971. In the original function definition, Mathcad put in your given value of x (0.550) and evaluated the function.
It is very easy to make plots with Mathcad. We will use the function defined above, f(x) as an example. Before making a plot, however, we will need to specify a range of x values over which the function f(x) will be evaluated. To do this, we will make the variable x a range variable: that is, we will specify the starting and ending values of x, and the amount by which we will increment x. In the space below, type "x:0,0.01;10" (that is, x(colon)0(comma)0.01(semicolon)10 )
to see what you've done, go below this text and screen print x ("x="). To delete this mess, left-click near the x values, click and drag until the x values are surrounded by a dotted box, and hit the backspace key. (Be sure you just delete the x-values; if you delete some text also, pull down the edit menu and select "Undo Last Edit", then try again.
You have defined x as a range variable; that is, x starts (in this case) at 0, and is incremented by 0.01 all the way to 10. In a Mathcad range statement, the second number is not directly the increment; rather, the increment is the difference between the first and second numbers in the statement. For example, the range "x:1.05,1.06;10" gives a range from 1.05 to 10 with increment 0.01.
Now, click below this text block and open the graphing palette (scroll down and leave yourself a little room). From the graphing palette, select X-Y plot; an empty plot with 6 placeholders appears in the workspace where you originally clicked.
Of these six placeholders, the middle ones on each axis are of immediate interest. Click on the placeholder in the middle of the x-axis and type "x". Click on the placeholder in the middle of the y-axis and type "f(x)". Click anywhere outside the plot to display the data.
To move or size the graphic, drag the mouse cursor in from outside the plot until the dotted frame appears. You can resize by clicking and dragging on the the lower right corner of the box, or move it by clicking on the right side of the box, getting the 'hand' cursor, and dragging.
When you click the mouse inside a graphic that is not surrounded by a dotted line, a solid frame appears. Additional numbers appear at the corners of the axes, showing the actual limits of the numbers being plotted. You can adjust the axis limits in this way. If you double-click on the plot, the Plot format dialog box appears; from here, you can add axis labels and a title, and change plot colors and characteristics. Note that Mathcad refers to lines on a plot as traces in this dialog box. Go up to the plot, double-click, bring up the Plot format dialog, and play around a bit.
To plot multiple lines on the same plot, do the following: left-click just to the right of the variable on the y-axis, hit the spacebar, and hit a comma. A new placekeeper will appear, and you can type the name of the new variable in. On the plot above, click on f(x); hit the up arrow twice, and then a comma. In the new placekeeper, type f(5), and move away from the plot and click. You should have two plots on this graph (a line and half of a parabola). Double click on the plot, and using the Plot format dialog, make the line solid and the curve a dashed line (use the pull down menus under Traces to do this).
Example 5. Entering and graphing data
Few operations are as basic to chemistry as data analysis. You will often be required to plot discrete pairs of x-y data obtained in the laboratory. In Mathcad, discrete data of this type are entered into subscripted arrays, so first we must discuss subscripts. Note that in example 4 we generated the data to be plotted from a function and a range variable. Here we assume that we have a number of x-y points to be plotted.
Subscripts are numerical quantities which label positions (or indices) in an array of numbers. An array is simply a list of numbers. In this example, we will create two arrays to hold 5 pairs of x-y data in the space below. First, left-click the Vectors and Matrices toolbar; the Matrix dialog box appears (you can click and drag in the title bar (the blue area where it says Matrices) to move it around). In the area below, left click and type "x:" , and then click the picture of a matrix in the Matrix toolbar. You will create an array of 5 rows and 1 column at the vacant placekeeper. Go to the Matrix dialog box; change it so it says 5 rows and 1 column, and click the Create button. A 5x1 matrix appears at the placekeeper. Somewhere to the right of the definition of x, define a variable y similarly ("y:"); then hit the Create button on the Matrices dialog box to create an array to hold the y-values. You may close the Matrices dialog box by double-clicking on the 'x' in the upper right hand corner.
Now we have a place to stash our experimental data. In the x-array, enter the following 5 values: 1,2,3,4,5. Click on each placekeeper and enter the values. Similarly, in the y-array, enter the values 2.01, 2.98, 4.04, 4.97, 6.03.
Now, we have 5 discrete x-y pairs of data to play with. We need a way to deal with each observation discretely - we need to tell Mathcad to deal with pair #1, 2, 3, 4, or 5. To do this, we use a subscript variable. To set this up, do the following: pull down the Math menu, select Options, and change the ORIGIN from 0 to 1 (this step is VERY important). Below, left-click and define a variable i as a range variable from 1 to 5 (since we have 5 pairs of data). To do this, type "i:1;5" (that is, i(colon)1(semicolon)5
In a range statement such as this, the range is incremented by 1 if the middle number is left out of the range statement (remember exercise 4?) now screen print i below (type "i=")
so i takes on five integer values, and we have 5 x-y pairs. (you just knew there'd be a connection, huh?) To use this variable i to address each element of the arrays x and y, we use i as a subscript variable. Subscript variables are created using the left square bracket ( [ ) on the keyboard. Below, type "x[1=". What do you get? Change the subscripted 1 to a 2, and to a 3, and so on. Somewhere to the right of the x stuff, type "y[1=", and change the 1 to a 2 to a 3, etc. Get the picture? For discrete data sets the subscript variable i lets us address each element of the data arrays individually.
Now, to plot the data in the arrays x and y, we create an empty plot in the space below (click and then select X-Y plot from the Graphing palette).
On the middle placekeeper of the y-axis, type "y[i"; on the middle placekeeper in the x-axis, type "x[i". Move away from the plot and click to display the data. You should remember that whenever you enter discrete data pairs into Mathcad using arrays, you must use a subscripted variable when you perform any manipulations with this data. (Don't worry - you'll get used to it!)
Resize the above plot (get it surrounded by a dotted line and drag the bottom right corner). Double-click to bring up the Format plot dialog, and plot the data as squares with no line through them (use the pull-down menus in the Traces section). Hide the x and y axis arguments (again, in the Traces section), and use axis labels and a title (available in the Labels section).
Example 6. Fitting data to a line
You will encounter numerous occasions in your Chemistry coursework where you will need to fit the best straight line to a set of data, and this example can serve as a template. Following example 5, we first set up two arrays, x and y, both with 7 rows and 1 column (do this in the space below). In the x-array, enter the points -1, 0, 1, 2, 3, 4, 5. In the y-array, enter the points 2.95, 4.25, 5.43, 7.50, 7.92, 9.15, 10.32. (remember to pull down the math menu, select matrices, click below and type "x:", then set the array to 7 rows 1 column, and click create; then define y and do the same).
Make sure that the ORIGIN is set to 1 (Math menu, Options). We have 7 points so we need a subscript variable which runs from 1 to 7. Define i as follows: type "i:1;7"
At this point, we plot the data (go ahead and make a plot with the x-variable as the independent variable). Don't forget to subscript x and y as you place them in the placekeepers. Bring up the plot format dialog box and display the data as boxes with no line drawn through them.
You should notice that y seems to depend linearly upon x; so if we were looking for a function to represent this dependence, we would try a function of the form y = mx + b, where m is the slope of the line and b is the y-intercept. We can do this in Mathcad by calculating the slope (m) and the intercept (b) and calculating a new set of y-values using the existing x-values. (Think about it for a second: if you were asked to print out the above plot and draw the best fit line by hand, you would, in a sense, be calculating the slope and intercept mentally and constructing a new set of y values corresponding to the existing x values). To do this in Mathcad, we use the slope and intercept operators. Define a variable m by typing "m:slope(x,y)"; similarly, define a variable b by typing "b:intercept(x,y)". slope and intercept are canned Mathcad operators which return the slope and intercept of the arrays x and y (one caution: in the arguments, the independent variable is given first, followed by the dependent variable). Make these definitions below:
You can print the values of these quantities by typing "m=" and "b="
Now, since we are fitting a linear function to the data, and there are 7 points, we define a new subscripted variable (call it ynew) by typing "ynew[i:m*x[i(spacebar)+b". Define this variable below:
Be sure you understand the purpose of the subscripts! Now, we make a plot just like we did above and put y[i in the y-axis placekeeper and x[i in the x-placekeeper:
Go to the plot format dialog and get rid of the line (show the experimental data as points only). Next, click on the y[i in the y-axis placekeeper, hit the spacebar, followed by a comma, and type "ynew[i" in the new placekeeper. Click away from the plot to display the result - you should see your experimental data as points with a line running through them (note that the ONLY time you should turn in a plot with a line on it is when you have actually fit the line to the data - otherwise, we display experimental data as points only). Hide the axis arguments and place proper axis labels and a title on the plot. You can also place a legend on the plot to clarify things for the reader.
The End
This is only an introduction to the capabilities of Mathcad. You are encouraged to explore other things that this software will do, and to use this tutorial as an aid in your studies.
DAC 9/01