Mathcad - For Civil Engineering
Mathcad - For Civil Engineering
INTRODUCTION TO MATHCAD
Mathcad is calculation software which lets users integrate text, calculations and graphs, then
document and share the results in an easy-to-use environment.
Mathcad is a powerful mathematical tool that can be used for data analysis, graphing (2-D
and 3-D), solving equations, linear algebra, statistics, calculus, and symbolic math.
This tutorial will cover the basics of using Mathcad for data analysis and graphing. In the
second Mathcad tutorial, we will use Mathcad to compute cross-sectional areas and volumes
of material to be excavated using your survey data. You will need these calculations for your
course project.
You will have the opportunity to use Mathcad in other courses throughout your engineering
education.
Strengths of Mathcad
What you see is what you get. The Mathcad environment is like a blank worksheet, and
information and formulas can be entered anywhere on the sheet.
Once variables or variable ranges are defined, functions can be plotted, solved, etc.
Mathcad 2001 Professional is available in the WEEF Lab and the Multi-Media Lab.
Mathcad may be purchased from the Computing Help and Information Place (CHIP) in
MC1052 for $15. You can also purchase a Users Guide for $35. For information go to
http://ist.uwaterloo.ca/admin/mathcad.html.
Page 2
General Guidelines
For these notes, the information between angle brackets < > has to be typed as indicated.
ctrl, sp, sft, and Tab mean the control, space, shift, and Tab keys, respectively.
Evaluation is from left to right, and from top to bottom; unless, it is a global variable. This
means that if you enter a function that contains variables, the variables must be defined above
or to the left of the function. Variables not defined in this manner will appear in red.
The relative positions of functions (i.e., which equation is above or below another) is based
on the anchor point for the equation. Mathcad assigns an anchor point to each equation
located to the left of the first character, at the character baseline. You can see the anchor
points by selecting Regions from the View menu. The anchor point is visible as a small,
black dot.
The undo command only works if the cursor is still on the expression.
To add text, locate the cursor, red + symbol, in the desired location with the mouse, press
<> and then begin typing.
To add an equation, locate the cursor, red + symbol, in the desired location with the mouse
and then begin typing.
Assignment
:=
Page 3
Symbolic Equality
Global Assignment
To define or assign a variable or function, press <:> rather than <=>. For example:
To assign a value of 4 to the variable a,
Typing
a:4
Results in a := 4
To define the function y(a) = 12a +3,
Typing
y (a) : 12 a + 3
Results in y( a) := 12 a + 3
To evaluate a function or equation that has already been defined (i.e., return the result of the
calculation), use the normal equals sign, <=>. For example:
To evaluate the above expression for y,
Typing
y (a) =
Results in y( a) = 51
If the value of a (defined previously as 4) is changed, the result of the expression for
y(a) = will be automatically recalculated.
Page 4
To define a range of values for a, press <;> after pressing <:>. Then type the starting
value, <,>, the second value and the last value of a in the range. For example,
To define a range of a from 0 to 10 by 2,
Typing
a : ; 0 , 2 <tab> 10
Results in a := 0 , 2 .. 10
As soon as we finish defining the range for a, y(a)= is recalculated for each value of
a in the range and shown as:
y( a) =
3
27
51
75
99
123
When typing an expression, the cursor changes to a blue vertical line and the variables that
will be affected by the operation are underline in blue. To change the variables that will be
affected press space bar <sp>.
To define the name of a variable that has a subscript, type the variable name, press <.> and
type the name of the subscript: e.g. A.o will result in Ao
When working with vectors and arrays, subindices are entered after pressing the square
bracket <[>. For example, if we have the following 3x3 array, and we want to return the
value of the entry in location 2,2 of the array:
ORIGIN 1
Typing
1 2 3
V := 4 5 6
7 8 9
V[2,2=
Results in V2 , 2 = 5
Although the square bracket results in a subscript, it is not the same as using a period
<.> to produce a subscript when defining a variable, as described above. Using a <.>
instead of <[> in the example above would return an error, since Mathcad would
assume you are trying to return the result of an undefined variable.
NOTE: The ORIGIN 1 command was used to indicate that the array indices start at
1. If it had not been used, a result of V2 , 2 = 9 would have occurred, since the first
column and row of the array would have been called column 0 and row 0.
Page 5
To define a variable that has Greek symbols, type the corresponding letter and then press
<ctrl+g>: e.g. t followed by <ctrl+g> will result in .
To import data from Excel, define a variable and press <:>, copy and paste the data in the
placeholder red square.
Graphs
Insert 2-D and 3-D graphs using the Insert menu. Graphs may also be inserted by pressing
<sft+2> for 2-D plots, and <ctrl+2> for 3-D plots.
The function(s) to be plotted must be defined above or to the left of the graph.
Once the chart has been inserted, click on the black box placeholders on the axes to define
the functions and variables to be plotted. For example,
Type <y(a)> in the y-axis box and <a> in the x-axis box.
123
150
100
black
boxes
y ( a)
50
3
10
10
To change the plot formatting, double-click on the plot and change the options available in
the dialog box.
Page 6
Units
Units must be specified for all variables in a function or Mathcad will be unable to evaluate
the function.
System of units: By default, Mathcad assumes you are using the fundamental SI units: m,
kg, s, K, A, cd, and mole. To use a different system of units, choose Options from the
Math menu and click on the Unit System tab. Click on the whatever default system of
units you want to use. If you choose None, you can define your own system of units.
Refer to the Mathcad Help for more information.
Built-In Units: Mathcad has a series of units built-in. This means that Mathcad will
recognize standard units without the user having to define them. Examples include m
(metre), mph (miles per hour) and s or sec (seconds). To see a list of built-in units, go to
Help and search for built-in units. You can also choose Unit under the Insert menu to
see a list of available built-in units.
Trigonometric Functions: By default, trig functions assume that the input angle has units
of radians. However, if you define the angle as a variable with units of degrees, Mathcad
will automatically convert degrees to radians while executing the trig function. For example,
compute the sine of 30 degrees:
:= 30
sin( ) = 0.988
:= 30 deg
sin( ) = 0.5
The user can define different units or an entire system of units. Refer to the Mathcad help.
Help???!!!
Main help function press <F1>. The search function is very helpful.
A PDF version of the Mathcad Users Guide and Reference Manual is available on the
Mathcad CD-ROM.
Page 7
Let:
[1]
xo = 1000 inches
vo = 60 miles per hour
a
cm
2
Page 8
6. Define a range of time, t, for which x(t) will be evaluated. We will specify units of seconds
for time. If we do not specify units for one or more of the variables, Mathcad will not be able
to evaluate the expression x(t). Let us start t at 0 sec., and go to 50 sec. in 5 sec. intervals.
Type: t : ; 0*s , 5*s tab 50*s <enter>
You should see:
t := 0 s , 5 s .. 50 s
7. Evaluate x(t) for the specified range of t (remember to use an equals sign <=> to evaluate a
variable or function). Since we have defined a range of t, Mathcad will return an vector
containing the value of x(t) for each t. (Note, to see a vector containing the values of t, type
<t = > <enter>)
Type: x(t) = <enter>
You should see:
x( t) =
25.4 m
156.387
281.124
399.611
511.848
617.835
717.572
811.059
898.296
979.283
1.05410 3
Since we are using SI units, Mathcad returns our answer in its default units for length, or
metres. If you would like to change the number of decimal places displayed, click anywhere
in the block for x(t) =, and select Result under the Format menu.
Page 9
8. In the background, Mathcad has converted our values of xo, vo and a into m, m/s and m/s2,
respectively, and has returned an answer in metres without us having to worry about units.
To see the converted values of our variables, evaluate the variables as follows (using
<=>):
Type: x.o = <enter>
v.o = <enter>
a = <enter>
You should see:
xo = 25.4 m
m
vo = 26.822
s
a = 0.25
m
2
9. Lets change the output units of x(t) from metres to kilometres. Click within the block for
x(t) =, then click on the black box placeholder to the right of m. Type the new units, in
this case <km>, and hit enter. The output for x(t) will be immediately reported in kilometres.
black
box
results
disappear
temporarily
when typing
km
results in km
appear after
hitting (enter)
Try changing kilometres to inches. To do this, insert your cursor to the right of km and hit
backspace twice to delete it. Then, type <in> and hit enter.
Page 10
x ( t ) = e t cos(t )
Where:
[2]
x(t)
1. Start by opening Mathcad and saving the file as Free Vibration Example.mcd
2. Type a title near the top of the Mathcad Sheet.
Type: Example 2: Plotting a Function and Solving for Roots
3. Lets define our variables (remember to use a colon <:> to define a variable). We will
include units where applicable.
Click below our title (Step 2)
Type: w ctrl+g : 2*ctrl+p * 3 * rad/s <tab> x ctrl+g : 0.07 <tab> x.o : 25*cm <enter>
r ctrl+g : x.o <tab> q ctrl+g : x ctrl+g
You should see:
:= 2 3
:= xo
rad
s
:= 0.07
xo := 25 cm
:=
Page 11
x( t) := e
cos( t )
Our result should have units of length, since is 25 cm and all other units cancel out.
Note that Mathcad will assign units of metres to x(t), since this is the default unit for
length in the SI system of units.
5. Define a range of time, t, for which x(t) will be evaluated. Let us start t at 0 sec., and go to
3 sec. in 0.03 sec. intervals.
Type: t : ; 0*s , 0.03*s tab 3*s <enter>
You should see:
t := 0 s , 0.03 s .. 3 s
6. Plot the function x(t). Click somewhere below the function x(t) and the defined range of t.
Press <sft+2> to insert a 2-D graph. Click on the black box near the y-axis and type <y(t)>.
Click on the black box near the x-axis and type <t> then hit enter. You should see the plot
below.
0.2
x ( t)
0
0.2
Important Note: Mathcad plots always use the default units for the system of units selected.
Since we are using the SI system, x(t) is plotted in metres.
Although we now have a plot of the function x(t), the formatting is terrible. Use the
handles on the graph to drag it larger to fill the page width. Click in the plot, and then
click on the maximum value on the y-axis (which should be 0.25). Delete 0.25 and type
<0.3>, then hit enter (Note: the plot will temporarily disappear when you delete 0.25).
Repeat for the minimum value of the y-axis, changing it to 0.3. Add horizontal grid lines by
double clicking on the plot and checking the box for Y-Axis Grid Lines. Click on the tab for
Labels and add labels for the x- and y-axes.
Page 12
Now our plot should appear as shown below. We can see that the initial displacement is
0.25 m (specified as xo = 25 cm), and that the structure will oscillate about the zero
displacement position. The vibrations decrease to near zero over the 3 second duration of the
plot.
0.2
0.1
x ( t)
0.1
0.2
0.5
1.5
2.5
t
Time (sec.)
7. Now lets solve for the first two roots using the Root command. A complete description
of the Root command can be found with Mathcad Help. Root will solve for a single root
based on either:
a) A guess value close to the root of interest
b) Lower and upper limits, between which the root of interest lies.
In order to help us determine guess values and lower and upper limits, lets change the
x-axis limits to a maximum of 1 second to better show the function near the first few roots.
Your plot should look like the one shown on the following page.
To use a guess value, we need to first define a guess for the root. For this example, lets
try 0.10 sec and 0.30 sec.
Type: t : 0.10 <tab> root(x(t),t) = <enter>
t : 0.30 <tab> root(x(t),t) = <enter>
You should see:
t := 0.10
root ( x( t) , t) = 0.087
t := 0.30
root ( x( t) , t) = 0.254
Page 13
0.2
0.1
first
root
x ( t)
second
root
0.1
0.2
0.2
0.4
0.6
0.8
t
Time (sec.)
To use lower and upper limits, we must first define the limits. We will call them L and U,
and assign values on either side of the roots as determined by looking at the above plot.
Type: L : 0 <tab> U : 0.2 <enter>
root(x(t),t,L,U) = <enter>
You should see:
L := 0
U := 0.2
root ( x( t) , t , L , U) = 0.087
Page 14
f ( x, y) = x e ( x
+y2 )
[3]
1. Start by opening Mathcad and saving the file as 3-D Plotting Example.mcd
2. Define equation [3].
Type: f(x , y) : x * e ^ - (x^2 <sp> + y^2 <sp> ) <enter>
3. Make a 3-D Surface Plot of the function. Insert a 3-D plot, and define a quick plot of the
function f (equation [3]).
Type: <ctrl+2> followed by <f> then hit <enter>
Double-click on the chart, then click General, Contour Plot, Appearance, Fill
Contours, OK
Surface Plot
Contour Plot