Basic Operations on Numbers
LABVIEW MATHSCRIPT has many
arithmetic operations and functions built in. Most of them are
straightforward to use. The
Table below lists some commonly used
scalar operations; in this table,
x and
y are scalars. (A scalar is a single number.)
Common scalar mathematical operations in LABVIEW MATHSCRIPT
| Operation |
LABVIEW MATHSCRIPT |
| x-yxy |
x-y |
| x+yxy |
x+y |
| xyxy |
x*y |
| xyxy |
x/y |
| xyxy |
x^y |
| exex |
exp(x) |
| log10xlog10x |
log10(x) |
| lnxlnx |
log(x) |
| log2xlog2x |
log2(x) |
Expressions are formed from numbers, variables, and these operations. The operations have different precedences. The ^ operation has the highest precedence; ^ operations are evaluated before any other operations. Multiplication and division have the next highest precedence, and addition and subtraction have the lowest precedence. Precedence is altered by parentheses; expressions within parenthesesare evaluated before expressions outside parentheses.
Example 1
The
Table below shows several mathematical formulas, the corresponding LABVIEW MATHSCRIPT expressions, and the values that LABVIEW MATHSCRIPT would compute for the expressions.
Example LABVIEW MATHSCRIPT Expressions
| formula |
LABVIEW MATHSCRIPT Expression |
Computed Value |
|
52+42
52
42
|
5^2+4^2 |
41 |
|
5+42
54
2
|
(5+4)^2 |
81 |
|
2+34-5
23
45
|
(2 + 3)/(4 - 5) |
-5 |
|
log10100
log10
100
|
log10(100) |
2 |
|
ln42+3
ln
4
23
|
log(4*(2+3)) |
2.9957 |
Basic Operations on Matrices
In addition to scalars, LABVIEW MATHSCRIPT can operate on matrices. Some common matrix operations are shown in the
Table below; in this table,
M and
N are matrices.
Common matrix mathematical operations in LABVIEW MATHSCRIPT
| Operation |
LABVIEW MATHSCRIPT |
| MNMN |
M*N |
| M-1M-1 |
inv(M) |
| MTMT |
M' |
| det(MM) |
det(M) |
LABVIEW MATHSCRIPT functions length and size are used to
find the dimensions of vectors and matrices, respectively.
LABVIEW MATHSCRIPT can perform an operation on each element of a vector or matrix. To perform an arithmetic operation on each element in a vector (or matrix), rather than on the
vector (matrix) itself, then the operator should be preceded by
".", e.g .*, .^ and ./.
Example 2
Let
A= 1 1 1 1
A
1
1
1
1
.
Then A^2 will return
AA= 2 2 2 2
AA
2
2
2
2
,
while A.^2 will return
12121212= 1 1 1 1
12
12
12
12
1
1
1
1
.
Example 3
Given a vector x, compute a vector y having elements
yn=1sinxn
yn
1
xn
.
This can be easily be done in LABVIEW MATHSCRIPT by typing y=1./sin(x)
Note that using / in place of ./ would result in the (common) error
Matrix dimensions must agree.
Complex numbers
LABVIEW MATHSCRIPT has excellent support for complex
numbers with several built-in functions available. The imaginary
unit is denoted by i or (as preferred in electrical engineering) j.
To create complex variables
z1=7+ⅈ
z1
7
and
z2=2eⅈπ
z2
2
e
simply enter
z1 = 7 + j and z2 = 2*exp(j*pi)
The
Table below gives an overview of the basic
functions for manipulating complex numbers, where
zz is a complex number.
Manipulating complex numbers in LABVIEW MATHSCRIPT
| |
LABVIEW MATHSCRIPT |
| Re(zz) |
real(z) |
| Im(zz) |
imag(z) |
| |z|z |
abs(z) |
| Angle(zz) |
angle(z) |
| z*z* |
conj(z) |
Other Useful Details
- A semicolon added at the end of a line tells LABVIEW MATHSCRIPT to suppress
the command output to the display.
- LABVIEW MATHSCRIPT Version 1.0 is case sensitive for both variables and functions; for example,
b and B are different variables and LABVIEW MATHSCRIPT will recognize the built-in function sum but not SUM. In previous versions, LABVIEW MATHSCRIPT was not case sensitive for function names. - Often it is useful to split a statement over multiple lines. To split a
statement across multiple lines, enter three periods
... at the end of
the line to indicate it continues on the next line.
Example 4 Splitting
y=a+b+c
y
a
b
c
over multiple lines.
y = a...
+ b...
c;
"This course provides a brief introduction to LabVIEW MathScript, the textual math componenet of LabVIEW. The modules for this course include typical syntax and programming methods commonly used […]"