{"id":21299,"date":"2017-07-24T09:44:50","date_gmt":"2017-07-24T16:44:50","guid":{"rendered":"https:\/\/blog.digilentinc.com\/?p=21299"},"modified":"2021-06-10T16:35:36","modified_gmt":"2021-06-10T23:35:36","slug":"labview-formula-nodes","status":"publish","type":"post","link":"https:\/\/digilent.com\/blog\/labview-formula-nodes\/","title":{"rendered":"LabVIEW Formula Nodes"},"content":{"rendered":"<p>The Formula Node in the LabVIEW software is a convenient, text-based node you can use to perform complicated mathematical operations on a block diagram using the C++ syntax structure. It is most useful for equations that have many variables or are otherwise complicated. The text-based code simplifies the block diagram and increases its readability. Furthermore, you can copy and paste existing code directly into the Formula Node rather than recreating it graphically.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-21476 aligncenter\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/07\/formnode.gif\" alt=\"\" width=\"272\" height=\"96\" \/><\/p>\n<p>In addition to text-based equation expressions, the Formula Node can accept text-based versions of if statements, while loops, for loops, and do loops, which are familiar to C programmers. These programming elements are similar but not identical to those you find in C programming.<\/p>\n<p><strong>Using the Formula node<\/strong><\/p>\n<p>Complete the following steps to create a VI that computes different formulas depending on whether the product of the inputs is positive or negative.<\/p>\n<ol>\n<li>Selecting\u00a0<b>File<\/b>\u00bb<b>New VI<\/b>\u00a0to open a blank VI.<\/li>\n<li>Place a Formula Node on the block diagram.\n<ol>\n<li>Right-click on the diagram and navigate to\u00a0<b>Programming<\/b>\u00bb<b>Structures<\/b>\u00bb<b>Formula Node<\/b>.<\/li>\n<li>Click and drag the cursor to place the Formula Node on the block diagram.<\/li>\n<\/ol>\n<\/li>\n<li>Right-click the border of the Formula Node and select\u00a0<b>Add Input<\/b>\u00a0from the shortcut menu.<\/li>\n<\/ol>\n<p align=\"center\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.ni.com\/cms\/images\/devzone\/tut\/agzctjcu49131.jpg\" alt=\"\" width=\"198\" height=\"246\" \/><\/p>\n<ol start=\"4\">\n<li>Label the input variable\u00a0<span class=\"code\">x.<\/span><\/li>\n<li>Repeat steps 3 and 4 to add another input and label it\u00a0<span class=\"code\">y<\/span>.<\/li>\n<li>Right-click the border of the Formula Node and select\u00a0<b>Add Output<\/b>\u00a0from the shortcut menu.<\/li>\n<\/ol>\n<p align=\"center\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.ni.com\/cms\/images\/devzone\/tut\/tjocxwcb49132.jpg\" alt=\"\" width=\"336\" height=\"242\" \/><\/p>\n<ol start=\"7\">\n<li>Create two outputs and name them\u00a0<i><span class=\"code\">z1<\/span><\/i>\u00a0and\u00a0<i><span class=\"code\">z2<\/span><\/i>, respectively.<\/li>\n<\/ol>\n<p align=\"center\"><b><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.ni.com\/cms\/images\/devzone\/tut\/gubwnlto49133.jpg\" alt=\"\" width=\"187\" height=\"114\" \/><\/b><\/p>\n<ol start=\"8\">\n<li>Enter the expressions below in the Formula Node. Make sure that you complete each command with a semicolon. Notice, however, that the if statement does not require a semicolon after the first line.<\/li>\n<\/ol>\n<p class=\"code\" style=\"text-align: center;\">if (x*y&gt;0)<br \/>\nz1 = 3*x**2 &#8211; 2*y**3;<br \/>\nelse z1 = 0;<br \/>\nz2 = sinh(z1);<\/p>\n<ol start=\"9\">\n<li>Create controls and indicators for the inputs and outputs.\n<ol start=\"1\">\n<li>Right-click on each input and select\u00a0<b>Create<\/b>\u00bb<b>Control<\/b>\u00a0from the shortcut menu.<img loading=\"lazy\" decoding=\"async\" style=\"font-size: 14px; font-family: 'Open Sans', Arial, sans-serif; text-align: -webkit-center;\" src=\"http:\/\/www.ni.com\/cms\/images\/devzone\/tut\/ezcsndjx49134.jpg\" alt=\"\" width=\"259\" height=\"158\" \/><\/li>\n<li>Right-click on each output and select\u00a0<b>Create<\/b>\u00bb<b>Indicator<\/b>\u00a0from the shortcut menu.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p align=\"center\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.ni.com\/cms\/images\/devzone\/tut\/bdgbziol49135.jpg\" alt=\"\" width=\"385\" height=\"163\" \/><\/p>\n<ol start=\"10\">\n<li>Place a While Loop with a stop button around the Formula Node and the controls. Be sure to include a Wait (ms) function inside the loop to conserve memory usage. Your block diagram should appear as follows<\/li>\n<\/ol>\n<p align=\"center\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/www.ni.com\/cms\/images\/devzone\/tut\/yoynkmfs49136.jpg\" alt=\"\" width=\"351\" height=\"194\" \/><\/p>\n<ol start=\"11\">\n<li>Click the\u00a0<b>Run<\/b>\u00a0button to run the VI. Change the values of the input controls to see how the outputs change.<\/li>\n<\/ol>\n<p>In this case, the Formula Node helps minimize the space required on the block diagram. Accomplishing the same task without the use of a Formula Node requires the following code.<\/p>\n<p align=\"center\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/www.ni.com\/cms\/images\/devzone\/tut\/nlbzcuxw49137.jpg\" alt=\"\" width=\"507\" height=\"298\" \/><\/p>\n<p>Thank you for reading my blog post, and for more information on\u00a0formula nodes follow this\u00a0<a href=\"http:\/\/www.ni.com\/white-paper\/7572\/en\/\">link<\/a>. If you are interested in trying out LabVIEW for yourself, you can purchase a copy of\u00a0<a href=\"https:\/\/digilent.com\/shop\/labview-home-bundle\/\">LabVIEW 2014 Home Edition<\/a>\u00a0which includes everything you will need to run\u00a0<a href=\"https:\/\/www.labviewmakerhub.com\/doku.php?id=learn:tutorials:libraries:linx:3-0:beaglebone-black-setup\">LINX 3.0<\/a>.\u00a0Please comment below with any questions or comments you may have.<\/p>\n<div class='watch-action'><div class='watch-position align-left'><div class='action-like'><a class='lbg-style6 like-21299 jlk' data-task='like' data-post_id='21299' data-nonce='8896bc70a6' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Like' \/><span class='lc-21299 lc'>+6<\/span><\/a><\/div><div class='action-unlike'><a class='unlbg-style6 unlike-21299 jlk' data-task='unlike' data-post_id='21299' data-nonce='8896bc70a6' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Unlike' \/><span class='unlc-21299 unlc'>0<\/span><\/a><\/div><\/div> <div class='status-21299 status align-left'><\/div><\/div><div class='wti-clear'><\/div>","protected":false},"excerpt":{"rendered":"<p>Austin makes LabVIEW even more efficient with formula nodes!<\/p>\n","protected":false},"author":42,"featured_media":21484,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4323],"tags":[],"ppma_author":[4493],"class_list":["post-21299","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software"],"jetpack_featured_media_url":"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/07\/yoynkmfs49136.jpg","jetpack_sharing_enabled":true,"authors":[{"term_id":4493,"user_id":42,"is_guest":0,"slug":"astanton","display_name":"Austin Stanton","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/0cc9db2caf6344c8f78ea46c21570f33a954c45596addf479125043e52431de0?s=96&d=mm&r=g","1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":"","9":"","10":""}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/21299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/comments?post=21299"}],"version-history":[{"count":0,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/21299\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media\/21484"}],"wp:attachment":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media?parent=21299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/categories?post=21299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/tags?post=21299"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=21299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}