Now that you know about LabVIEW's four main control flow structures, we'll introduce a structure that doesn't affect program flow. The Formula Node is a resizable box that you use to enter algebraic formulas directly into the block diagram. You will find this feature extremely useful when you have a long formula to solve. For example, consider the fairly simple equation, y = x2 + x + 1. Even for this simple formula, if you implement this equation using regular LabVIEW arithmetic functions, the block diagram is a little bit harder to follow than the text equations (see Figure 6.67). Figure 6.67. A snippet of code that we can convert to a formula and put inside a Formula Node, as shown in Figure 6.68
You can implement the same equation using a Formula Node, as shown in Figure 6.68.[1]
Figure 6.68. A Formula Node containing a formula derived from the code snippet in Figure 6.67
With the Formula Node, you can directly enter a formula or formulas, in lieu of creating complex block diagram subsections. Simply enter the formula inside the box. You create the input and output terminals of the Formula Node by popping up on the border of the node and choosing Add Input or Add Output from the pop-up menu. Then enter variable names into the input and output terminals. Names are case sensitive, and each formula statement must terminate with a semicolon (;). You will find the Formula Node in the Programming>>Structures subpalette of the Functions palette. These operators and functions are available inside the Formula Node. To get detailed information on the Formula Node syntax, open the Help window and place the cursor over the formula node. The Help window will look like Figure 6.69. Click on the Detailed help link to open the LabVIEW help file and then follow the Formula Node Syntax link. Figure 6.69. The Context Help window showing detailed information about the Formula Node
The following example shows a conditional branching that you could perform inside a Formula Node. Consider the following code fragment, similar to Activity 6-3, which computes the square root of x if x is positive, and assigns the result to y. If x is negative, the code assigns value of 99 to y.
You can implement the code fragment using a Formula Node, as shown in Figure 6.70. Figure 6.70. A Formula Node formula with some of its syntax elements annotated
Activity 6-5: Formula FunYou will build a VI that uses the Formula Node to evaluate the equation y = sin(x), and graph the results.
VI Logic
|