# Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number.

## Presentation on theme: "Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number."— Presentation transcript:

Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number Capitalization & spelling count!!! A1 is different from a1 Be careful not to conflict with predefined name (e.g. g = acceleration due to gravity, m = meter, etc. -- which we will discuss later) Be careful that variables and functions have different names

Subscripts The “.” (period) starts a text subscript, which really is part of the variable name A 1 is different from A1 The “[“ indicates an array subscript. Thus A 1 indicates an element in the array A (it is the second element, as array subscripts start with 0 by default in Mathcad)

Functions Similar to Excel function Have a name with argument list in ( ) Return a value ( or set of values)

Common math functions implemented as functions or predefined symbols (from the calculator tool pad: Square Root:  Or \ Absolute Value: | | (put expression in edit box, hit | key) Powers of “ e “ : e

Most available as function with a standard math name: log ln sin cos exp abs

Other somewhat useful functions: If ( test expression, true result, false result) Health (Temp) = if ( Temp>98, “Fever”, “No Fever”) Health(100) = “Fever” String functions --- to find length, take substrings, search, concatenate + others.

And, as you might expect, we can write our own. We will look at writing simple functions that can be expressed as a single mathematical expression Example: Function to compute volume of an ideal gas as a function of the gas constant (R), temperature (T), pressure ( P), and moles (n)

First, define the function as you would assign a value to a variable ( use the := sign ) Vol(P,n,R,T) := n*R*T/P Use it like any other function: Volume := Vol(100,1,0.08206,273.15)

Functions can take and use units: Vol ( 1 atm, 2 mol, 0.80206 L*atm/(mol*K), 500K) = 41.03 L But as with all use of units in Mathcad, must be consistent. If evaluation results in incorrect unit operations, will get an error message ( the variable or whatever in red )

Functions Functions “know about” variable values defined to the left and above its definition and those values will be used when the function is used. A:= 3 Y(x) = A*3 Y(2)=6 A:=10 Y(2) = 6

Functions Functions can have other functions in them, providing they have been previously defined. Y(x) := x 2 A(y, x):= y 2 +Y(x) A(2, 3) = 13Y13

Arrays, Vectors, & Matrices Range Variables Brief Introduction to Plots

Arrays Ordered set of numbers Vector Single Row Or Column Matrix Two or More Rows and / or Columns

Arrays Access elements with array subscript “ [ “ Maximum of two dimensions Define with ctrl-m or matrix tool button First element has index of [0] or [0,0] (can change with the ORIGIN keyword)

Basic Operations Scalar add & multiply -- affects Each element in the array Determinant & Inverse -- square matrix only -- short cut key strokes ( | | & ^ -1 ) Add, subtract, multiply with usual matrix rules on size & shape -- standard math operators (+, -, *)

Resize Operations Add / Delete Rows Add / Delete Columns Add / Delete Rows & Columns Put array (or element) in edit box, type ctrl-m

Vectorize Operation This is a non-standard matrix operation in which the indicated operation is performed element by element

Vectorized Standard Multiply Useful, but be careful!

Range Variable A special type of Mathcad variable Takes on the indicated range of values when found in the worksheet

Range Variable Var := First, Second; Upper Limit ( the ; shows as … ) J := 1,3;10 J takes on values 1, 3, 5, 7 & 9 each time it is in found in the worksheet (following usual worksheet evaluation – To right or anywhere below)

Define and fill a matrix in 4 steps:

Arrays can have units, but each element must have the same dimensions

Range variable not limited to integers:

Range variable can have units:

Plots As in Excel, many type of plots. We will look at the x-y plot

From the menu: Insert / Graph / X-Y plot Add X vector in the box on the x axis Add Y vector in the box on the y axis Can add multiple x – y vector pairs. Works in internal units – no units on plot

Insert / Graph / X-Y Plot Click on plot, then right click to get format menu

Plots If would like specific units for a plot, need to convert the data before or during plotting. Say wanted previous plot in ft & ft^2

As with Excel, plot not complete until has title and axis labels

To add axis labels & titles, select plot then right click. Choose “Labels” and add as desired To get rid of Mathcad’s variables, choose “Trace” and check “Hide Arguments”

Download ppt "Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number."

Similar presentations