mathcad variable names a string of characters (including numbers and some “special” characters...
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 A1 is different from A1
The “[“ indicates an array subscript. Thus A1 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 asfunctions or predefined symbols (from the calculator tool pad:
Square Root: Or \
Absolute Value: | | (put expression in edit box, hit | key)
Powers of “ e “ : e
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:= 3Y(x) = A*3Y(2)=6A:=10Y(2) = 6
Functions
Functions can have other functions in them, providing they have been previously defined.
Y(x) := x2
A(y, x):= y2+Y(x)
A(2, 3) = 13Y13
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 RowsAdd / Delete ColumnsAdd / 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
2
4
3
5
4
6
5
7
8
24
15
35
2
4
3
5
4
6
5
7
8
24
15
35
Vectorized
2
4
3
5
4
6
5
7
26
46
31
55
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 timeit is in found in the worksheet (following usual worksheet evaluation – To right or anywhere below)
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
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
0 5 10 15 200
500
1 103
1.5 103Area of Circle
Radius, ft
Are
a,ft
^2