Fundamentals of Labview Programming
Fundamentals of Labview Programming
2
=
1
N
(x
I
)
2
N
I=1
"hile the standard deviation for a population is
= _
1
N
(x
I
)
2
N
I=1
"here x
I
is the ith data, is the population mean, and N is the number of data 0population1. +o implement
this formula, "e do the follo"in steps:
1. 'ompute the population mean .
7. 9ubtract the population mean from the data and s.uare their difference. +his .uantit# is called the
s.uared error 0Eii
2
1. Cind the s.uared error for all the data.
:. Add all the error s.uared data. +he sum is called the sum of s.uared error 0SSE1.
<. 2ivide the sum of s.uared error "ith the number of data. +his .uantit#, "hich is a mean, is called
the mean s.uared error 0NSE1. +his is also the variance
2
of the data.
=. +a%e the s.uare root of the variance. +his .uantit# is no" the standard deviation .
+he St&0e)"#)i sho"s ho" the five steps "ere implemented in LabVIEW.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 16
St&0e)"#)i
Cront panel:
,loc% diaram:
+he VI is tested b# enterin test values as sho"n in fiure 1.11.
Figure 1. 11. 2t!+e,1.,i with sample inputs. The output is as e3pecte!.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 17
Eotice that the averain part "as t"ice done: first to determine the population mean, and second to
averae the s.uared error terms. A more eleant bloc% diaram can be built if sub&VIs "ere used. A sub&VI
is a VI that is used as part of a larer VI. +"o thins are needed to be defined "hen ma%in sub&VIs:
1. the functionalit# of the sub&VI! and
7. the input and output ports of this sub&VI.
6ptionall#, an icon for the sub&VI can be customi/ed. +he St&0e)/#)i sho"s the use of such sub&VIs. A VI
named A)erage#)i "as created from the oriinal VI and "as t"ice used. Another VI called the
ErrS@uare&#)i "as also created from the oriinal VI.
St&0e)/#)i
Cront panel:
,loc% diaram:
)ust li%e an# other prorammin lanuaes, #ou ma# encounter t"o t#pes of errors or bus in LabVIEW:
1. those errors or bus that prevent the VI from runnin 0similar to s#ntactical errors in text&based
prorammin lanuaes1! and
7. those errors or bus that cause #our VI to enerate bad results or incorrect behavior.
In both cases, LabVIEW has tools to help #ou deal "ith these errors and bus.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 18
VIs "hich does not run is bro%en or non&executable. +his ma# be caused b# an# of the follo"in:
+he bloc% diaram contains a bro%en "ire because of a mismatch of data t#pes or a loose,
unconnected end.
A re.uired bloc% diaram terminal is un"ired.
A subVI is bro%en or #ou edited its connector pane after #ou placed its icon on the bloc% diaram of
the VI.
A VI "hich cannot be run because of a prorammin error is indicated b# a bro%en arro" as sho"n in the
fiure 1.17.
Figure 1. 12. 4 VI with an error.
+o %no" "hat error has occurred, #ou can clic% the bro%en arro" "hich "ill displa# the error list.
Figure 1. 13. Error list.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 19
+he list suests that the error occurred at the ErrS@uare&#)i because it is not executable. Bou can clic%
the error messae under the Block 0iagram Errors to hihliht the node "hich contains errorIs. 6penin
the subVI reveals the follo"in bloc% diaram
Figure 1. 1". The subVI with an error.
"hich sho"s that the error is caused b# unconnected "ires in the subVI. 'orrect it b# ma%in the proper
connections. With no" a correct subVI, the VI is no" executable. -o"ever, testin the VI "ith the same
sample values as before,
Figure 1. 1$. 2t!+e,2.,i with erroneous output.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 20
We can use LabVIEW5s debuin tools to troubleshoot this apparentl# erroneous VI. +he follo"in can be
used:
1. 9inle steppin execution, "here the VI is run step b# step.
7. ,rea%points "hich pauses the VI "hen data passes throuh and allo"s the prorammer to inspect
the current state of the VI at this point.
6ne can animate the execution of the VI b# clic%in the $ighlight eecution button, and use Probes to
displa# and monitor the values passin thru a "ire "hile the VI executes.
Eam!le "#A
+he file St&0e)/Berr#)i contains errors. $se the debuin tools to correct the errors.
0rill Problems "#6
1. ,uild a VI that "ould solve a .uadratic e.uation of the form
ax
2
+ bx + c = u
b# usin onl# basic arithmetic operations and comparison operators. +a%e note that the s.uare root
operations return a NaN 0not a number1 value "hen it operates on neative numbers. +his should not
be the case "ith #our VI, ho"ever. It should be able to return complex numbers, but do not use
functions for complex numbers #etA 'all this VI as Cua&raticE@uationSol)er#)i
7. $se the Cua&raticE@uationSol)er#)i to build a VI that "ould solve a .uartic e.uation of the form
ax
4
+ bx
2
+c = u
callin this as CuarticE@uationSol)er#)i. )ust li%e in the previous item, the VI should be able to return
complex numbers as ans"ers "ithout usin functions for these.
:. ,uild a VI that "ould convert a decimal number into a 1?&bit binar# number, callin this as 0ecToBin#)i
and another VI that "ould convert a 1?&bit binar# number into its decimal form, callin this as
BinTo0ec#)i
<. $se the VIs built in number : to build 0ecToOct#)i 0decimal&to&octal1 and OctTo0ec#)i 0octal&to&
decimal1.
=. +he VI tscoreBerr#)i computes the 9tudent5s t&score for t"o sets of sampled data. +he t&score of t"o
sets of data indicates "hether there is sinificant difference bet"een the means of the t"o sets. +hese
t"o sets of data can be dependent or independent of each other. +he steps to compute the t&score are
the follo"in:
a. 'ompute the means of the t"o data sets, callin them x
a
and x
b
0"e have used the x s#mbol to
indicate that "e are ta%in the mean of a sample, "hich sa#s that the data at hand are part of a
larer data "hich is the most practical case1.
b. 'ompute the sum of the s.uares of the error for the t"o sets of data, callin them SSE
a
and SSE
b
.
c. 2etermine the sample variance usin the formula
s
2
=
SSE
a
+ SSE
b
(n
a
1) + (n
b
1)
"here n is the number of samples for each data set.
d. 2etermine the standard deviation of the samplin distribution of the sample&mean differences usin
the formula
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 21
= _
s
2
n
a
+
s
2
n
b
e. +he t&score is then computed as
t =
|x
a
x
b
|
$sin LabVIEW5s debuin tools, troubleshoot the VI "hich should ive the correct t&score for the
follo"in set of fifteen data:
Bata set A: 26, 26, 26, 21, 18, 21, 19, 2S, 2S, 29, 22, 22, 24, 2S, 22
Bata set B: 18, 2u, 2u, 26, 17, 2S, 2u, 16, 21, 18, 21, 29, 2u, 2S, 19
Sel1 Assessment3 Date #our level of achievement for the follo"in outcomes:
Outcome
Can4t &o
+.,
5arginal
Per1ormance
+",
Acce!table
Per1ormance
+/,
Ece!tional
Per1ormance
+6,
,uild virtual instruments usin arithmetic
and comparison functions in LabVIEW
'reate a sub&VI out of a portion of, or all of,
a VI alread# made
2ebu VIs usin different debuin tools
Write #our o"n thouhts and reflections on this topic.
1.< LabVIEW5s mathematical functions
At the end of this lesson, the student shall be able to:
a. use LabVIEW5s different elementar# math, statistical and complex number functions! and
b. use "hile loops "ith shift reister and tunnels "ith different modes.
LabVIEW offers different built&in elementar# mathematical, statistical and functions for complex numbers.
+he follo"in function roups are found in the %unctions 77 5athematics 77 Elementary an& S!ecial
%unctions
Trigonometric: functions such as sin, cos, tan, etc., are under this palette.
E!onential: functions such as e!, ln, log, etc., are under this palette.
$y!erbolic: functions such as sinh, cosh, tanh, etc., are under this palette.
Demember that trionometric functions accept radians as inputs and inverse trionometric functions return
anles in radians.
9tatistical functions such as measures of central tendencies 5ean, 5e&ian and 5o&e are found at the
%unctions 77 5athematics 77 Probrability an& Statistics.
'omplex number functions are found at %unctions 77 Numeric 77 Com!le. 9ome of these functions
include 'om!le Con8ugateD Polar to Com!leD Com!le to PolarD -e=Im to Com!leD and so on.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 22
As an example, "e build a VI that accepts input of anle in derees and returns the sine, cosine, tanent,
cosecant, secant and cotanent values for such anle.
Trigo#)i
Cront panel:
,loc% diaram:
Eam!le "#E
,uild a VI that "ould allo" the input of a value from 1 to +1 and return the anle in derees
correspondin to the inverse sine and inverse cosine of the input value.
+he WhileFloo! is a structure in LabVIEW that depends on the mode it is run, "ill do the follo"in:
a. execute a code and stop "hen a certain condition is met! or
b. execute a code as lon as a certain condition is bein met.
Ciure 1.1? sho"s the WhileFloo! and the iteration and condition terminals. +he iteration terminal is an
output node that %eeps trac% of the number of times the WhileFloo! has executed. +he condition terminal is
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 23
an input node that re.uires the necessar# conditions to terminate the execution of the VI. It has t"o modes:
Sto! i1 True and Continue i1 True. +he node re.uires a ,oolean input, and dependin on the mode, does
one of the t"o thins as stated before.
Figure 1. 1%. The While0loop with the terminals shown.
Figure 1. 1&. The two mo!es of the con!ition terminal of the While0loop.
2ata can be communicated in, out and around the loop usin tunnels and shift reisters. +unnels allo" the
passae of data in and out of the WhileFloo!. Ciure 1.1G sho"s an input node passin a scalar data into
the loop. +unnels are automaticall# made "hen nodes outside the WhileFloo! are connected to the nodes
inside the WhileFloo!.
Figure 1. 1*. 5on0in!e3e! !ata tunnel in While0loop.
+unnels are to be discussed in detail on the next article. Cor no", it is sufficient to %no" that the input
tunnel 0a tunnel "hich inputs data into the "hile loop1 and the output tunnel 0a tunnel "hich passes data
from the "hile loop to another node outside1 are non&indexed b# default in WhileFloo!.
+he shift reister stores the result of the current iteration and passes it to the next iteration for use. 9hift
reister comes in pair, that is, an output shift reister is paired "ith an input shift reister. +he shift reister
can have an initial value b# passin a data into the input shift reister. +his initial value is the value used b#
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 24
the WhileFloo! in its first iteration of calculation. If the value of the shift reister is not initiali/ed, it uses the
value stored in the output shift reister carried out from the previous execution of the VI as the initial value.
Ciure 1.1H sho"s the WhileFloo! "ith a shift reister. +o add a shift reister to a WhileFloo!, riht&clic%
on the ede of the WhileFloo! then choose A&& Shi1t -egister#
Figure 1. 1/. While0loop with a shift register.
+he "hile loop structure, as "ell as other execution structures in LabVIEW "ill be discussed in more detail
in future topics! for no", "e cover the basic thins one must %no" "hen usin a WhileFloo!. +he next
example uses a WhileFloo! to implement a numerical solution called the Ee"ton&Daphson method.
Eam!le "#G
@iven the follo"in e.uations for a catenar#
s = a sinh
L
a
"here s is half of the rope lenth a is the parameter related to the mass of the rope and the acceleration
due to ravit#, and L is half the distance of the posts supportin the rope. +he sa of the rope is iven as
u = a _cosh
L
a
1]
@iven s = S8.7S and L = Su, find u usin LabVIEW.
Catenary#)i
Cront panel:
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 25
,loc% diaram:
Eam!le "#".
$se the statistical functions of LabVIEW to enerate the follo"in
a. an arra# of 1uu uniforml# distributed random numbers bet"een u and 1.
b. an arra# of 1uu uniforml# distributed random numbers bet"een 1 and 1.
c. an arra# of 1uu normall# distributed random numbers.
d. an arra# of 1uu normall# distributed random numbers "ith a mean of 2.8 and a standard deviation
of 2.S.
In all of the cases, find the mean, standard deviation, variance, s%e"ness and root mean s.uare 0D*91,
and then usin the $istogram#)i, plot the historams of each set of random numbers.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 26
-an&om#)i
Cront panel:
,loc% diaram:
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 27
Eam!le "#""
+he front panel of #our VI for the .uadratic e.uation solver 0Cua&raticE@uationSol)er#)i, drill problem 1.:
item number 11 miht loo%ed somethin li%e the one belo", "ith four indicators, since #ou are not allo"ed
to use complex functions.
+his time, use onl# t"o indicators and use complex functions to build Cua&raticE@uationSol)er/#)i, "ith
the front panel loo%in li%e the one belo":
-int: 9et the indicators to displa# numbers usin complex double precision floatin&point format.
0rill Problems "#:
1. $sin the Euler5s formula, the trionometric and h#perbolic functions for the complex number z = x +
jy can be established, and "ill sho" that the t"o functions are actuall# related thru the complex
number. 2erive a formula to find the follo"in: sinh(x +jy) ! cosh(x + jy) ! sin(x + jy) and
cos(x + jy), and then create a VI that "ould numericall# prove #our derivations. Eame the VI as
TrigAn&$y!#)i.
7. 2e *oivre5s theorem is a formula that is useful in findin the po"er and roots of complex numbers. It is
stated as
z
n
= (x + jy)
n
= |i(cos + j sin )]
n
= i
n
(cos n + j sinn)
Cor fractional n, the riht&hand side expression is multivalued and becomes
z
1n
= (x + jy)
1n
= |i(cos +j sin)]
1n
= i
1n
_cos
+ 2k
n
+ j sin
+ 2k
n
]
"here k = u,1,2 .n 1. ,uild a VI that computes the fourth root of a complex number. +he user is
allo"ed to input numbers: the real part and the imainar# part of the complex number z. +he VI must
solve the four roots of the number z, in complex number form. Implement the VI in t"o "a#s:
a. usin trionometric functions 0name the VI as 0e5oi)reTrig#)i1, and
b. usin complex number functions 0name the VI as 0e5oi)reCom!le#)i1
:. +he +a#lor series expansion for the h#perbolic sine function is iven as
sinh x = x +
x
3
S!
+
x
5
S!
+
x
7
7!
+ =
x
2n+1
(2n + 1)!
n=0
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 28
"hile for the h#perbolic cosine is
cosh x = 1 +
x
2
2!
+
x
4
4!
+
x
6
6!
+ =
x
2n
(2n)!
n=0
"here n is the number of terms to be added to the series. 'reate a VI that "ould compute the sum of
the first ten terms of the +a#lor series expansion for the h#perbolic sine and h#perbolic cosine of an
input x, callin this VI as $y!Taylor#)i $se WhileFloo!, and follo" the follo"in steps:
1. Input x.
7. Cor the first iteration 0i = u1, compute the first term of the series.
:. 9tore the first term into the shift reister.
<. Cor the second iteration 0i = 11, compute the second term of the series. Add this to the first term
stored in the shift reister and save their sum into the shift reister.
=. Depeat step < until the number of iterations reaches 1u 0i = 91.
?. 2ispla# the sum.
Cor comparison, compute the h#perbolic sine and h#perbolic cosine. Eotice that as x ro"s larer, the
discrepanc# bet"een the +a#lor series enerated and the function enerated values ro"s larer.
<. 9imulate the follo"in random events b# creatin a VI :
a. +ossin of coins. +he output should either be a J-eadK or a J+ailK. 'all the VI as TossCoin#)i.
b. +ossin of a dice. +he output should be an inteer number from 1 to 6. 'all the VI as 0ice.)i.
c. 9electin six numbers out of SS numbers from 1 to SS. +he output is an arra# of six numbers, li%e
pic%in six numbers to place a bet on the lotter#. 'all the VI as Lotto?;;#)i. Eote that the VI miht
return repeated numbers in an arra#. +his "ill be o%a# for no".
=. 2etermine the lo"est positive root of f(x) = 8e
-x
sin(x) 1
a. usin Ee"ton&Daphson method.
b. usin fixed&point iteration. $se the fixed&point iteration formula x
I+1
= x
I
+ 8e
-x
sin(x
I
) 1.
2etermine the root correct to three decimal places. Also, determine ho" man# iterations are re.uired
for each method. Which method arrives at the ans"er faster?
Sel1 Assessment3 Date #our level of achievement for the follo"in outcomes:
Outcome
Can4t &o
+.,
5arginal
Per1ormance
+",
Acce!table
Per1ormance
+/,
Ece!tional
Per1ormance
+6,
$se LabVIEW5s different elementar# math,
statistical and complex number functions
$se "hile loops "ith shift reister and
tunnels "ith different modes
Write #our o"n thouhts and reflections on this topic.
1.=. *atrices and arra#s in LabVIEW
At the end of this lesson, the student shall be able to:
a. understand ho" LabVIEW roups data into a sinle container!
b. enerate arra#s and matrices usin WhileFloo! and %orFloo!! and
c. operate and manipulate matrices and arra#s.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 29
LabVIEW provides three "a#s to roup data:
'luster F a cluster is a roupin of potentiall# different data t#pes! for example, information about
an individual that includes:
o Eame 0strin1
o ,irthdate 0dateItime1
o Ae 0inteer numeric1
o -eiht and "eiht 0floatin&point numeric1
o ;hotoraph 0imae1
can be stored on a sinle container called a cluster. We "ill deal "ith clusters later on.
Arra# F an arra# is a roup of data "ith the same data t#pe. Arra#s can have as man# dimensions.
+he list of scores in a .ui/ of a class of Su is a one&dimensional arra# 0can be a ro" vector or a
column vector1. If the list contains not onl# the scores of a particular class, but of all classes "ho
too% the same .ui/, the list is a t"o&dimensional arra#.
*atrix F a matrix is a t"o&dimensional arra# "hich onl# contains numeric data. A t"o&dimensional
arra# "hose elements are all numeric can be considered a matrix, ho"ever, LabVIEW
differentiates the t"o b# havin arra# operations and matrix math operations. Cor most cases, both
operations have the same meanin and hence can be used interchaneabl#.
In this chapter, "e "ill deal mostl# "ith arra# manipulations and operations, "hich also appl# to matrix
manipulations and operations. We "ill 4ust mention specific cases "hen needed.
Eam!le "#"/
'reate an arra# control, a matrix control, an arra# indicator and a matrix indicator in the front panel.
+he next example sho"s ho" a WhileFloo! can be used to create a t"o&dimensional arra#.
Eam!le "#"6
0a1 ,uild a 1u S t"o&dimensional arra# "hose elements are uniforml# distributed random numbers
bet"een u and Su rounded off as inteers.
0b1 ,uild a S 1u t"o&dimensional arra# "hose elements are uniforml# distributed random numbers
bet"een u and Su rounded off as inteers.
0c1 9ho" ho" the number of columns and ro"s of the t"o&dimensional arra# can be controlled b# the user.
$se WhileFloo!s in 0a1 and 0b1.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 30
ArrayHsingWhile#)i
Cront panel:
,loc% 2iaram:
Another structure that can be used in the eneration of arra#s is the %orFloo!. +he %orFloo! executes the
code inside the structure for a number of times. A condition can also stop a %orFloo! from runnin b#
insertin a condition terminal inside a %orFloo!. +he %orFloo! stops "hen this condition is met, or "hen
the number of iterations has been reached, "hichever comes first.
2ata in and out of the %orFloo! can also be transferred via data tunnels. +hese tunnels are basicall# the
same as that of WhileFloo!. +he basic difference onl# is that the default tunnel mode for WhileFloo! is the
latest value, "hile that for the %orFloo!, the default is indexin.
Eam!le "#":
0a1 ,uild a 1u S t"o&dimensional arra# "hose elements are uniforml# distributed random numbers
bet"een u and Su rounded off as inteers.
0b1 ,uild a S 1u t"o&dimensional arra# "hose elements are uniforml# distributed random numbers
bet"een u and Su rounded off as inteers.
0c1 9ho" ho" the number of columns and ro"s of the t"o&dimensional arra# can be controlled b# the user.
$se %orFloo!s in 0a1 and 0b1.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 31
ArrayHsing%or#)i
Cront ;anel:
,loc% 2iaram:
Another mode for the tunnel is the concatenatin mode, "hich concatenates the recentl# enerated arra#
into the previousl# enerated arra#. +he use of such mode can be demonstrated usin the follo"in
example.
Eam!le "#";
@iven an arra# |
1 2 S 4
], produce the follo"in arra#s:
0a1 _
1 2 S 4
1 2 S 4
1 2 S 4
_
0b1 |
1 2 S 4 1 2 S 4 1 2 S 4
]
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 32
In&eingVsConcatenating#)i
Cront panel:
,loc% diaram:
O!erations on arrays an& matrices# Arra#s and matrices can be operated on arithmeticall# 4ust li%e
scalars.
Eam!le "#"?
+hrouh an example VI, sho" ho" arithmetic operations "or% for scalars and arra#s.
A&&ingArrays#)i
Cront panel:
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 33
,loc% diaram:
*atrices enerall# follo" the same rules as that of arra# operation, except for multiplication and division.
Eam!le "#"A
+hrouh a VI, demonstrate the difference bet"een arra# multiplication and matrix multiplication.
Array5ultVs5atri5ult#)i
Cront panel:
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 34
,loc% diaram:
Eam!le "#"E
De&implement the VI for computin the standard deviation, improvin "hat St&0e)"#)i and St&0e)/#)i can
do. +his time, St&0e)6#)i should be able to compute the standard deviation for an# number of data.
St&0e)6#)i
Cront panel
,loc% 2iaram
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 35
Array 5ani!ulation# LabVIEW provides various functions to manipulate arra#s. Ciure 1.78 sho"s the
Arra# palette "hich contains functions for arra# manipulation.
Figure 1. 20. The 4rra( 6alette.
Eam!le "#"G
@iven the follo"in arra#s,
do the follo"in:
0a1 2etermine the si/e of an# one of these arra#s.
0b1 'reate a 72 arra# "hose elements of the first, second and third ro"s are the elements of "0 Array ",
"0 Array /, and "0 Array 6, respectivel#. 2etermine the si/e of this 72 Arra#.
0c1 'reate a 72 arra# "hose elements of the first, second and third columns are the elements of "0 Array
", "0 Array /, and "0 Array 6, respectivel#. 2etermine the si/e of this 72 Arra#.
0d1 Extract the fourth, sixth and tenth element of "0 Array ".
0e1 Extract the elements at the fifth ro" of /0 Array in 0b1. Also, extract the elements of the second column
of /0 Array.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 36
0f1 Extract a >&b#&7 arra# from /0 Array startin from the second ro", first column element.
01 'reate a =&b#&? arra# from /0 Array.
0h1 2etermine the maximum and minimum values of /0 Array as "ell as their positions.
5ani!ulatingArrays#)i
Cront panel:
,loc% diaram:
*atrices can also be manipulated usin functions under the 5atri palette. +he students are expected to
tr# on these functions and see ho" the# "or%.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 37
As an application, "e tr# to implement the matrix multiplication via arra#s. Demember that arra#
multiplication is different from matrix multiplication in the sense that the latter has more rules. +he matrix
product of t"o matrices A and B "hose si/es are m n and n p respectivel# is the expression
(AB)
Ij
= A
Ik
B
kj
m
k=1
+he follo"in example implements matrix multiplication usin arra#s.
Eam!le "#/.
Implement an alorithm for matrix multiplication usin arra#s onl#. +hen find the matrix product of the
matrices
A = _
8 1 6
S S 7
4 9 2
_ and B = _
1 1 1
1 2 S
1 S 6
_
5atri5ulti!licationViaArrays#)i
Cront panel
,loc% diaram
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 38
0rill Problems "#;
1. -o" does LabVIEW roup data? 9ho" ho" each data roups are made usin a VI called
0ata<rou!s#)i
7. 'reate a VI that "ould perform arithmetic operations 0add, subtract, multipl# and divide1, as "ell as
mathematical functions 0trionometric, exponential, h#perbolic1 and statistical functions to matrices and
arra#s. 2esin #our front panel as if it "ill loo% li%e a scientific calculator for arra#s and matrices. It
"ould be ood if the user is informed "hether an operation is invalid and "h#. 'reate separate VIs for
arra#s 0ArrayCalculator#)i1 and matrices 05atriCalculator#)i1
:. 'reate #our o"n reshape alorithm that reshapes a iven 72 arra# into another arra# "hose si/e is to
be specified b# the user. Decall that the reshape function of LabVIEW reshapes an arra# thru ro"&"ise
re&arranement of elements. Bour reshape function should do this column&"ise. $se WhileFloo!
0-esha!eHsingWhile#)i1 and %orFloo! 0-esha!eHsing%or#)i1.
<. +"o more commonl# done operations on matrices, specificall# on s.uare matrices, are findin
determinants and findin the inverse. $sin arra#s, create a VI that "ould evaluate the determinant of
a 72 s.uare arra# as user input! call this VI as 0eterminants#)i. 'reate a separate VI "hich "ill
evaluate the inverse of a 72 s.uare arra# of numeric data usin co&factors and expansion b# minors!
call the VI as In)erse5atri#)i. 'hec% #our results usin matrices and matrix functions 0%unctions 77
5athematics 77 Linear Algebra1
=. @auss and @auss&)ordan elimination are alorithms "hich reduces a matrix into an upper trianular
matrix and identit# matrix respectivel#. Implement the t"o alorithms in LabVIEW 0<aussElims#)i and
<aussIor&anElims#)i1 usin matrices.
Sel1 Assessment3 Date #our level of achievement for the follo"in outcomes:
Outcome
Can4t &o
+.,
5arginal
Per1ormance
+",
Acce!table
Per1ormance
+/,
Ece!tional
Per1ormance
+6,
$nderstand ho" LabVIEW roups data into
a sinle container!
@enerate arra#s and matrices usin WhileF
loo! and %orFloo!! and
6perate and manipulate matrices and
arra#s.
Write #our o"n thouhts and reflections on this topic.
1.? @raphin in LabVIEW
At the end of this lesson, the student shall be able to:
a. understand the difference bet"een LabVIEW5s chart and raph!
b. displa# data and "aveforms into a chart or raph! and
c. confiure charts and raphs suitable for presentin data.
LabVIEW provides a number of chartin and raphin options for producin data plots. +he table belo"
summari/es the most commonl# used chart and raph t#pes in LabVIEW.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 39
Table 1. 3. #ost commonl( use! charting an! graphing t(pes in LabVIEW.
+hese chart and raph indicators are available on the controls palette.
Waveform chart and "aveform raphs differ b# the manner the# can displa# and update data.
A *a)e1orm chart remembers and displa#s a certain number of points b# storin these points in a buffer.
When the buffer ets full, the chart starts over"ritin the old values "ith the ne" ones. When ne" data
points become available, the# are appended to the old ones. Waveform charts are used to displa# real&time
data points, thouh it also accepts arra#s and displa#s the points all at once.
A *a)e1orm gra!h ho"ever, accepts arra# as an input and displa#s these as data points all at once. It
does not accept sinle value points. It is assumed that the points in the arra# are e.uall# spaced "hen the#
are accepted as an input to a "aveform raph.
+he follo"in example illustrates the difference bet"een a "aveform chart and a "aveform raph.
Eam!le "#/"
;lot the function y = sinx for u x 2 usin a "aveform chart and a "aveform raph.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 40
ChartVs<ra!h#)i
Cront panel:
,loc% diaram
A "aveform chart has three update modes
9trip 'hart: +his mode has a scrollin displa# that is similar to a paper tape strip chart recorder.
+his mode first plots values from left to riht. Crom here, it continues to plot ne" points at the
rihtmost point and shifts old values to the left.
9cope 'hart: +his mode has a retracin displa# similar to an oscilloscope. As it receives each ne"
value, it plots the value to the riht of the last value. When the plot reaches the riht border of the
plottin area, it erases the plot and beins plottin aain from the left border.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 41
9"eep 'hart: +his mode acts much li%e the scope chart, but the plot is not erased "hen the plot
hits the riht border. Instead, a movin vertical line mar%s the beinnin of ne" data and moves
across the displa# from left to riht as it adds ne" data.
Eam!le "#//
Explore the difference bet"een the three update modes of "aveform chart.
+he "aveform chart and the "aveform raph can be confiured usin the Pro!erties dialo box.
Eam!le "#/6
9ho" ho" charts and raphs can be confiured usin the Pro!erties dialo box.
Con1iguringChartAn&<ra!h#)i
Cront panel:
Eam!le "#/:
;lot the sine "ave y = sinx and the cosine "ave y = cos x for u x 2 on the same "aveform
chart and raph.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 42
5ulti!lePlots#)i
Cront panel
,loc% diaram:
In the foreoin discussions, the data plotted mostl# are time&based data, that is, the x&axis "as dedicated
to time. +his is not reall# the case ho"ever. Cor "aveform charts and "aveform raphs, "e assume that
the variable in x&axis is e.uall# spaced. 9o if #ou are to plot a data, not necessaril# time&based data, but
the data points are enerated "ith e.ual spacin, "aveform charts and "aveform raphs provide a ood
"a# to plot these data points. Cor une.uall# spaced x&axis, JK <ra!hs can be used.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 43
Eam!le "#/:
;lot the pol#nomial f(x) = A + Bx + Cx
2
+Bx
3
"ith A = 4, B = S.7, C = 1.9 and B = u.17 for
the follo"in 12 arra#s of x.
a. u x 9
b. x = |
u 1.u 2.7 S.u 4.2 S.u 6.S 7.S 8.1 9.u
]
PlottingHsingJK<ra!h#)i
Cront panel
,loc% diaram
Eam!le "#/;
$se raphical method to find the approximate roots of the e.uation x
3
9.4x
2
+ 22.9Sx 1u.6u2 =
u. +he roots of this e.uation are the values of x "hich satisf# the e.uation. Eote that since the deree of
the pol#nomial in the e.uation is S, there "ill be three roots.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 44
%in&ing-oots<ra!hically#)i
Cront panel
,loc% diaram
LabVIEW also has tools for plottin in three dimensional. In the first example, a surface plot is enerated
usin parametric values.
Eam!le "#/?
'reate a surface plot for a torus. A torus is a rin "ith t"o parameters: the distance bet"een the center of
the torus to the center of the tube R, and the radius of the tube i, as sho"n in the fiure belo".
With these definitions, the torus is defined b# the follo"in e.uations:
x = (R + i cos u) cos v
y = (R + i cos u) sinv
z = i sinv
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 45
"here u and v are parameters "ith rane from u up to 2. +he Cor R = 1u and i = 2, and usinSu data
points for u and v, plot a torus in LabVIEW.
PlottingATorus#)i
Cront panel
,loc% diaram
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 46
0rill Problems "#?
1. 0a1 @enerate a @aussian distributed random number "ith a mean of 1u and a standard deviation of 2.
Bour VI "ould onl# stop eneratin a random number "hen a Sto! button is pressed. +he VI should
onl# enerate 1uu data points per second. ;lot the random numbers as the# are enerated and after
pressin the Sto! button. Eame the VI as WhiteNoise#)i.
0b1 A movin averae filter is a %ind of filter "hich aims to smoothen out variations in sinals. It "or%s in
the follo"in manner: the current value and a number of previous values are averaed to enerate a
ne" value. +he number of values to be enerated depends on the "indo" si/e of the filter. If for
example, the "indo" si/e is 1u, then the current value plus 9 previous values of the input sinal are
averaed. With this, create a movin averae filter for the input sinal enerated in part 0a1. +he
"indo" si/e of the movin averae filter is S. ;lot the input sinal and the filtered sinal on the same
set of axes. +he VI should stop "hen a Sto! button is pressed. 'all this VI as the
5o)ingA)erage%ilter#)i. 0Hint: Use shift registers.1
0+here is a video called WhiteNoise#*m) and 5o)ingA)erage%ilter#*m) "hich demonstrates ho"
these VIs should "or%.1
7. Cor a set of correlated data, a straiht line that best fits the data is iven as y = a
1
x + a
0
, "here
a
1
=
n_x
-_x
_y
n_x
2
-(_x
)
2
and a
0
= y a
I
x 0x and y are the means of x and y respectivel#1. @iven the
data belo" "hich tries to determine if there is a relationship bet"een the lenth of the tail 0TLength1
of a fox in inches to the "eiht 0Weight1 of the fox in pounds.
Cor these data, build a VI to do the follo"in:
a. ;lot the data in a raph. Eote that as this point, there is no relationship bet"een the t"o sets of
data and therefore, the data points should not be connected in an# "a#.
b. $sin the VI, compute the line that best fits the t"o data sets, "ith the tail lenth the independent
variable and the "eiht as the dependent variable.
c. ;lot the best fit line into the same axes as that of the plot in 0a1 "ith x bet"een u and SS.
d. @raphicall# determine the approximate "eiht in pounds of the fox if the tail lenth is 0i1 S in! 0ii1
12 in! 0iii1 18 in! 0iv1 22 in and 0v1 Su in. 9ave these values in an arra# indicator.
e. 2oes the line ma%e sense? Wh# or "h# not? ;ut #our ans"er here as an annotation to #our VI.
'all the VI as Best%itLine#)i
:. 'reate a VI that "ould plot the follo"in functions into a chart and a raph: the exponential function
y = e
x
, the loarithmic function y = lnx, h#perbolic cosine function y = cosh x and the cosine
function y = cos x for u x S. 'hoose appropriate spacin to ensure smooth plot. 'hoose the
appropriate scalin for the x and y axes so that the user "ill have an idea on ho" the function behaves
as x ets larer. *a%e sure also that the user "ill be able to discern "hich plot is "hich. Cinall#, choose
"hich is the better tool to plot such functions so that the user "ill be able to use the plots for better
understandin of the behavior of the function. 'all this VI as %unctionPlotter#)i.
Fundamentals of LabVIEW Programming
Basic LabVIEW Concepts Page 47
<. +he PlottingATorus#)i in the example used *ath9cript node to enerate the needed arra#s. 9ho"
ho" the nodes and structures of LabVIEW can be used to accomplish such tas%. *a%e the VI
interactive too, that is the user can specif# the value of R and i, as "ell as the spacin for the
parameters u and v. +a%e note that as a re.uirement R > i or the torus "ill not be the familiar torus.
Interate this into the VI so that "hen the user enters a value of R and i such that R i, the arra#s
"ill return empt#. 'all the VI as PlottingATorus/#)i
=. 9ho" ho" the follo"in functions can be plotted as a surface for S x, y S:
a. f(x, y) = sinc x
2
+ y
2
! +he sinc x function is e.ual to the expression sinx x.
b. f(x, y) = exp(x
2
y
2
).
c. f(x, y) = (cos x)(siny)
d. f(x, y) = ln (x
2
+y
2
)
e. f(x, y) = sinh x + cosh y
'all the VI as Sur1acePlots#)i.