Anda di halaman 1dari 14

CivE 125 / EnvE 100 - Week 8 - Monday Tutorial

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.

There are no hidden formulas or cell references.

Mathematical functions are displayed as they would be printed in a text or notes.

Once variables or variable ranges are defined, functions can be plotted, solved, etc.

Calculations can incorporate units.

Easy to use (after initial learning curve).

Powerful plotting and analysis tools.

Solutions to many engineering problems are available on the internet.

Mathcad at the University of Waterloo

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.

The version of Mathcad sold in CHIP is Mathcad 11.1

Important Note: Mathcad files from 11.1 may not be backward-compatible.

CivE 125 / EnvE 100


Mathcad Basics

Page 2

To see a list of Engineering and other courses using Mathcad at Waterloo, go to


www.uwaterloo.ca and do a search using the keyword Mathcad. Some information and
examples presented here have been adapted from the Universitys web site.

Support and examples of Mathcad applications can be found at http://www.mathcad.com/.

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.

Graphs must start after the definition of the equation to be evaluated.

To get out of any expression, left-click anywhere outside the expression.

The undo command only works if the cursor is still on the expression.

Click on any entity (variable, expression, etc.) to edit it.

Mathcad is case sensitive.

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.

There are four (4) different equal signs in Mathcad:

Assignment

:=

Enter in Mathcad by typing the colon key <:>.


This type of equals sign is used to assign a value to a
variable or to define a function. More information on
assigning or defining variables and functions is provided
in the following section.

Display the Value

Enter in Mathcad by typing the equals sign <=>.


This equals sign is used to display the value of a variable
or to return the calculated result of a function or
equation. More information on evaluating functions is
provided in the following section.

CivE 125 / EnvE 100


Mathcad Basics

Page 3

Enter in Mathcad by typing <ctrl+=>.

Symbolic Equality

The symbolic equality is a heavy, bold equals sign. It is


used to show a relationship between variables. That is, it
shows that the combination of variables to the left of the
equality is equal to the combination of variables on the
right. This type of equals sign is primarily used for
symbolic math in Mathcad.

Global Assignment

Enter in Mathcad using the tilde key <~>.


This equals sign is used to assign global variables that
are not subject to the left-to-right and top-to-bottom
evaluation order.
Global assignments are not common. It may be desirable
to use global assignments for user-defined units or
constants (although it is not strictly necessary).
Global assignments are used to set ORIGIN 1 to
make arrays begin with element 1, otherwise arrays
begin with element 0. This will be illustrated in the
following section.

Defining Variables and Functions

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.

CivE 125 / EnvE 100


Mathcad Basics

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 insert an exponent, press <^>: e.g. 2^3 will result in 23.

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.

CivE 125 / EnvE 100


Mathcad Basics

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

Inserted 2-D Graph Function

10

10

Plot of y(a) versus a

To change the plot formatting, double-click on the plot and change the options available in
the dialog box.

Important Note: Default Mathcad graph


(chart) formatting is not acceptable for
your assignments and reports! Follow the
guidelines discussed previously in this
course to format your plots.

CivE 125 / EnvE 100


Mathcad Basics

Page 6

Units

Variables and functions can be defined to include units.

Subsequent calculations will incorporate units, even automatically converting between


different units and systems of measurement.

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

(since no units are specified, is assumed to be in radians)

:= 30 deg
sin( ) = 0.5

(since was defined in degrees, we now get the answer


we were expecting)

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.

Most commonly used functions are available in toolbar menus.

CivE 125 / EnvE 100


Mathcad Basics

Page 7

Example 1: Working With Units


This example will illustrate how Mathcad incorporates units into calculations.
We will use one of the equations of kinematics with different unit systems for distance, velocity
and acceleration.
1
x ( t ) = x o + v o t + at 2
2

Let:

[1]

xo = 1000 inches
vo = 60 miles per hour
a

= -25 centimetres per second per second (deceleration)

1. Start by opening Mathcad and saving the file as Units Example.mcd


2. Type a title near the top of the Mathcad Sheet.
Type: Example 1: Working With Units
3. We will use the SI system of units. Check to make sure Mathcad is set to use SI Units by
selecting Options under the Math menu, and clicking on the Unit System tab.
4. Lets define our initial location, velocity and acceleration (remember to use a colon <:> to
define or assign a variable). We will specify units for each. We do this in Mathcad by
multiplying <*> the magnitude of the variable by the desired units.
Click below our title (Step 2)
Type: x.o : 1000*in <enter>
v.o : 60*mph <enter>
a : -25*cm / s^2 <enter>
You should see:
xo := 1000 in
vo := 60 mph
a := 25

cm
2

CivE 125 / EnvE 100


Mathcad Basics

Page 8

5. Define equation [1].


Type: x(t) : x.o + v.o*t + 1/2 <sp> * a * t^2 <enter>
You should see:
1 2
x( t) := x o + v o t + a t
2

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.

CivE 125 / EnvE 100


Mathcad Basics

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.

CivE 125 / EnvE 100


Mathcad Basics

Page 10

Example 2: Plotting a Function and Solving for Roots


In this example, we will plot the equation for the damped free vibration of a building subject to
an initial lateral displacement. After we plot the function, we will solve for the first two roots.

x ( t ) = e t cos(t )

Where:

[2]

x(t)

= frequency of vibration = 2 3 rad/sec


= damping ratio = 7% = 0.07
xo = initial displacement = x(0) = 25 cm
xo (for small values of (< 10%))
in radians (for small (< 10%))
t = time (seconds)

Idealized structure with 2 columns

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

:=

4. Define equation [2].


Type: x (t) : r ctrl+g * e^- x ctrl+g * w ctrl+g * t <sp> <sp> <sp> * cos (w ctrl+g * t
q ctrl+g) <enter>

CivE 125 / EnvE 100


Mathcad Basics

Page 11

You should see:


t

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.

CivE 125 / EnvE 100


Mathcad Basics

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.

Lateral Displacement (m)

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

CivE 125 / EnvE 100


Mathcad Basics

Page 13

Lateral Displacement (m)

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

Change L and U to automatically solve for the second root:


L := 0.2 U := 0.4
root ( x( t) , t , L , U) = 0.254

CivE 125 / EnvE 100


Mathcad Basics

Page 14

Example 3: 3-D Plotting


This example will create a surface plot and a contour plot of the following function:

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 Appearance, Fill Surface, Colormap, OK


You can rotate the plot by holding down the left mouse button and moving. The
viewing position of the plot can also be changed by double-clicking on the plot
and adjusting the View parameters on the General tab.
4. Make a 3-D Contour Plot of the function.
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