# 2.1 Lab 2: labview mathscript and hybrid programming

 Page 1 / 6

## Arithmetic operations

There are four basic arithmetic operators in .m files:

+ addition

- subtraction

* multiplication

/ division (for matrices, it also means inversion)

The following three operators work on an element-by-element basis:

.* multiplication of two vectors, element-wise

./ division of two vectors, element-wise

.^ raising all the elements of a vector to a power

As an example, to evaluate the expression ${a}^{3}+\sqrt{\text{bd}}-4c$ , where $a=1\text{.}2$ , $b=2\text{.}3$ , $c=4\text{.}5$ and $d=4$ , type the following commands in the Command Window to get the answer (ans) :

>>a=1.2;

>>b=2.3;

>>c=4.5;

>>d=4;

>>a^3+sqrt(b*d)-4*c

ans =

-13.2388

Note the semicolon after each variable assignment. If the semicolon is omitted, the interpreter echoes back the variable value.

## Vector operations

Consider the vectors x $=\left[{x}_{1},{x}_{2},\text{.}\text{.}\text{.},{x}_{n}\right]$ and y $=\left[{y}_{1},{y}_{2},\text{.}\text{.}\text{.},{y}_{n}\right]$ . The following operations indicate the resulting vectors:

x*.y $=\left[{x}_{1}{y}_{1},{x}_{2}{y}_{2},\text{.}\text{.}\text{.},{x}_{n}{y}_{n}\right]$

x./y $=\left[\frac{{x}_{1}}{{y}_{1}},\frac{{x}_{2}}{{y}_{3}},\text{.}\text{.}\text{.},\frac{{x}_{n}}{{y}_{n}}\right]$

x.^p $=\left[{x}_{1}^{p},{x}_{2}^{p},\text{.}\text{.}\text{.},{x}_{n}^{p}\right]$

Note that because the boldfacing of vectors/matrices are not used in .m files, in the notation adopted in this book, no boldfacing of vectors/matrices is shown to retain consistency with .m files.

The arithmetic operators + and – can be used to add or subtract matrices, vectors or scalars. Vectors denote one-dimensional arrays and matrices denote multidimensional arrays. For example,

>>x=[1,3,4]

>>y=[4,5,6]

>>x+y

ans=

5 8 10

In this example, the operator + adds the elements of the vectors x and y, element by element, assuming that the two vectors have the same dimension, in this case $1×3$ or one row with three columns. An error occurs if one attempts to add vectors having different dimensions. The same applies for matrices.

To compute the dot product of two vectors (in other words, $\sum _{i}{x}_{i}{y}_{i}$ ), use the multiplication operator ‘*’ as follows:

>>x*y'

ans =

43

Note the single quote after y denotes the transpose of a vector or a matrix.

To compute an element-by-element multiplication of two vectors (or two arrays), use the following operator:

>>x .* y

ans =

4 15 24

That is, x .* y means $\left[1×4,3×5,4×6\right]$ = $\left[\begin{array}{ccc}4& \text{15}& \text{24}\right]\end{array}$ .

## Complex numbers

LabVIEW MathScript supports complex numbers. The imaginary number is denoted with the symbol i or j, assuming that these symbols have not been used any other place in the program. It is critical to avoid such a symbol conflict for obtaining correct outcome. Enter the following and observe the outcomes:

>>z=3 + 4i % note the multiplication sign ‘*’ is not needed after 4

>>conj(z) % computes the conjugate of z

>>angle(z) % computes the phase of z

>>real(z) % computes the real part of z

>>imag(z) % computes the imaginary part of z

>>abs(z) % computes the magnitude of z

One can also define an imaginary number with any other user-specified variables. For example, try the following:

>>img=sqrt(-1)

>>z=3+4*img

>>exp(pi*img)

## Array indexing

In .m files, all arrays (vectors) are indexed starting from 1 − in other words, x(1) denotes the first element of the array x. Note that the arrays are indexed using parentheses (.) and not square brackets [.], as done in C/C++. To create an array featuring the integers 1 through 6 as elements, enter:

#### Questions & Answers

how can chip be made from sand
Eke Reply
is this allso about nanoscale material
Almas
are nano particles real
Missy Reply
yeah
Joseph
Hello, if I study Physics teacher in bachelor, can I study Nanotechnology in master?
Lale Reply
no can't
Lohitha
where is the latest information on a no technology how can I find it
William
currently
William
where we get a research paper on Nano chemistry....?
Maira Reply
nanopartical of organic/inorganic / physical chemistry , pdf / thesis / review
Ali
what are the products of Nano chemistry?
Maira Reply
There are lots of products of nano chemistry... Like nano coatings.....carbon fiber.. And lots of others..
learn
Even nanotechnology is pretty much all about chemistry... Its the chemistry on quantum or atomic level
learn
Google
da
no nanotechnology is also a part of physics and maths it requires angle formulas and some pressure regarding concepts
Bhagvanji
hey
Giriraj
Preparation and Applications of Nanomaterial for Drug Delivery
Hafiz Reply
revolt
da
Application of nanotechnology in medicine
has a lot of application modern world
Kamaluddeen
yes
narayan
what is variations in raman spectra for nanomaterials
Jyoti Reply
ya I also want to know the raman spectra
Bhagvanji
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
Nasa has use it in the 60's, copper as water purification in the moon travel.
Alexandre
nanocopper obvius
Alexandre
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
Any one who tell me about Preparation and application of Nanomaterial for drug Delivery
Hafiz
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

### Read also:

#### Get Jobilize Job Search Mobile App in your pocket Now!

Source:  OpenStax, An interactive approach to signals and systems laboratory. OpenStax CNX. Sep 06, 2012 Download for free at http://cnx.org/content/col10667/1.14
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'An interactive approach to signals and systems laboratory' conversation and receive update notifications? By Brooke Delaney By Brooke Delaney By OpenStax By Sheila Lopez By Angela Eckman By OpenStax By Jams Kalo By OpenStax By OpenStax By Brooke Delaney