Skip to content Skip to navigation

Connexions

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

Navigation

Content Actions

  • Download module PDF
  • Add to ...
    Add the module to:
    • My Favorites
    • A lens
    • An external social bookmarking service
    • My Favorites (What is 'My Favorites'?)
      'My Favorites' is a special kind of lens which you can use to bookmark modules and collections directly in Connexions. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need a Connexions account to use 'My Favorites'.
    • A lens (What is a lens?)

      Definition of a lens

      Lenses

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

      What is in a lens?

      Lens makers point to Connexions 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 Connexions member, a community, or a respected organization.

    • External bookmarks
  • E-mail the author

Lenses

What is a lens?

Definition of a lens

Lenses

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

What is in a lens?

Lens makers point to Connexions 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 Connexions member, a community, or a respected organization.

This content is ...

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.
  • National Instruments

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

    Comments:

    "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.

Also in these lenses

  • 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"

    Comments:

    "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.

Recently Viewed

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 Based on: Basic operations in MATLAB by Anders Gjendemsjø, Darryl Morrell

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

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;

Comments, questions, feedback, criticisms?

Send feedback