LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

the sequence of fibonacci

Solved!
Go to solution

So i want to make a vi that generates all the numbers of fibonacci. It can't go higher than a given number by the user of the program. The program i made works, but everytime i want to use it i have to click the arrow. Is there a way to avoid this?

0 Kudos
Message 1 of 14
(1,073 Views)

@corned wrote:

So i want to make a vi that generates all the numbers of fibonacci. It can't go higher than a given number by the user of the program. The program i made works, but everytime i want to use it i have to click the arrow. Is there a way to avoid this?


Turn it into a subVI. 

Put a while loop around it.

You probably want an event structure too, to trigger the call.

 

This is pretty basic. You might want to do some (free) tutorials.

0 Kudos
Message 2 of 14
(1,069 Views)

@corned wrote:

So i want to make a vi that generates all the numbers of fibonacci. ?


Since the series has an infinite number of elements, it is impossible to generate all of them. Do you have an input for an upper limit or number of elements?

 


@corned wrote:

The program i made works, but everytime i want to use it i have to click the arrow. Is there a way to avoid this?


You simply need to make it into a toplevel VI with a while loop, a reasonable loop rate (or an event structure) and recalculate the series whenever the input changes. Think "state machine".

 

Ultimately, you can build it onto a standalone executable (or configure it to run when opened, not really recommended).

Message 3 of 14
(1,031 Views)

Adding to the previous answers; Are you just wanting to reread the results at a later time? If so, it's easy to write the result to a text file and simple look there, e.g. Input in the 1st column and the fibonacci numer in the 2nd.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 14
(964 Views)

I have to make a program that gives all the numbers of fibonacci lower than a given number by the user. It works great but the stop button is not working. How do i fix this?

0 Kudos
Message 5 of 14
(962 Views)

Welcome to the LabVIEW Forum.

 

As a new user of LabVIEW, you might not know that if you post code using LabVIEW 2022, the people with the most experience with LabVIEW might not have purchase the "latest version" (which, admittedly, 2022 is not), and won't be able to open and look at your code.  But you can open your routine, go to the File menu, and "Save for Previous Version".  Almost all of the "experts" will be able to read LabVIEW 2019 or 2021.

 

So I'll make some "guesses" at your problem with the Stop button.  I'm assuming you are using the one on the Boolean palette for the Front Panel.  Boolean controls have a "mechanical action".  Some (like the Push Button and Toggle Switches) are "Switch when Pressed" -- you change them, and they "stay changed" until you change them again.  However, the Rectangular ones (like "Stop" and "OK") are "Latch when Released" -- this mean they "stick" until you read them, then they revert to their default value.  So if you put a Stop button on your Block Diagram, every time you read it, the mechanical action will reset its value to its default value (which is False) after it is read.

 

This is not a "bug", it is a Feature.  If you post your code in LabVIEW 2019 (and none of my colleagues on the Forum has answered you yet), I'll suggest how you can "fix" the Stop Button problem.

 

Bob Schor

 

P.S. -- another sometimes-useful Mechanical Action is "Switch until Released" -- this makes the "Push Button" really behave like a buzzer Push Button -- as long as you are pushing it, it is "True", but when you lift your finger off it, it switches back to "False".  These kinds of Mechanical Actions are designed for creating "responsive Front Panels", but if you are unaware of these "actions", can cause confusion when you are trying to use them as ordinary Boolean (True-false) variables.

0 Kudos
Message 6 of 14
(944 Views)

The stop doesn't work, because the event structure stalls data flow.

 

Add an event case for the stop button's value change event, and wire a Boolean true in it to the loop's stop criterium.

 

Also, put the max value outside the loop. It's just cleaner.

 

Groeten, Wiebe.

wiebeCARYA_0-1709644464706.png

 

0 Kudos
Message 7 of 14
(943 Views)

Let's have a look at your VI:

 

  • Code could be dramatically simplified.
  • There should be no orange at all, because we are dealing with integers. (Use U64 if you like)
  • The max control terminal belongs outside the loop unless you want to read it with every iteration.
  • "delete from array" removes the last element, no need to wire the index.
  • Never ever(!!!) delete a label from a terminal. If you don't want to see the label, hide it on the front panel. An empty string as label is not useful!
  • Yes, you need an evet for the stop button.
  • Work on the code first. Don't waste time with decorations, micromanaging the front panel.

 

altenbach_0-1709655258696.png

 

0 Kudos
Message 8 of 14
(917 Views)

See if this can give you some ideas. Note that if you "tap" the wire before the addition, you correctly get the zero as first element and the last element that is smaller than the max value entered. No need to trim later. Your stop button must be latch action. I have no idea why you would change that.

 

altenbach_0-1709656926116.png

 

 

0 Kudos
Message 9 of 14
(912 Views)
Solution
Accepted by corned

Be aware that for very large inputs the while loop will never stop due to the magic of integer math. To protect from rollover, you need to check as follows:

 

altenbach_0-1709668257291.png

 

 

Now is is guaranteed to complete the loop when the numbers wrap and you can get all 94 elements that fit into U64 instantly (Max=18446744073709551615)

 

To go higher, you would need to implement bignum math.

 

 

altenbach_1-1709658523901.png

 

 

Message 10 of 14
(893 Views)