# Connexions

You are here: Home » Content » Basic operations in LabVIEW MathScript

### Lenses

What is a lens?

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

#### Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
• NSF Partnership

This module is included inLens: NSF Partnership in Signal Processing
By: Sidney BurrusAs a part of collection: "Introduction to LabVIEW MathScript"

Click the "NSF Partnership" link to see all content affiliated with them.

Click the tag icon to display tags associated with this content.

• National Instruments

This module is included in aLens by: National InstrumentsAs a part of collection: "Introduction to LabVIEW MathScript"

"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 […]"

Click the "National Instruments" link to see all content affiliated with them.

Click the tag icon to display tags associated with this content.

#### Also in these lenses

• Lens for Engineering

This module is included inLens: Lens for Engineering
By: Sidney Burrus

Click the "Lens for Engineering" link to see all content selected in this lens.

• NI Signal Processing

This module is included inLens: Digital Signal Processing with NI LabVIEW and the National Instruments Platform
By: Sam ShearmanAs a part of collection: "Introduction to LabVIEW MathScript"

"Tutorial / Introduction to LabVIEW MathScript, a text-based component of National Instruments LabVIEW that allows you to run your .m file scripts in LabVIEW Virtual Instruments."

Click the "NI Signal Processing" link to see all content selected in this lens.

Click the tag icon to display tags associated with this content.

### Recently Viewed

This feature requires Javascript to be enabled.

### Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.

# Basic operations in LabVIEW MathScript

Module by: Anthony Antonacci. E-mail the author

Summary: This module covers basic operations in LabVIEW MathScript.

## 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.)

Table 1: Common scalar mathematical operations in LABVIEW MATHSCRIPT
Operation LABVIEW MATHSCRIPT
xyxy 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.

Table 2: 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+345 23 45 (2 + 3)/(4 - 5) -5
log10100 log10 100 log10(100) 2
ln4×(2+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.

Table 3: 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 ( 1212 1212 )=( 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+i z1 7 and z2=2eiπ 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.

Table 4: 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;

## Content actions

PDF | EPUB (?)

### What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

### Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks