Formula Node Calculation Issues

I'm trying to make an array where the output is defined by the formula 25*(2^x) where x is the input variable, with integer iterations from 0 to 7.  To do this, I made an formula node and put it in a for loop.  Unfortunately the (^) symbol is not working right for the calculation.  I tested it simply with x^2 and this did not work, while having x*x returned the correct values.  Instead of outputting the correct values, it outputs seemingly random integers.  Anyone know why?  I am new to this software so I apologize if this this a common issue but I could not find help anywhere else.
Solved!
Go to Solution.

If you use the numeric primitives rather than a formula node, craziness can be avoided (well, sometimes).
Lynn

Similar Messages

  • Cannot Access Shortcut Menu for Adding Input/Output in Formula Node

    This is a wierd problem. I cannot access the shortcut menu in formula node. I right click the border, nothing happens. Anyone run into this before? Is there any other way to add inputs and outputs?
    I am running Vision Builder AI and want to use a formula node in my calculator tool.
    Solved!
    Go to Solution.

    As the saying goes, "when you hear hoofbeats, think horses and not zebras".  Let's get a few things out of the way.
    Is the VI in edit mode?
    Is autotool on?
    Drop a fresh FN on a New VI and try it again.
    The only other way I know to add/remove inputs is scripting, let's not go there.
    I have had a few issues with context menus, very few which persisted past a LV and/or computer restart, so I won't rule out a zebra just yet.

  • "Eval Parsed Formula Node VI" does not return outputs in predefined order

    I make a data analysis program, where the data consists of some million events and each event has e.g. 4 channels and 1-5 hits on each channel. 
    I would like the user to select different expressions of these channels to give coordinates to plot in a 2D histogram (increment a bin in Intensity Graph), e.g. for some experiment you want to show x=ch1-ch2; y=ch1+ch2+ch3+ch4; while in another experiment you want x=ch1-123; y=123-ch2;
    There are other VIs that use static LabView-code for the normal things, but now after a few years of adding to this program I find that it would be quite good with a general plotter and let the user specify simple expressions like this. Also with the "normal" static plots, there is a need to filter out bad data and then it would be much simpler both to program and use if you could write text expressions with boolean logic to combine multiple filters. Making a LabView code and GUI that allows AND/OR/parenthesis combinations of expressions will be quite an effort and not very reusable.
    So, with the above motivation, I hope you see that it would make sense to have a useable string formula evaluator in LabView. I find some info about MathScript's user-defineable functions, but haven't managed to get MathScript working in LV2010 yet (maybe some licensing or installation issues, I think I had it in 8.6). But I think it would be possible to do most of what I want for the display-part (not the filtering) with the simpler Eval/Parse Formula Node VIs and suitable use of the limited variable name space. So I started testing, and found a quite annoying issue with how the evaulator works.
    To the parser, you are expected to send an array of output variable names. But then it ignores this array, and returns one output per assignment/semicolon in the formula, in the order of the formula text. Since the static parts of my program need to know what the output values mean (which of them is x and which is y), I would have to rely on the user not using any intermediate variable and defining x before y. The attached screenshot demonstrates the problem, and also that it has been solved by NI statff in the "Eval Formula Node VI" which does the appropriate array-searching to extract only the pre-defined outputs, in their expected order. But using that VI is about 100 times as slow, I need to pre-compile the formula and then only use the evaulator in the loop that runs over a million events.
    I don't know if I'll take the time to make my own tweks to the parsing stage (e.g. preparation of array-mapping to not have to repeat the search or maybe hacking the output list generated by the parser) or if I'll have to make it in a static Formula Node in the block-diagram (which supports more functions), so that the user has to run with development environment and stop the program to change the plotting function. But I wanted to share this trouble with you, in hope of improvments in future LabView versions or ideas from other people on how I could accomplish my aim. I have MATLAB-formula node possibility too, but is far as I have seen the only place the user could update the formula would then be in a separate .m file, which is re-read only when typing "clear functions" in the Matlab console window. (Having this window is also an annoyance, and perhaps the performance of calling Matlab in every iteration is not great.) 
    Besides this issue, it also seems very strange there is virtually no support for conditional expressions or operators in Formula Node evaulated formulas (called Mathematics VIs in the documentation). Maybe using (1+sign(a-b))/2 you can build something that is 0 when a<b and 1 when a>b, but it is not user friendly! Would it really be diffcult to add a function like iif(condition, return_value_if_true, return_value_if_false) to replace the unsupported "condition ? if_true : if_false" operator? Would it really be difficult to add support for the < <= >= > == || && operators? Although compiled to an assemply language, this can't exactly be difficult for a CPU.
    Attachments:
    LV script test.png ‏62 KB
    LV script test.vi ‏18 KB

    (1) You can put any kind of code inside an event structure with the limitation that it should be able to complete quickly and without user interaction.  For example a while loop for a newton-raphson method is fine, but an interactive while loop where the stop condition depends on user iteraction is not recommended. By default, event structures lock the front panel until the event completes, so you would not even be able to stop it.
    (2) Yes, you can do all that. LabVIEW has no limitation as a programming language. Use shift registers to hold data and state information, the manipulate the contents as needed.
    (3) I would recommend to use plain LabVIEW primitives instead of formula nodes. Show us your code so we can better see what it's all about. Obviously you have a mismatch betweeen scalars and arrays. It is impossible from the given information where the problem is.
    (4) Yes, look inside the nonlinear curve fit VI (you can open it an inspect the code!). One of the subVIs does exactly that. Just supply your model VI.
    LabVIEW Champion . Do more with less code and in less time .

  • Formula node uInt32 overflow

    I'm having a weird behaviour in formula node. The overflow of unsigned integer operations simply doesn't match the results of standard LabVIEW blocks as shown in the attached picture.
    How can I deal with this problem? I need the behaviour of the block diagram. I could not do a right logical shift in unsigned integers in block diagram, so I'm using formula node (I could not figure out how to do it because I can't negate a unsigned value).
    I'm using LV2012SP1. Were there any changes in this behaviour in newer versions?
    Thank you.

    I found a problem in hexadecimal and octal numeric representations of the formula node. The picture illustrates the issue. Three variables are assigned with the same value but outputs different results.
    The hex and octal representations only work for half range of the 32 bits unsigned integer. When the value assigned gets beyond this limit the variable receives zero. This doesn't happen with a decimal value neither with 8 bits variables. Seems the problem doesn't only happen with overflow operations.

  • Parenthesis in formula node

    I'm using the formula node and it appears that parenthesis don't work. Is this correct? What is the order of operations?
    The Formula Node Syntax page in the help is extremely brief and sparse, bordering on useless for anyone that doesn't already now what is going on. Is there a more thorough description of the Syntax anywhere?

    Thanks Dennis,
    The error is just an incorrect calculation.
    I put together a simple node and parenthesis did work. So something else must be amiss. I stripped down my VI and equation and made two formula nodes implementing the same equation with and without parenthesis. One gives an exponential decreasing curve, the other a constant array. Where is the error?
    Attachments:
    parenth_ex.vi ‏49 KB

  • How to change content in the formula node of the current vi

    Actually I want to give formula with array index. 
    My formula p=a[0]-30; But i couldnot give array index in the formula expression..
    Please help me in this issue.

    Muthu92 wrote:
    Thank you for your reply. It is very useful for me.  But i can't give conditional operator in that operator. It is showing error.
    My Test cases
    A[0]+A[1]>150
    A[31]-50 <100.
    If those are your exact statements, then they don't make sense in a formula node.  You have to use them in an if-statement or some other type of control logic.  This mimics text-based programming languages such as C... See here for instructions on formula node syntax: http://zone.ni.com/reference/en-XX/help/371361G-01​/lvhowto/formula_node_syntax/
    For instance, you COULD say something like:
    **In this example, let A[0] == x, A[1] == y, A[31] == z**
    if(x+y>150)
    /* do something if this is true */
    else if(z-50 < 100)
    /* do something else */
    EDIT: 
    It should also be noted that Variable Names MUST be lowercase!! I just discovered this
    EDIT2:
    I stand corrected.  After trying to create an example and digging through the LabVIEW Help, I stumbled across this:
    Differences between the Parser in the Mathematics VIs and the Formula Node
    The parser in the Mathematics VIs supports all elements that Formula Nodes support with the following exceptions:
    Variables—Only a, a0, ..., a9, ... z, z0, ..., z9, are valid.
    Logical, conditional, inequality, equality—?:,, &&, !=, ==, <, >, <=, and >= are not valid.
    Functions—atan2, max, min, mod, pow, rem, and sizeOfDim are not valid. You can use these functions in a Formula Node or use their corresponding LabVIEW functions.
    So it DOES NOT seem like Eval Formula Node can do conditionals like you want.  I would just implement them using a LabVIEW based algorithm after all.  Trying to out smart the formula nodes to avoid simple LabVIEW code is just too much of a hassle
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If someone helped you out, please select their post as the solution and/or give them Kudos!

  • Really need Min(a,b) and Max(a,b) function in "Eval formula node"

    Hi all,
    I've been using the 'Eval formula node" to let the user of my app configure his own calculations,
    but now I've found out that the "Eval formula node" doesn't support these functions.
    e.g        y= min (a,b)
    or         y = max (a+3, c-4)
    I considered adding them myself to the Eval formula node's subvi's,
    but franckly I've never seen such complex subvi's :-)
    Is pretty urgent. Any ideas?

    MegKB wrote:
    Maybe the MathScript node is the way to go now, as long as you want to install MatLab.
    The MathScript node does NOT need Matlab.  It runs Matlab-like code, but it is totally inside of LabVIEW.  There is a Matlab node that uses ActiveX to run Matlab.  For that you need to have Matlab installed.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • HELP: Run-time array dimension in LabVIEW formula node

    I need to dimension an array at run time within a formula node as follows:
    int32 i,N;
    N = sizeOfDim(inputArray,0);
    float64 outputArray[N];
    for (i = 0; i outputArray[i] = myfunction(inputArray[i]);
    However, LabVIEW complains "Formula Node: index list expected". On the
    other hand, if I say
    float64 outputArray[1000];
    LabVIEW is perfectly happy. But that's not what I need to do! Is there
    an alternative
    way of accomplishing my goal?
    BTW, I've tried calculating N outside the formula node and then
    presenting it as
    an input with the same results. I've got a bad feeling that run time
    array dimensioning
    just isn't allowed.
    TIA,
    Hugh

    Can't you just use the Initialize Array function outside the formula node and pass that instead?

  • Functions in Formula Node

    Hello:
    I have written a simple formula node in the VI in annex. It uses two functions that should be called for R, G and B. Because I do not know how to implement functions (the way I implement C functions) I had to repeat 3 times the same code (for R, G and B) which makes the code not so readable and maybe I loose on performances? Could you correct the formula node by implementing functions, please? I was not able to find this tip in the various documentation that I have nor on the net. Thank you very much in advance,
    Chris
    Attachments:
    myRGBtoLAB.vi ‏32 KB

    Wow Chris!
    That is one impressive formula node! In terms of computational efficiency, I wouldn't expect there to be a lot of difference between the formula node and separate VIs. Stll, I have attached two sub VIs that I think implement the two repeated areas of the formula node code.
    Something to do though is change the type of all the outputs to doubles. The calculation is being done in double precision anyway, so you might as well preserve it. Also, the single frame sequence around the whole thing isn't performing any function so it can be deleted.
    As far as readability goes, remember that readability (like beauty) is in the eye of the beholder. If you can read the code and know intuitively what it does, I wouldn't worry too much about it...
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps
    Attachments:
    n_to_n1.vi ‏22 KB
    the_other_calculation.vi ‏25 KB

  • Why do in-line conditiona​l expression​s work in Formula Node but not in 'Eval Formula Node.vi'?

    'Eval Formula Node.vi' and a standard Formula node seem identical in most respects in terms of their functionality, however I'm stumped by the case of inline conditional expressions. 
    I'd like to read in a string in the syntax "(expr)?(expr)expr)" from a text file and recieve the output as a double.
    The subVI seemed like the perfect tool since I was already using it to interpret a number of other calculations within the text file, however in this case the behavior is not as expected.
    Has anyone else ever tried this? is there a different syntax needed between the two tools?
    Are there other features of the Formula Note not replicated by this VI?  (so I can avoid them in future)?
    For simplicity I've attached a little demo of the behavior.
    I am currently working in 2010, which I know is getting on in years.
    If the behavior is improved in later versions, that may be a good excuse to upgrade :-) 
    Thanks,
    Elaine R.
    Attachments:
    Conditional Formula Node demo.vi ‏13 KB

    .aCe. wrote:
    Eval formula Node does not do any conditional expressions as far as I am aware.
    That is right. It's a rather dirty hacked VI library to do some formula evalution and has many limitations in comparison to the Formula Node including no support for conditional operator as well as some others. In addition it can also error on some more complex bracketed expressions.
    It is an old example VI that was never revisited and probably never will be as writing a new one from scratch would be easier. But considering that the Formula Node and Mathscript and other possibilities exist, this is not likely going to happen soon.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • It crushes when the formula in a Formula Node is somewhat complicated.

    I call outer Formula Node VIs using Call By Reference Node VI. This works well in general but for some VIs with a little complicated formulas. The system crushes while calling the VI repeatedly. In the attached files, Script1.vi goes well but Script0.vi doesn't. The difference between two is just that the expressions in the former are short (but equivalent essentially). Are there any rules or constraints here?
    Attachments:
    TestScript.zip ‏40 KB

    Hi Randy,
    Thanks for your answer.
    I've raised one more question at the forum. I lastly attached a sample program for explaining the issue. I would greatly appreciate if you check the program at http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=5065000000080000008A6D0000&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0.
    Michiro

  • Shift Register while Indexing Arrays in Formula Node

    Hello, 
    I am having trouble using the formula node while indexing my two arrays.  I keep getting "NaN" for my output array. I believe the problem lies within my shift register.  My guess is that for the first calculation there is not a PreviousAngle so that is why it is giving me "NaN."  For the first index I would like the value of the PreviousAngle to be 0. I am new to LabView and unsure what to do.
    Thanks!
    Christian Seymour
    Solved!
    Go to Solution.
    Attachments:
    Complementary Filter.vi ‏21 KB

    The shift register should contain 0 by default since you are using a double [if uninitalized, the shfit register takes the default value of the data type.  In this case, the default Double is 0], but you should explicitly initalize the shift register to a default value in most cases.
    To do so, right click on the "previous angle" shift register and select "Create constant".  This will create a Double value of 0 to fill in the register for the first calculation.
    If you need a number other than 0 to start, you can just change this constant.
    **Note:  This is a good habit to have.  Shift registers retain value as long as the VI is in memory.  So if you run this more than once, it will have the value from the last execution automatically!  This is usually unintended behavior for new LabVIEW users -- however you can sometimes take advantage of this feature in some applications and make it intended behavior
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    If someone helped you out, please select their post as the solution and/or give them Kudos!

  • Periodic PCR profile in Formula Node

    I use Formula Node to build a three-stage temperature profile in LabVIEW v7.
    if (x>=0&&x<5)
    y=94;
    if (x>=5&&x<10)
    y=56;
    if (x>=10&&x<15)
    y=72;
    How to make this signal become periodic?
    You can find my VI in the attachment.
    Attachments:
    test.vi ‏21 KB

    If you mean periodic on x, then adding before your calculations expression
    x=mod(x,15);
    can work (as this will make argument always wrap in [0,15) ).

  • Applying delay in formula node in labview

    hi every bod
    Solved!
    Go to Solution.

    If you have not done so yet, please go through the free on-line tutorials about LabVIEW.
    Rarely is the formula node the most appropriate way to write code in LV.  The native LV constructs may be a bit awkward at first for someone with a text-based programming background.  Once you learn to use dataflow and to recognize the functions by their icons, you may find that graphical programming can be both powerful and easy to read.  
    For delays use the Wait(ms) function found in the Timing palette.  If you need a delay in the middle of a calculation (which seems unlikely), you may need to split the calculation into two parts and put the Wait (ms) between the parts.  See the image below for one way to do this without any formula nodes.
    Lynn

  • Updating equation in formula node from a string or text file

    Is it possible to have a calculation performed based on an equation stored in a string (read from a text file). I am guessing not because the equation would need be compiled but thought I would ask.

    Hi,
    it depends on how complex the equation is.
    Rather than using a formula node, you could use the eval formula node vi instead. (Functions->Analyze->Mathematics->Formula), but you may needs to re-organise the text formula a little.
    Assuming you're using not the base package, and atleast LabVIEW version 6.1 that shouldn't be a problem.
    Hope that helps.
    Sacha Emery
    National Instruments (UK)
    // it takes almost no time to rate an answer

Maybe you are looking for

  • Possible to send PO item info with PO cancellation?

    Hello! We are running "pseudo" standalone SRM 5.0. The "pseudo" is because we are using a legacy backend, emulating R/3. We need to send PO cancellation back to our legacy using XI/PI. The standard PROXY for this, "PurchaseOrderCancellationRequest_Ou

  • Best strategy for migrating GL 6 DW CS4?

    First I gotta say that -- as decade-long user of several Adobe products -- Adobe has really screwed over long-time users of Adobe Golive. After a week of messing around with something that should be a slam dunk (considering the substatial amount of $

  • Portlet resource bundle

    Hi, I have written and deployed a portlet. which works very fine with the default language (english) I want to make the same portlet available in multiple languages, rather I want to provide internationalization over this. I have prepared a resource

  • Adobe Premiere Elements 2

    I have not been able to discover the serial number of the software that accompanied my Nokia N93 hence making it impossible for me to instal the software. How do I find the serial number? This is the problem I have for now. Can you, please, help imme

  • User Account and Location

    How do I determine the user account and location so that I can track user changes?