Search code examples
mathsequencefibonaccilabview

LabVIEW help explain simple Fibonacci sequence


I have an assignment due for my LabVIEW class that involves a Fibonacci sequence, here is the exact question:

Create a VI that uses a WHILE loop to keep calculating iterations of a Fibonacci sequence until the ratio of |fib(n-1)/fib(n) - fib(n-2)/fib(n-1)| converges. Inputs should include the first two elements of the sequence and the magnitude of the convergence. The output should be the number of iterations required to converge.

I looked on Wikipedia, that didn't help. I have done some Googling around and still nothing. I don't understand what a Fibonacci sequence is nor do I know how to make it converge. Where do the two user inputed elements come in and what of the magnitude. I can code it but I don't what I am to code. If you understand please explain it to me.

To be clear I don't really want you to give me the code, just clarification; thanks.


Solution

  • You probably need something in that style. Try translating the following Python code into LabVIEW. Use shift registers in while loop. :

    import math
    ordofmag = 4
    result = 1
    n = 0
    while result >= ( 10 ** (-ordofmag) ):
      n = n + 1
      if n == 1 or n==2:
        x0 = 1.0     # fib(n)
        x1 = 1.0     # fib(n+1)
        x2 = x1 + x0 # fib(n+2)
        result = math.fabs(x1/x2 - x0/x1)  
      elif n > 2:
        x2 = x1 + x0
        result = math.fabs(x1/x2 - x0/x1)  
        x0 = x1
        x1 = x2
      print int(x1), round(result,ordofmag)