LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I don't understand what this code does.

Can someone please tell me what this code does in some steps.Oefening 2 labview 2.png

0 Kudos
Message 1 of 7
(245 Views)

Can someone please tell me what this code does in some steps.

Oefening 3 labview 2.png

0 Kudos
Message 2 of 7
(228 Views)

When running, the Event will wait for the OnChange Event from the Numeric or Stop Button. If you hit the Stop button, then the While loop will be terminated.
If you change the number, then the inner While loop will run and perform some trivial computation. The shift register will hold the value between iterations and return it on the next iteration. These values will be shown in an array.
Usually, the OnChange Event from the Stop button is not combined with other events like numerics.
Preliminary the inner loop may never stop (because wire may never reach 1 exactly), depending on what values you have entered and the False case condition (which is not shown).
I would recommend recreating this in LabVIEW and simply run it and explore.

0 Kudos
Message 3 of 7
(223 Views)

It rather depends on what's going on in the False case of the Case Structure, but in very basic terms:

  1. Input a number (double-precision floating point)
  2. Divide the input number by 2
  3. If the remainder  is *exactly* zero, divide the input number by 2 and store this value
  4. If the remainder is not *exactly* zero, execute the False case
  5. Repeat the procedure using the stored value as the input number
  6. If at any point the input number is *exactly* one, stop the procedure

 

Given the name of the output terminal, it looks like this code is intended to test the Collatz conjecture in which case the False case will contain "multiply the input number by 3 then add 1 and store this value".  Since the conjecture applies to positive integers, you would be far better off using unsigned integer data types (for example, U32).

 

PsyenceFact

0 Kudos
Message 4 of 7
(219 Views)

I see that you've posted a similar question about similar code.  Is this some kind of homework?  Why not just run it and see?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 7
(219 Views)

The indicator names should give you a hint. The 1st one divides by 2 until you have all conjectures and the 2nd divides by 2 to get a list of all even numbers.

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 7
(187 Views)

@Noah_Steenkiste wrote:

Can someone please tell me what this code does in some steps.

 


No, we cannot, because a picture is an incomplete representation of the code. We cannot tell what's in the other cases (event or case structure).

 

Obviously, you must have found these programs somewhere and it would only be respectful to the original author to give a link and proper credit.

 

You posted two very different programs. the one with the event structure looks somewhat reasonable and seems to produce a Collatz sequence given a starting number. There are potential problems once you exceed the resolution of DBL precision numbers, for example above a certain very large number, every value will be divisible by two! Switching to an integer datatype could make things equally bad, so make sure to stick to reasonable inputs that are also guaranteed not fractional. Overall, it is fragile code.

 

The second code (without event structure) is a greedy while loop that operates on an array of numbers and checks them for even/odd (again, you need to ensure that the inputs are integers, so a blue datatype would be significantly more reasonable). Unfortunately, the picture shows the FALSE case that does nothing and we can only guess that the TRUE case probably appends the value to the initially empty array. Not sure why you think repeating the sample array processing millions of time per second, even if the input never changes, burning 100% of a CPU core is a good idea. For a better approach to get all even values, maybe you want to check with your classmates here.

0 Kudos
Message 7 of 7
(128 Views)