You are on page 1of 47

Fundamentals of LabVIEW Programming

BASIC LABVIEW CONCEPTS


1.1 What is LabVIEW?
At the end of this lesson, the student shall be able to:
a. explain the concept of virtual instrumentation and graphical programming; and
b. understand the uses and capabilities of LabVIEW.
LabVIEW is the short name for Laboratory Virtual Instrument Engineering Workbench. It is a
programming environment in which you create programs using a graphical notation. Unlike the traditional
text-based programming languages, like C, C++, Java, or MATLAB, you program in LabVIEW graphically,
that is functions are represented as nodes with inputs and outputs, and are wired through which data flows.
Being a programming language, LabVIEW can be used to develop applications similar to what can be
developed using text-based programming language. However, more than being a programming language,
LabVIEW can be used to do the following:

acquire data from instruments or generate data using signal generation functions;
analyze data;
process data (e.g. filtering, transforms, etc.); and
control instruments and equipment.

Engineers and scientists use LabVIEW to bring information from the outside world into a computer using
data acquisition (DAQ) devices, process these data, and present these data to the user. Thus, LabVIEW
can be used to create virtual instruments (VI).
A virtual instrument is a computer program that imitates the functionality of the real-world physical
instrument. These virtual instruments can also take in external data and do something about these data,
just as how a standard instrument will work. These VIs however has the inherent advantage of being
flexible in terms of its use. Being virtual, these instruments functionalities are being programmed, and
hence can be changed whenever wanted and needed. In most cases, virtual instrumentation also results to
lower costs, as a single set of hardware (a DAQ device, a computer, and a software) can be configured to
perform many instrumentation tasks that require multiple physical instruments.
A LabVIEW program is also called a virtual instrument or VI.
Moreover, LabVIEW can also be used to simulate processes and control external instruments and
equipment. Thus, LabVIEW is very useful in the field of instrumentation and control.
Example 1.1
1. Open LabVIEW 2012 (via the desktop shortcut or the Start menu) and on the opening window, click
Help and choose Find Examples.
2. On the NI Example Finder window, choose the Search tab, type in Simulation Tank Level in the
Enter keyword(s) field and click Search. The Simulation Tank Level.vi must appear at the results
Basic LabVIEW Concepts

Page 1

Fundamentals of LabVIEW Programming


3.
4.

5.

6.
7.

field. Double click it to open the VI.


Press the white arrow icon (the Run icon) on the VI to run the VI.
Click the HV102 valve to make it black and the LCV101 to make it green. This step basically opens an
input valve to let fluid flow into the tank (the green valve) and a drain valve (the black valve) to drain
fluid out of the tank. The tank has an inherent slow leak drain.
The objective of the control of the system is to keep the level of the fluid inside the tank (the process
variable PV) the same as the Setpoint (SP). The degree by which the controller reacts is indicated by
the value of the Output (the greater the difference between the PV and SV, the greater the output of
the controller). Thus, when you change the value of the setpoint, the level of the tank should follow
through (try changing the setpoint from 50 to 10 and from 10 to 70; observe how the output of the
controller changes with these).
Turn off the HV102 valve and change the setpoint from 70 down to 40. Observe how the PV value
changes as compared how it changed in the previous step.
Play around with the other parameters of the VI (like the PID parameters) and observe how the PV
changes with the changes in setpoint.

LabVIEW uses a very powerful graphical programming language which most LabVIEW users refer to as G
for graphical (the term is in reference to the C programming language). Programs are created in pictorial
form called a block diagram. One advantage it offers is that the developer does not need to know
syntactical details associated with text-based programming languages. The developer just needs to
connect functional nodes and how data flows from one node to another. However, those that are used to
working with text-based languages may need time to adjust to LabVIEWs style of programming (a personal
experience!).
Example 1.2
When you opened the Simulation Tank Level.vi, the front panel (or FP) appeared. To display the
source code or the block diagram (BD), press Ctrl+E. You need not know how does this BD works at this
point, but you can examine the composition of this BD by turning on the Context Help (via Ctrl+H), and
then hovering the mouse over the icons.
1. Find out what functional nodes do this BD contain.
2. What does the gray line that bounds the blocks represent?
Stop the VI by pressing the Abort execution icon on either the FP or the BD.
Drill Problems 1.1
1. Discuss what is meant by virtual instrumentation and how LabVIEW facilitates development of virtual
instruments. What are the advantages and disadvantages of using virtual instruments?
2. Explain what graphical programming is and how it accelerates development of systems.
3. Enumerate the uses and capabilities of LabVIEW.

Basic LabVIEW Concepts

Page 2

Fundamentals of LabVIEW Programming


Self Assessment: Rate your level of achievement for the following outcomes:
Cant do
Marginal
Acceptable Exceptional
Outcome
Performance Performance Performance
(0)
(1)
(2)
(3)
Explain
the
concept
of
virtual
instrumentation and graphical programming
Understand the uses and capabilities of
LabVIEW.
Write your own thoughts and reflections on this topic.
1.2 The LabVIEW environment
At the end of this lesson, the student shall be able to identify parts of and navigate through the LabVIEW
environment.
When the LabVIEW is opened, a Welcome screen (or the Getting Started window in older versions)
appears, as shown below

Figure 1. 1 The LabVIEW 2012 welcome screen.

To start using LabVIEW, one can either choose to click the Blank VI, click on the File >> New VI menu or
press Ctrl+N to open a new, blank VI. This opens up two windows: the front panel (FP) and the block
diagram (BD), as shown in the figures below:

Basic LabVIEW Concepts

Page 3

Fundamentals of LabVIEW Programming

Figure 1. 2. The front panel.

Figure 1. 3. The block diagram.

Each window contains different set of menus. The menus pop out when you right-click on an empty field in
a window. We first discuss the front panel and its menus.
The front panel is the window through which the user interacts with the program. This is the window where
the user would input into the VI and also where the output is displayed. When you right-click on an empty
field in the front panel, the Controls palette appears as shown in the figure below.
Basic LabVIEW Concepts

Page 4

Fundamentals of LabVIEW Programming

Figure 1. 4. The controls palette with the Modern controls palette selected.

This set of menus contains the controls and indicators for the front panel. In LabVIEW, controls are used
as inputs into the VI, while indicators are used as outputs of the VI. You can pin this menu to the front
panel by clicking the pin icon on the top left corner of the menu. You can unpin it by clicking the close
button at the top right corner of the menu when it is pinned. You can also click View >> Controls Palette
on the menu bar of the front panel so that the controls palette will appear. You can use the Search button
when finding for a front panel object. To get information about a certain object, press Ctrl+H and hover the
mouse over the object you wish to have more information about.
Controls are typically knobs, push buttons, dials, sliders, and strings. Controls simulate instrument input
devices and supply data to the block diagram of the VI. Indicators are typically graphs, charts, LEDs, and
status strings. Indicators simulate instrument output devices and display data the block diagram acquires or
generates.
Example 1.3
Find and place the following objects into the front panel, and find out some information about each.
1. Numerical control and numerical indicator.
2. Horizontal and vertical slide switches.
3. A square LED and round LED.
4. A knob and a dial.
5. A string and a ring control.

Basic LabVIEW Concepts

Page 5

Fundamentals of LabVIEW Programming


6. A string and a file path indicator.
7. A chart and a graph.
Close the VI without saving your work. Then open a new blank VI again.
The figure below shows the menu icons for running and arranging the objects in the front panel.

Figure 1. 5. Menu icons in the front panel.

The figure are labeled as follows:


1. Run button this button causes the VI to run once.
2. Run Continuously button this button causes the VI to run continuously until the Stop or Pause
button is pressed.
3. Abort Execution button this button stops the running of the VI.
4. Pause button this button pauses the running of the VI.
5. Application Font button this pull-down menu displays the options for changing the size, style,
alignment, color and type of font for different fonts used in the VI. The first option causes the Font
Dialog Box to appear.
6. Align Objects button this pull-down menu displays the options for aligning objects in the front
panel with respect to different axes.
7. Distribute Objects button this pull-down menu displays the options for distributing objects, or
setting the spacing in between objects with respect to different axes.
8. Resize Objects button this pull-down menu displays the options for resizing objects.
9. Reorder button this pull-down menu displays the grouping, locking and ordering options for the
objects in the front panel.
10. Search text field and Context Help toggle button you can type in keywords here to search them
in LabVIEW. You can also use this to find objects in the Controls palette and if they exist, you can
directly drag and drop them in the front panel. The Context Help button is a toggle button that
opens and closes the Context Help window.
Example 1.4
Place the following objects in the current front panel: a waveform chart, a dial and a real matrix indicator.
Then try out the different alignment, distribution, resizing and reorder buttons to demonstrate the use of
each. Close the front panel but do not save the VI. Open a new VI.

After you create the front panel window, you add code using graphical representations of functions to
control the front panel objects. The block diagram window contains this graphical source code.
Basic LabVIEW Concepts

Page 6

Fundamentals of LabVIEW Programming


Pressing the Ctrl+E while the front panel is active brings out the block diagram (BD). The block diagram is
where the functionality of the VI is defined thru function nodes and wires connecting these nodes. Block
diagram objects include terminals, subVIs, functions, constants, structures, and wires, which transfer data
among other block diagram objects. Right-clicking on an empty field inside the block diagram causes the
Functions palette to appear, as shown in the figure below.

Figure 1. 6. The Functions palette.

This set of menu contains the functions, VIs and Express VIs. You then connect these nodes with wires so
that data may flow in and out of these nodes.
Objects on the front panel window appear as terminals on the block diagram. Terminals are entry and exit
ports that exchange information between the front panel and block diagram. Terminals are analogous to
parameters and constants in text-based programming languages. Types of terminals include control or
indicator terminals and node terminals.
Example 1.5
1. Place a numeric control and a knob in the front panel. Then observe the corresponding nodes that
have been placed in the block diagram.
2. Place a tank and a waveform chart in the front panel. Observe the difference between the
corresponding nodes of the controls and the indicators in the block diagram.
3. Place a color box control and a round LED indicator on the front panel. What can be said about the
corresponding nodes of the control and the indicator in the block diagram as compared to the first
Basic LabVIEW Concepts

Page 7

Fundamentals of LabVIEW Programming


nodes placed?
4. Connect the knob control node with the tank indicator node and the color box control node with the
waveform chart node in the block diagram. Observe what happens.
5. Connect the numeric control node with the Boolean indicator node. What happens?
6. In the front panel, replace the numeric control with a push button. Observe what happens in the block
diagram.
7. In the front panel, replace the waveform chart with a numeric indicator. What is the difference (in
physical aspect) between the numeric control and the numeric indicator? Observe what also happens
in the block diagram.
You can run the VI continuously and experiment on adjusting the values. Then close the VI without saving
it.
There are two distinguishing characteristics between a control and an indicator terminal on the block
diagram. The first is an arrow on the terminal that indicates the direction of data flow. The controls have
arrows showing the data leaving the terminal, whereas the indicator has an arrow showing the data
entering the terminal. The second distinguishing characteristic is the border around the terminal. Controls
have a thick border and indicators have a thin border.

Figure 1. 7. Control and indicator terminals.

Figure 1.7 shows terminals in icon view. You can view these terminals without an icon by right-clicking on
the terminal icon at the block diagram and unchecking the View As Icon option. You can also automatically
place terminals on the block diagram without an icon by unchecking the Place front panel terminals as
icon option under the General options for the block diagram, which can be accessed via the Tools >>
Options menu and selecting Block Diagram under Category pane of the Options window that pops out.
Node terminals are terminal that do not appear as objects in the front panel, such as a constant.
Colors are used to represent what data types by default the nodes and the wires are carrying. Table 1.1
shows the common data types used in LabVIEW.

Basic LabVIEW Concepts

Page 8

Fundamentals of LabVIEW Programming


Table 1. 1 Common LabVIEW data types. From Larsen, 2012

The common rule of the thumb is that you can only connect nodes of the same color, otherwise, it may
result to a broken wire and a program error. But not all lead to errors. In some cases LabVIEW does some
conversions. This is the case when you have for example, a control node carrying an integer data is
connected to an indicator node carrying a double-precision floating-point number. In such case, the
conversion is indicated by a small red dot at the node, as shown in the figure below

Figure 1. 8. Data type conversion.

You transfer data among block diagram objects through wires. Each wire has a single data source, but you
can wire it to many VIs and functions that read the data. Wires are different colors, styles, and thicknesses,
depending on their data types. Table 1.2 shows different wires and how are they identified depending on
their data type.

Basic LabVIEW Concepts

Page 9

Fundamentals of LabVIEW Programming


Table 1. 2. Wires in LabVIEW. From http://www.ni.com/gettingstarted/labviewbasics/dataflow.htm, retrieved 09-Jan-2014.

Nodes are objects on the block diagram that have inputs and/or outputs and perform operations when a VI
runs. They are analogous to statements, operators, functions, and subroutines in text-based programming
languages. Nodes can be functions, subVIs, Express VIs, or structures. Structures are process control
elements, such as Case structures, For Loops, or While Loops.
Functions are the fundamental operating elements of LabVIEW. The Add and Subtract functions are
examples of function nodes. Functions do not have front panel windows or block diagram windows but do
have connector panes. Double-clicking a function only selects the function. A function has a pale yellow
background on its icon.
After you build a VI, you can use it in another VI. A VI called from the block diagram of another VI is called
a sub-VI. You can reuse a sub-VI in other VIs. To create a sub-VI, you need to build a connector pane and
create an icon. Sub-VIs are to be discussed in the next topic.
Express VIs are nodes that require minimal wiring because you configure them with dialog boxes. Use
Express VIs for common measurement tasks. Express VIs appear on the block diagram as expandable
nodes with icons surrounded by a blue field. Express VIs are to be discussed in a future topic.
The figure below shows the menu icons available for the block diagram.

Figure 1. 9. Menu icons for the block diagram.

The figure is labeled as follows:


1. Run options which are the same as that in the front panel.
2. Debugging tools tools which can be used for debugging the VI.
Highlight execution displays an animation of the block diagram execution when the VI
is run.
Retain wire values saves the wire values at each point in the flow of execution so that
when probes are placed you can immediately retain the most recent value of data that
passed the wire.
Basic LabVIEW Concepts

Page 10

Fundamentals of LabVIEW Programming


Step into causes the execution of a node and then pause after execution.
Step over causes the execution of a node and then pause after the execution of the next
node.
Step out finishes the execution of the entire VI.
3. Application font button which is the same as in the front panel.
4. Options for aligning, distributing, ordering and cleaning the objects in the block diagram.
5. The Search field and the Context Help toggle button which are the same as that in the front panel.

The Tools palette, which is common to both the front panel and block diagram, is shown in the figure
below. The Tools palette contains options for the cursor and is accessible thru the View >> Tools Palette.
You can also press Shift + Left click on an empty FP or BD to display the Tools palette temporarily.

Figure 1. 10. The Tools palette.

The icons in the Tools palette menu are as follows:

Automatic Tool Selection Button this enables the cursor to change automatically as needed in
the block diagram. A green LED lit on indicates that this tool is enabled.
Operate Value Tool (finger) used to push buttons (to toggle a Boolean value, to select a menu
item, etc.
Position / Size / Select Tool (arrow) used to relocate and resize controls.
Edit Text Tool (A with cursor) used to enter text (on labels and string constants).
Connect Wire Tool (spool) used to connect wires between block outputs and inputs.
Object Shortcut Menu Tool (menu icon) opens a pop-up menu of options for controls and
programming blocks, the same as when an object or node is right-clicked.
Scroll Window Tool (cupped hand) used to drag a window (eg. to scroll to a hidden portion of a
large block diagram).
Set / Clear Breakpoint Tool (stop sign) used to set and clear breakpoints in the block diagram
which freezes the execution of the program to enable the programmer to see what is happening
within the program.
Probe Data Tool (probe symbol: yellow circle, arrow, P character) used to place probes in the
block diagram which shows the value in a wire as the program is executed.
Get Color Tool (dropper) used to set the current foreground and background colors

Basic LabVIEW Concepts

Page 11

Fundamentals of LabVIEW Programming


Drill Problems 1.2
1. What are the main windows that pop out when a blank VI is opened? What tasks can you do with each
one?
2. How can objects be found and placed in the front panel and block diagram? Discuss the use of the
following menus: controls palette, functions palette and tools palette.
3. What is the difference between controls and indicators? In the front panel, how can you identify, just by
mere looking at them, if the object is a control or an indicator?
4. How are data types differentiated in LabVIEW? Give an example node that represents each data type
used in LabVIEW.
Self Assessment: Rate your level of achievement for the following outcomes:
Cant do
Marginal
Acceptable Exceptional
Outcome
Performance Performance Performance
(0)
(1)
(2)
(3)
Identify parts of and navigate through the
LabVIEW environment.
Write your own thoughts and reflections on this topic.
1.3 Building the virtual instrument (VI)
At the end of this lesson, the student shall be able to:
a. build virtual instruments using arithmetic and comparison functions in LabVIEW;
b. create a sub-VI out of a portion of, or all of, a VI already made; and
c. debug VIs using different debugging tools.
As an example, we build the following virtual instrument (VI) with the following front panel and block
diagram
Sum&Average1.vi
Front panel:

Block diagram:

Basic LabVIEW Concepts

Page 12

Fundamentals of LabVIEW Programming


and save this as Sum&Average1.vi (File >> Save or File >> Save As). Put values in the Num 1 and Num
2 then click the Run button to test the functionality of the VI.
By clicking the Run button, the VI is run only once. You can use the Run continuously so that the VI
becomes interactive (it updates the results when the inputs are changed). We can make the front panel
display more attractive by using not just numerical controls and indicators. Edit Sum&Average1.vi as
shown below and save this as Sum&Average2.vi
Sum&Average2.vi
Front panel:

Block diagram:

The front panel uses vertical pointer slider as controls and meters as indicators. Take note that the limit of
the Sum meter was changed to 20 because the limits of both the inputs are 10 and therefore the maximum
sum will be 20. In the block diagram, the control and indicator nodes are viewed as simple nodes to
conserve space.
Some instruments have warning indicators in their panels. We can add this up using a round LED (light
emitting diode) that lights up whenever the average of the two numbers reach 9. Edit Sum&Average2.vi
as shown below and save this as Sum&Average3.vi.

Basic LabVIEW Concepts

Page 13

Fundamentals of LabVIEW Programming


Sum&Average3.vi
Front panel:

Block diagram:

In this VI, annotations are added into the block diagram to provide information to the reader of the source
code. Labels are also displayed to the function nodes providing more readability to the block diagram.
Example 1.6
Build the VI AverageGrade.vi. The VI will have a front panel similar to the one below. The VI lists the
mathematics courses that an engineering student will take. The user is allowed to input numerical grades,
assuming that the input of the user will be just between 50 and 100. The VI averages the inputs and
displays the average grade rounded off to the nearest whole number using a gauge. A round LED is lit red
when the average is less than 75, and green when it is 75 or above.

Basic LabVIEW Concepts

Page 14

Fundamentals of LabVIEW Programming

As another example, let us make a VI that would compute the mean, variance and standard deviation for a
set of five numbers. The variance for a population is computed as
=

while the standard deviation for a population is


=

1
N

1
N

where x is the ith data, is the population mean, and N is the number of data (population). To implement
this formula, we do the following steps:
1. Compute the population mean .
2. Subtract the population mean from the data and square their difference. This quantity is called the
squared error (Err ). Find the squared error for all the data.
3. Add all the error squared data. The sum is called the sum of squared error (SSE).
4. Divide the sum of squared error with the number of data. This quantity, which is a mean, is called
the mean squared error (MSE). This is also the variance of the data.
5. Take the square root of the variance. This quantity is now the standard deviation .

The StdDev1.vi shows how the five steps were implemented in LabVIEW.

Basic LabVIEW Concepts

Page 15

Fundamentals of LabVIEW Programming


StdDev1.vi
Front panel:

Block diagram:

The VI is tested by entering test values as shown in figure 1.11.

Figure 1. 11. StdDev1.vi with sample inputs. The output is as expected.

Basic LabVIEW Concepts

Page 16

Fundamentals of LabVIEW Programming


Notice that the averaging part was twice done: first to determine the population mean, and second to
average the squared error terms. A more elegant block diagram can be built if sub-VIs were used. A sub-VI
is a VI that is used as part of a larger VI. Two things are needed to be defined when making sub-VIs:
1. the functionality of the sub-VI; and
2. the input and output ports of this sub-VI.
Optionally, an icon for the sub-VI can be customized. The StdDev2.vi shows the use of such sub-VIs. A VI
named Average.vi was created from the original VI and was twice used. Another VI called the
ErrSquared.vi was also created from the original VI.
StdDev2.vi
Front panel:

Block diagram:

Just like any other programming languages, you may encounter two types of errors or bugs in LabVIEW:
1. those errors or bugs that prevent the VI from running (similar to syntactical errors in text-based
programming languages); and
2. those errors or bugs that cause your VI to generate bad results or incorrect behavior.
In both cases, LabVIEW has tools to help you deal with these errors and bugs.
Basic LabVIEW Concepts

Page 17

Fundamentals of LabVIEW Programming


VIs which does not run is broken or non-executable. This may be caused by any of the following:

The block diagram contains a broken wire because of a mismatch of data types or a loose,
unconnected end.
A required block diagram terminal is unwired.
A subVI is broken or you edited its connector pane after you placed its icon on the block diagram of
the VI.

A VI which cannot be run because of a programming error is indicated by a broken arrow as shown in the
figure 1.12.

Figure 1. 12. A VI with an error.

To know what error has occurred, you can click the broken arrow which will display the error list.

Figure 1. 13. Error list.

Basic LabVIEW Concepts

Page 18

Fundamentals of LabVIEW Programming


The list suggests that the error occurred at the ErrSquared.vi because it is not executable. You can click
the error message under the Block Diagram Errors to highlight the node which contains error/s. Opening
the subVI reveals the following block diagram

Figure 1. 14. The subVI with an error.

which shows that the error is caused by unconnected wires in the subVI. Correct it by making the proper
connections. With now a correct subVI, the VI is now executable. However, testing the VI with the same
sample values as before,

Figure 1. 15. StdDev2.vi with erroneous output.

Basic LabVIEW Concepts

Page 19

Fundamentals of LabVIEW Programming


We can use LabVIEWs debugging tools to troubleshoot this apparently erroneous VI. The following can be
used:
1. Single stepping execution, where the VI is run step by step.
2. Breakpoints which pauses the VI when data passes through and allows the programmer to inspect
the current state of the VI at this point.
One can animate the execution of the VI by clicking the Highlight execution button, and use Probes to
display and monitor the values passing thru a wire while the VI executes.
Example 1.7
The file StdDev2_err.vi contains errors. Use the debugging tools to correct the errors.
Drill Problems 1.3
1. Build a VI that would solve a quadratic equation of the form
ax + bx + c = 0
by using only basic arithmetic operations and comparison operators. Take note that the square root
operations return a NaN (not a number) value when it operates on negative numbers. This should not
be the case with your VI, however. It should be able to return complex numbers, but do not use
functions for complex numbers yet! Call this VI as QuadraticEquationSolver.vi
2. Use the QuadraticEquationSolver.vi to build a VI that would solve a quartic equation of the form
ax + bx + c = 0
calling this as QuarticEquationSolver.vi. Just like in the previous item, the VI should be able to return
complex numbers as answers without using functions for these.
3. Build a VI that would convert a decimal number into a 16-bit binary number, calling this as DecToBin.vi
and another VI that would convert a 16-bit binary number into its decimal form, calling this as
BinToDec.vi
4. Use the VIs built in number 3 to build DecToOct.vi (decimal-to-octal) and OctToDec.vi (octal-todecimal).
5. The VI tscore_err.vi computes the Students t-score for two sets of sampled data. The t-score of two
sets of data indicates whether there is significant difference between the means of the two sets. These
two sets of data can be dependent or independent of each other. The steps to compute the t-score are
the following:
a. Compute the means of the two data sets, calling them x! and x" (we have used the x symbol to
indicate that we are taking the mean of a sample, which says that the data at hand are part of a
larger data which is the most practical case).
b. Compute the sum of the squares of the error for the two sets of data, calling them SSE! and SSE" .
c. Determine the sample variance using the formula
SSE! + SSE"
s =
n! 1 + n" 1
where n is the number of samples for each data set.
d. Determine the standard deviation of the sampling distribution of the sample-mean differences using
the formula

Basic LabVIEW Concepts

Page 20

Fundamentals of LabVIEW Programming


s
s
=% +
n! n"

|x! x" |

Using LabVIEWs debugging tools, troubleshoot the VI which should give the correct t-score for the
following set of fifteen data:
Data set A: 26, 26, 26, 21, 18, 21, 19, 25, 23, 29, 22, 22, 24, 23, 22
Data set B: 18, 20, 20, 26, 17, 23, 20, 16, 21, 18, 21, 29, 20, 25, 19
Self Assessment: Rate your level of achievement for the following outcomes:
Cant do
Marginal
Acceptable Exceptional
Outcome
Performance Performance Performance
(0)
(1)
(2)
(3)
Build virtual instruments using arithmetic
and comparison functions in LabVIEW
Create a sub-VI out of a portion of, or all of,
a VI already made
Debug VIs using different debugging tools
Write your own thoughts and reflections on this topic.
e. The t-score is then computed as

t=

1.4 LabVIEWs mathematical functions


At the end of this lesson, the student shall be able to:
a. use LabVIEWs different elementary math, statistical and complex number functions; and
b. use while loops with shift register and tunnels with different modes.
LabVIEW offers different built-in elementary mathematical, statistical and functions for complex numbers.
The following function groups are found in the Functions >> Mathematics >> Elementary and Special
Functions

Trigonometric: functions such as sin, cos, tan, etc., are under this palette.
Exponential: functions such as exp, ln, log, etc., are under this palette.
Hyperbolic: functions such as sinh, cosh, tanh, etc., are under this palette.

Remember that trigonometric functions accept radians as inputs and inverse trigonometric functions return
angles in radians.
Statistical functions such as measures of central tendencies Mean, Median and Mode are found at the
Functions >> Mathematics >> Probrability and Statistics.
Complex number functions are found at Functions >> Numeric >> Complex. Some of these functions
include Complex Conjugate, Polar to Complex, Complex to Polar, Re/Im to Complex, and so on.
Basic LabVIEW Concepts

Page 21

Fundamentals of LabVIEW Programming


As an example, we build a VI that accepts input of angle in degrees and returns the sine, cosine, tangent,
cosecant, secant and cotangent values for such angle.
Trigo.vi
Front panel:

Block diagram:

Example 1.8
Build a VI that would allow the input of a value from 1 to +1 and return the angle in degrees
corresponding to the inverse sine and inverse cosine of the input value.
The While-loop is a structure in LabVIEW that depends on the mode it is run, will do the following:
a. execute a code and stop when a certain condition is met; or
b. execute a code as long as a certain condition is being met.
Figure 1.16 shows the While-loop and the iteration and condition terminals. The iteration terminal is an
output node that keeps track of the number of times the While-loop has executed. The condition terminal is
Basic LabVIEW Concepts

Page 22

Fundamentals of LabVIEW Programming


an input node that requires the necessary conditions to terminate the execution of the VI. It has two modes:
Stop if True and Continue if True. The node requires a Boolean input, and depending on the mode, does
one of the two things as stated before.

Figure 1. 16. The While-loop with the terminals shown.

Figure 1. 17. The two modes of the condition terminal of the While-loop.

Data can be communicated in, out and around the loop using tunnels and shift registers. Tunnels allow the
passage of data in and out of the While-loop. Figure 1.18 shows an input node passing a scalar data into
the loop. Tunnels are automatically made when nodes outside the While-loop are connected to the nodes
inside the While-loop.

Figure 1. 18. Non-indexed data tunnel in While-loop.

Tunnels are to be discussed in detail on the next article. For now, it is sufficient to know that the input
tunnel (a tunnel which inputs data into the while loop) and the output tunnel (a tunnel which passes data
from the while loop to another node outside) are non-indexed by default in While-loop.
The shift register stores the result of the current iteration and passes it to the next iteration for use. Shift
register comes in pair, that is, an output shift register is paired with an input shift register. The shift register
can have an initial value by passing a data into the input shift register. This initial value is the value used by
Basic LabVIEW Concepts

Page 23

Fundamentals of LabVIEW Programming


the While-loop in its first iteration of calculation. If the value of the shift register is not initialized, it uses the
value stored in the output shift register carried out from the previous execution of the VI as the initial value.
Figure 1.19 shows the While-loop with a shift register. To add a shift register to a While-loop, right-click
on the edge of the While-loop then choose Add Shift Register.

Figure 1. 19. While-loop with a shift register.

The while loop structure, as well as other execution structures in LabVIEW will be discussed in more detail
in future topics; for now, we cover the basic things one must know when using a While-loop. The next
example uses a While-loop to implement a numerical solution called the Newton-Raphson method.
Example 1.9
Given the following equations for a catenary

s = a sinh

L
a

where s is half of the rope length a is the parameter related to the mass of the rope and the acceleration
due to gravity, and L is half the distance of the posts supporting the rope. The sag of the rope is given as
L
d = a 6cosh 18
a
Given s = 58.75 and L = 50, find d using LabVIEW.
Catenary.vi
Front panel:

Basic LabVIEW Concepts

Page 24

Fundamentals of LabVIEW Programming


Block diagram:

Example 1.10
Use the statistical functions of LabVIEW to generate the following
a. an array of 100 uniformly distributed random numbers between 0 and 1.
b. an array of 100 uniformly distributed random numbers between 1 and 1.
c. an array of 100 normally distributed random numbers.
d. an array of 100 normally distributed random numbers with a mean of 2.8 and a standard deviation
of 2.5.
In all of the cases, find the mean, standard deviation, variance, skewness and root mean square (RMS),
and then using the Histogram.vi, plot the histograms of each set of random numbers.

Basic LabVIEW Concepts

Page 25

Fundamentals of LabVIEW Programming


Random.vi
Front panel:

Block diagram:

Basic LabVIEW Concepts

Page 26

Fundamentals of LabVIEW Programming


Example 1.11
The front panel of your VI for the quadratic equation solver (QuadraticEquationSolver.vi, drill problem 1.3
item number 1) might looked something like the one below, with four indicators, since you are not allowed
to use complex functions.

This time, use only two indicators and use complex functions to build QuadraticEquationSolver2.vi, with
the front panel looking like the one below:

Hint: Set the indicators to display numbers using complex double precision floating-point format.
Drill Problems 1.4
1. Using the Eulers formula, the trigonometric and hyperbolic functions for the complex number z = x +
jy can be established, and will show that the two functions are actually related thru the complex
number. Derive a formula to find the following: sinh x + jy ; cosh x + jy ; sin x + jy and
cos x + jy , and then create a VI that would numerically prove your derivations. Name the VI as
TrigAndHyp.vi.
2. De Moivres theorem is a formula that is useful in finding the power and roots of complex numbers. It is
stated as
z = = x + jy = = >r cos + j sin @= = r = cos n + j sin n
For fractional n, the right-hand side expression is multivalued and becomes
+ 2k
+ 2k
+ j sin
8
z /= = x + jy /= = >r cos + j sin @ /= = r /= 6cos
n
n
where k = 0,1,2 n 1. Build a VI that computes the fourth root of a complex number. The user is
allowed to input numbers: the real part and the imaginary part of the complex number z. The VI must
solve the four roots of the number z, in complex number form. Implement the VI in two ways:
a. using trigonometric functions (name the VI as DeMoivreTrig.vi), and
b. using complex number functions (name the VI as DeMoivreComplex.vi)
3. The Taylor series expansion for the hyperbolic sine function is given as
K
xE xG xH
x =J
sinh x = x + + + + =
3! 5! 7!
2n + 1 !
= L

Basic LabVIEW Concepts

Page 27

Fundamentals of LabVIEW Programming


x
x
xM
cosh x = 1 + + + + =
2! 4! 6!

while for the hyperbolic cosine is

= L

x =
2n !

where n is the number of terms to be added to the series. Create a VI that would compute the sum of
the first ten terms of the Taylor series expansion for the hyperbolic sine and hyperbolic cosine of an
input x, calling this VI as HypTaylor.vi Use While-loop, and follow the following steps:
1. Input x.
2. For the first iteration (i = 0), compute the first term of the series.
3. Store the first term into the shift register.
4. For the second iteration (i = 1), compute the second term of the series. Add this to the first term
stored in the shift register and save their sum into the shift register.
5. Repeat step 4 until the number of iterations reaches 10 (i = 9).
6. Display the sum.
For comparison, compute the hyperbolic sine and hyperbolic cosine. Notice that as x grows larger, the
discrepancy between the Taylor series generated and the function generated values grows larger.
4. Simulate the following random events by creating a VI :
a. Tossing of coins. The output should either be a Head or a Tail. Call the VI as TossCoin.vi.
b. Tossing of a dice. The output should be an integer number from 1 to 6. Call the VI as Dice.vi.
c. Selecting six numbers out of 55 numbers from 1 to 55. The output is an array of six numbers, like
picking six numbers to place a bet on the lottery. Call the VI as Lotto655.vi. Note that the VI might
return repeated numbers in an array. This will be okay for now.
5. Determine the lowest positive root of f x = 8eOP sin x 1
a. using Newton-Raphson method.
b. using fixed-point iteration. Use the fixed-point iteration formula x J = x + 8eOPQ sin x 1.
Determine the root correct to three decimal places. Also, determine how many iterations are required
for each method. Which method arrives at the answer faster?
Self Assessment: Rate your level of achievement for the following outcomes:
Cant do
Marginal
Acceptable Exceptional
Outcome
Performance Performance Performance
(0)
(1)
(2)
(3)
Use LabVIEWs different elementary math,
statistical and complex number functions
Use while loops with shift register and
tunnels with different modes
Write your own thoughts and reflections on this topic.
1.5. Matrices and arrays in LabVIEW
At the end of this lesson, the student shall be able to:
a. understand how LabVIEW groups data into a single container;
b. generate arrays and matrices using While-loop and For-loop; and
c. operate and manipulate matrices and arrays.

Basic LabVIEW Concepts

Page 28

Fundamentals of LabVIEW Programming


LabVIEW provides three ways to group data:

Cluster a cluster is a grouping of potentially different data types; for example, information about
an individual that includes:
o Name (string)
o Birthdate (date/time)
o Age (integer numeric)
o Height and weight (floating-point numeric)
o Photograph (image)
can be stored on a single container called a cluster. We will deal with clusters later on.
Array an array is a group of data with the same data type. Arrays can have as many dimensions.
The list of scores in a quiz of a class of 30 is a one-dimensional array (can be a row vector or a
column vector). If the list contains not only the scores of a particular class, but of all classes who
took the same quiz, the list is a two-dimensional array.
Matrix a matrix is a two-dimensional array which only contains numeric data. A two-dimensional
array whose elements are all numeric can be considered a matrix, however, LabVIEW
differentiates the two by having array operations and matrix math operations. For most cases, both
operations have the same meaning and hence can be used interchangeably.

In this chapter, we will deal mostly with array manipulations and operations, which also apply to matrix
manipulations and operations. We will just mention specific cases when needed.
Example 1.12
Create an array control, a matrix control, an array indicator and a matrix indicator in the front panel.
The next example shows how a While-loop can be used to create a two-dimensional array.
Example 1.13
(a) Build a 10 5 two-dimensional array whose elements are uniformly distributed random numbers
between 0 and 30 rounded off as integers.
(b) Build a 5 10 two-dimensional array whose elements are uniformly distributed random numbers
between 0 and 30 rounded off as integers.
(c) Show how the number of columns and rows of the two-dimensional array can be controlled by the user.
Use While-loops in (a) and (b).

Basic LabVIEW Concepts

Page 29

Fundamentals of LabVIEW Programming


ArrayUsingWhile.vi
Front panel:

Block Diagram:

Another structure that can be used in the generation of arrays is the For-loop. The For-loop executes the
code inside the structure for a number of times. A condition can also stop a For-loop from running by
inserting a condition terminal inside a For-loop. The For-loop stops when this condition is met, or when
the number of iterations has been reached, whichever comes first.
Data in and out of the For-loop can also be transferred via data tunnels. These tunnels are basically the
same as that of While-loop. The basic difference only is that the default tunnel mode for While-loop is the
latest value, while that for the For-loop, the default is indexing.
Example 1.14
(a) Build a 10 5 two-dimensional array whose elements are uniformly distributed random numbers
between 0 and 30 rounded off as integers.
(b) Build a 5 10 two-dimensional array whose elements are uniformly distributed random numbers
between 0 and 30 rounded off as integers.
(c) Show how the number of columns and rows of the two-dimensional array can be controlled by the user.
Use For-loops in (a) and (b).

Basic LabVIEW Concepts

Page 30

Fundamentals of LabVIEW Programming


ArrayUsingFor.vi
Front Panel:

Block Diagram:

Another mode for the tunnel is the concatenating mode, which concatenates the recently generated array
into the previously generated array. The use of such mode can be demonstrated using the following
example.
Example 1.15
Given an array >1 2 3 4@, produce the following arrays:
1 2 3 4
(a) S1 2 3 4T
1 2 3 4
(b) >1 2 3 4 1 2 3 4 1 2 3 4@

Basic LabVIEW Concepts

Page 31

Fundamentals of LabVIEW Programming


IndexingVsConcatenating.vi
Front panel:

Block diagram:

Operations on arrays and matrices. Arrays and matrices can be operated on arithmetically just like
scalars.
Example 1.16
Through an example VI, show how arithmetic operations work for scalars and arrays.
AddingArrays.vi
Front panel:

Basic LabVIEW Concepts

Page 32

Fundamentals of LabVIEW Programming


Block diagram:

Matrices generally follow the same rules as that of array operation, except for multiplication and division.
Example 1.17
Through a VI, demonstrate the difference between array multiplication and matrix multiplication.
ArrayMultVsMatrixMult.vi
Front panel:

Basic LabVIEW Concepts

Page 33

Fundamentals of LabVIEW Programming


Block diagram:

Example 1.18
Re-implement the VI for computing the standard deviation, improving what StdDev1.vi and StdDev2.vi can
do. This time, StdDev3.vi should be able to compute the standard deviation for any number of data.
StdDev3.vi
Front panel

Block Diagram

Basic LabVIEW Concepts

Page 34

Fundamentals of LabVIEW Programming


Array Manipulation. LabVIEW provides various functions to manipulate arrays. Figure 1.20 shows the
Array palette which contains functions for array manipulation.

Figure 1. 20. The Array Palette.

Example 1.19
Given the following arrays,

do the following:
(a) Determine the size of any one of these arrays.
(b) Create a 2D array whose elements of the first, second and third rows are the elements of 1D Array 1,
1D Array 2, and 1D Array 3, respectively. Determine the size of this 2D Array.
(c) Create a 2D array whose elements of the first, second and third columns are the elements of 1D Array
1, 1D Array 2, and 1D Array 3, respectively. Determine the size of this 2D Array.
(d) Extract the fourth, sixth and tenth element of 1D Array 1.
(e) Extract the elements at the fifth row of 2D Array in (b). Also, extract the elements of the second column
of 2D Array.
Basic LabVIEW Concepts

Page 35

Fundamentals of LabVIEW Programming


(f) Extract a 7-by-2 array from 2D Array starting from the second row, first column element.
(g) Create a 5-by-6 array from 2D Array.
(h) Determine the maximum and minimum values of 2D Array as well as their positions.
ManipulatingArrays.vi
Front panel:

Block diagram:

Matrices can also be manipulated using functions under the Matrix palette. The students are expected to
try on these functions and see how they work.
Basic LabVIEW Concepts

Page 36

Fundamentals of LabVIEW Programming


As an application, we try to implement the matrix multiplication via arrays. Remember that array
multiplication is different from matrix multiplication in the sense that the latter has more rules. The matrix
product of two matrices U and V whose sizes are m n and n p respectively is the expression
UV

A Z BZY

The following example implements matrix multiplication using arrays.


Example 1.20
Implement an algorithm for matrix multiplication using arrays only.
matrices
8 1 6
1 1
U = S3 5 7T and V = S1 2
4 9 2
1 3

Then find the matrix product of the


1
3T
6

MatrixMultiplicationViaArrays.vi
Front panel

Block diagram

Basic LabVIEW Concepts

Page 37

Fundamentals of LabVIEW Programming


Drill Problems 1.5
1. How does LabVIEW group data? Show how each data groups are made using a VI called
DataGroups.vi
2. Create a VI that would perform arithmetic operations (add, subtract, multiply and divide), as well as
mathematical functions (trigonometric, exponential, hyperbolic) and statistical functions to matrices and
arrays. Design your front panel as if it will look like a scientific calculator for arrays and matrices. It
would be good if the user is informed whether an operation is invalid and why. Create separate VIs for
arrays (ArrayCalculator.vi) and matrices (MatrixCalculator.vi)
3. Create your own reshape algorithm that reshapes a given 2D array into another array whose size is to
be specified by the user. Recall that the reshape function of LabVIEW reshapes an array thru row-wise
re-arrangement of elements. Your reshape function should do this column-wise. Use While-loop
(ReshapeUsingWhile.vi) and For-loop (ReshapeUsingFor.vi).
4. Two more commonly done operations on matrices, specifically on square matrices, are finding
determinants and finding the inverse. Using arrays, create a VI that would evaluate the determinant of
a 2D square array as user input; call this VI as Determinants.vi. Create a separate VI which will
evaluate the inverse of a 2D square array of numeric data using co-factors and expansion by minors;
call the VI as InverseMatrix.vi. Check your results using matrices and matrix functions (Functions >>
Mathematics >> Linear Algebra)
5. Gauss and Gauss-Jordan elimination are algorithms which reduces a matrix into an upper triangular
matrix and identity matrix respectively. Implement the two algorithms in LabVIEW (GaussElims.vi and
GaussJordanElims.vi) using matrices.
Self Assessment: Rate your level of achievement for the following outcomes:
Cant do
Marginal
Acceptable Exceptional
Outcome
Performance Performance Performance
(1)
(2)
(3)
(0)
Understand how LabVIEW groups data into
a single container;
Generate arrays and matrices using Whileloop and For-loop; and
Operate and manipulate matrices and
arrays.
Write your own thoughts and reflections on this topic.
1.6 Graphing in LabVIEW
At the end of this lesson, the student shall be able to:
a. understand the difference between LabVIEWs chart and graph;
b. display data and waveforms into a chart or graph; and
c. configure charts and graphs suitable for presenting data.
LabVIEW provides a number of charting and graphing options for producing data plots. The table below
summarizes the most commonly used chart and graph types in LabVIEW.

Basic LabVIEW Concepts

Page 38

Fundamentals of LabVIEW Programming


Table 1. 3. Most commonly used charting and graphing types in LabVIEW.

These chart and graph indicators are available on the controls palette.
Waveform chart and waveform graphs differ by the manner they can display and update data.
A waveform chart remembers and displays a certain number of points by storing these points in a buffer.
When the buffer gets full, the chart starts overwriting the old values with the new ones. When new data
points become available, they are appended to the old ones. Waveform charts are used to display real-time
data points, though it also accepts arrays and displays the points all at once.
A waveform graph however, accepts array as an input and displays these as data points all at once. It
does not accept single value points. It is assumed that the points in the array are equally spaced when they
are accepted as an input to a waveform graph.
The following example illustrates the difference between a waveform chart and a waveform graph.
Example 1.21
Plot the function y = sin x for 0 x 2 using a waveform chart and a waveform graph.

Basic LabVIEW Concepts

Page 39

Fundamentals of LabVIEW Programming


ChartVsGraph.vi
Front panel:

Block diagram

A waveform chart has three update modes

Strip Chart: This mode has a scrolling display that is similar to a paper tape strip chart recorder.
This mode first plots values from left to right. From here, it continues to plot new points at the
rightmost point and shifts old values to the left.
Scope Chart: This mode has a retracing display similar to an oscilloscope. As it receives each new
value, it plots the value to the right of the last value. When the plot reaches the right border of the
plotting area, it erases the plot and begins plotting again from the left border.

Basic LabVIEW Concepts

Page 40

Fundamentals of LabVIEW Programming

Sweep Chart: This mode acts much like the scope chart, but the plot is not erased when the plot
hits the right border. Instead, a moving vertical line marks the beginning of new data and moves
across the display from left to right as it adds new data.

Example 1.22
Explore the difference between the three update modes of waveform chart.
The waveform chart and the waveform graph can be configured using the Properties dialog box.
Example 1.23
Show how charts and graphs can be configured using the Properties dialog box.
ConfiguringChartAndGraph.vi
Front panel:

Example 1.24
Plot the sine wave y = sin x and the cosine wave y = cos x for 0 x 2 on the same waveform
chart and graph.

Basic LabVIEW Concepts

Page 41

Fundamentals of LabVIEW Programming


MultiplePlots.vi
Front panel

Block diagram:

In the foregoing discussions, the data plotted mostly are time-based data, that is, the x-axis was dedicated
to time. This is not really the case however. For waveform charts and waveform graphs, we assume that
the variable in x-axis is equally spaced. So if you are to plot a data, not necessarily time-based data, but
the data points are generated with equal spacing, waveform charts and waveform graphs provide a good
way to plot these data points. For unequally spaced x-axis, XY Graphs can be used.

Basic LabVIEW Concepts

Page 42

Fundamentals of LabVIEW Programming


Example 1.24
Plot the polynomial f x = A + Bx + Cx + Dx E with A = 4, B = 3.7, C = 1.9 and D = 0.17 for
the following 1D arrays of x.
a. 0 x 9
b. x = >0 1.0 2.7 3.0 4.2 5.0 6.5 7.3 8.1 9.0@
PlottingUsingXYGraph.vi
Front panel

Block diagram

Example 1.25
Use graphical method to find the approximate roots of the equation x E 9.4x + 22.95x 10.602 =
0. The roots of this equation are the values of x which satisfy the equation. Note that since the degree of
the polynomial in the equation is 3, there will be three roots.

Basic LabVIEW Concepts

Page 43

Fundamentals of LabVIEW Programming


FindingRootsGraphically.vi
Front panel

Block diagram

LabVIEW also has tools for plotting in three dimensional. In the first example, a surface plot is generated
using parametric values.
Example 1.26
Create a surface plot for a torus. A torus is a ring with two parameters: the distance between the center of
the torus to the center of the tube R, and the radius of the tube r, as shown in the figure below.

With these definitions, the torus is defined by the following equations:


x = R + r cos u cos v
y = R + r cos u sin v
z = r sin v
Basic LabVIEW Concepts

Page 44

Fundamentals of LabVIEW Programming


where u and v are parameters with range from 0 up to 2. The For R = 10 and r = 2, and using30 data
points for u and v, plot a torus in LabVIEW.
PlottingATorus.vi
Front panel

Block diagram

Basic LabVIEW Concepts

Page 45

Fundamentals of LabVIEW Programming


Drill Problems 1.6
1. (a) Generate a Gaussian distributed random number with a mean of 10 and a standard deviation of 2.
Your VI would only stop generating a random number when a Stop button is pressed. The VI should
only generate 100 data points per second. Plot the random numbers as they are generated and after
pressing the Stop button. Name the VI as WhiteNoise.vi.
(b) A moving average filter is a kind of filter which aims to smoothen out variations in signals. It works in
the following manner: the current value and a number of previous values are averaged to generate a
new value. The number of values to be generated depends on the window size of the filter. If for
example, the window size is 10, then the current value plus 9 previous values of the input signal are
averaged. With this, create a moving average filter for the input signal generated in part (a). The
window size of the moving average filter is 5. Plot the input signal and the filtered signal on the same
set of axes. The VI should stop when a Stop button is pressed. Call this VI as the
MovingAverageFilter.vi. (Hint: Use shift registers.)
(There is a video called WhiteNoise.wmv and MovingAverageFilter.wmv which demonstrates how
these VIs should work.)
2. For a set of correlated data, a straight line that best fits the data is given as y = a x + aL , where
= P b O P b
a = = QPcQO Q c Q and aL = y a x (x and y are the means of x and y respectively). Given the
Q

PQ

data below which tries to determine if there is a relationship between the length of the tail (TLength)
of a fox in inches to the weight (Weight) of the fox in pounds.

For these data, build a VI to do the following:


a. Plot the data in a graph. Note that as this point, there is no relationship between the two sets of
data and therefore, the data points should not be connected in any way.
b. Using the VI, compute the line that best fits the two data sets, with the tail length the independent
variable and the weight as the dependent variable.
c. Plot the best fit line into the same axes as that of the plot in (a) with x between 0 and 35.
d. Graphically determine the approximate weight in pounds of the fox if the tail length is (i) 5 in; (ii)
12 in; (iii) 18 in; (iv) 22 in and (v) 30 in. Save these values in an array indicator.
e. Does the line make sense? Why or why not? Put your answer here as an annotation to your VI.
Call the VI as BestFitLine.vi
3. Create a VI that would plot the following functions into a chart and a graph: the exponential function
y = eP , the logarithmic function y = ln x, hyperbolic cosine function y = cosh x and the cosine
function y = cos x for 0 x 5. Choose appropriate spacing to ensure smooth plot. Choose the
appropriate scaling for the x and y axes so that the user will have an idea on how the function behaves
as x gets larger. Make sure also that the user will be able to discern which plot is which. Finally, choose
which is the better tool to plot such functions so that the user will be able to use the plots for better
understanding of the behavior of the function. Call this VI as FunctionPlotter.vi.
Basic LabVIEW Concepts

Page 46

Fundamentals of LabVIEW Programming


4. The PlottingATorus.vi in the example used MathScript node to generate the needed arrays. Show
how the nodes and structures of LabVIEW can be used to accomplish such task. Make the VI
interactive too, that is the user can specify the value of R and r, as well as the spacing for the
parameters u and v. Take note that as a requirement R > r or the torus will not be the familiar torus.
Integrate this into the VI so that when the user enters a value of R and r such that R r, the arrays
will return empty. Call the VI as PlottingATorus2.vi
5. Show how the following functions can be plotted as a surface for 5 x, y 5:
a. f x, y = sinc fx + y ; The sinc x function is equal to the expression sin x /x.
b. f x, y = exp x y .
c. f x, y = cos x sin y
d. f x, y = ln x + y
e. f x, y = sinh x + cosh y
Call the VI as SurfacePlots.vi.

Basic LabVIEW Concepts

Page 47

You might also like