Jump to content

Labview 7.1 factorial calculus!


Recommended Posts

Hello all,

We are relatively new users of version 7.1 of Labview, and we have been scratching our heads for days now (we are amateurs) about the best way to construct a vi that calculates the factorial of an integer, NOT using any existing vi's (for example Analyze->mathematics->Special and Numeric functions) but from scratch.

We appreciate any thorough help...

:thumbup:

Link to comment

Hi:

This factorial calculation problem is one that NI uses to show the recursive VI calling feature of LabVIEW. Recursive VI calling method is considered an advanced LabVIEW topic involving use of VI server. I would say that if you are new to LabVIEW, you should not punch yourself over, and over, if you could not get a quick solution to this 'seeminlgy' simple problem.

... Well, enough said. Pasted below is sample code for factorial calculation. I have also attached the VI.

Anthony

Link to comment

Although the factorial function is the classic example used to illustrate recursion, it does not have to be written that way. In fact, it is probably easier to understand (and far easier for a neophyte to write) a direct iterative routine to calculate factorial using LabVIEW.

The value for which factorial is to be calculated is the input value. The For Loop executes this many times, multiplying (loop index +1) by the results of the previous loop's iteration, which is stored on a shift register. The initial value of the shift register is one, to seed the calculation. We need to add one to the loop index because For Loops start at zero, not one. The code illustrated below took less than one minute to write; it took longer to write this description.

http://forums.lavag.org/index.php?act=attach&type=post&id=6070

For you experienced programmers out there: I know that it calculates one extra multiplication (1 x 1) during the first iteration of the loop. Mea culpa.

Link to comment

Simpler is better, and Bob's code has the safety advantage that it cannot run away from you in an endless recursive call if someone makes a simple modification mistake, which can easily happen with self calling code.

That being said, the technique in the second post has it's uses later in your LabVIEW life.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.