04-22-2024 08:48 AM
04-22-2024 09:03 AM
Can someone please tell me what this code does in some steps.
04-22-2024 09:09 AM
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.
04-22-2024 09:11 AM
It rather depends on what's going on in the False case of the Case Structure, but in very basic terms:
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
04-22-2024 09:13 AM
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?
04-22-2024 09:50 AM
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.
04-22-2024 01:32 PM - edited 04-22-2024 01:34 PM
@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.