# 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:

Is there any normative that regulates the use of silver nanoparticles?
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
why we need to study biomolecules, molecular biology in nanotechnology?
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
why?
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
what does nano mean?
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
it is a goid question and i want to know the answer as well
Maciej
Abigail
for teaching engĺish at school how nano technology help us
Anassong
Do somebody tell me a best nano engineering book for beginners?
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
what is fullerene does it is used to make bukky balls
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
what is the Synthesis, properties,and applications of carbon nano chemistry
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
NANO
so some one know about replacing silicon atom with phosphorous in semiconductors device?
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Harper
Do you know which machine is used to that process?
s.
how to fabricate graphene ink ?
for screen printed electrodes ?
SUYASH
What is lattice structure?
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
what is biological synthesis of nanoparticles
how did you get the value of 2000N.What calculations are needed to arrive at it
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!