LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

tunnels on labview

Solved!
Go to solution

plz could someone help how i can generate 10 random numbers and display their sum as well as the 5th random number generate.  

0 Kudos
Message 1 of 13
(227 Views)

I would start with the training resources listed at the top of the forum. (...and what does this have to do with tunnels?).

 

Start simple and go from there?

 

  1. Generate one random number.
  2. Generate 10 random numbers. (What would be a good data structure? Hint: array! How do repeat some code N times, where you know N from the beginning? Hint: FOR loop)
  3. Take the sum of these 10 random numbers. Look in the numeric palette for a reasonable function.
  4. How do you get the 5th element out of an array? (hint: index array)

LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 2 of 13
(213 Views)

thank you for ur reply the problem that i try to solve it:

  • For this problem we want to generate 10 random numbers and display their Sum as well as the 5th Random Number generated. Build this program using only the following LabVIEW elements:
  •  For Loop
  • Two Integer Constants
  •  An “Equal to” Function
  •  Any of the Random Number Generators (you can use any range of numbers)
  •  The “Add Array Elements” Function
  •  A Numeric Indicator to display the Sum
  • A Numeric Indicator to display the 5th Random Number Generated
0 Kudos
Message 3 of 13
(153 Views)

so... how far did you get?

 

  • Did you figure out how to start LabVIEW?
  • Did you find the diagram window?
  • Did you find all these items in the palettes?
  • Did you place them on the diagram?
  • Did you ponder how things should be arranged and connected?
  • Can you show us your partial efforts?

 

Nobody here will do your homework, but we are willing to help answer specific questions? Do you have a specific questions?


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 4 of 13
(148 Views)

i states the problem to clarify why i mention the tunnels  because i need to use the for loop. i built the program but i don't know how to generate the 5th random number and how to generate the sum with "add array element" function

0 Kudos
Message 5 of 13
(139 Views)
Solution
Accepted by topic author jiji_830

You might be "overthinking" this.  Suppose you can generate 10 random numbers, and you figure out how to get them all into an array.  Your "statement of the problem" says you should use the "Add Array Elements" function -- do you have an Array to give to this function?  You are taking a LabVIEW class -- did you learn anything about the functions on the Array Palette?  Do you know how to use the LabVIEW Help to get LabVIEW to tell you what the functions do, and how to use them?  Fortunately for you, LabVIEW has made "creating an Array using a For Loop" much easier than it used to be (I think this "new feature" is now around 10 years old ...), and For Loops "do this by default".

 

How will you know that your code works?  Simple -- run it and see!  Now, granted, seeing if the sum is correct is "hard" (adding 10 numbers "by hand" -- ugh!), but seeing if the number you think is the 5th agrees with looking at the entire array and counting (1, 2, 3, 4, 5) and seeing if it really is the 5th (and not, say, the 6th) is pretty easy.

 

But a way to make the whole example even easier is to make a small variation in the problem and turn it into one you can do in your head.  Here are two variations that you can try (more practice for you, and a "feel-good" feeling when you "get the right answer" --

  1. Generate an array of 10 numbers all equal to 1.0.  Return the sum and the 5th element.  [Do it with LabVIEW, and also do it "in your head" and be sure LabVIEW returns the "right answer"].
  2. Generate an array of 10 numbers, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.  Return the sum and the 5th element.  Can you do both the sum and the 5th element "in your head"?  If you had High School Algebra, you learned how to sum an arithmetic series ...

So if you solve the original Homework Problem, then write two additional little LabVIEW routines to do "simpler" problems, you get 3 times the training in creating and using For Loops and Arrays, and will give you more confidence in your LabVIEW skills, and maybe suggest that sometimes you can "solve a simpler problem first" to be sure you understand what's going on.

 

Bob Schor

 

Bob Schor

0 Kudos
Message 6 of 13
(125 Views)
Solution
Accepted by topic author jiji_830

Use an autoindexing output tunnel on your FOR loop to build up the array of random numbers.  After that, you can use Index Array to get a specific element and use the Add Array Elements to get the total sum.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 13
(125 Views)

Thank you for your help . it works 😊

0 Kudos
Message 8 of 13
(114 Views)

thank you so much. 

0 Kudos
Message 9 of 13
(109 Views)

@crossrulz wrote:

Use an autoindexing output tunnel on your FOR loop to build up the array of random numbers.  After that, you can use Index Array to get a specific element and use the Add Array Elements to get the total sum.


I agree that this is the right way to do this, but Index Array is not one of the allowed structures. The teacher has made this unnecessarily complicated and will likely lead the students into poor habits.

 

In order to do this using only the prescribed elements I would use a conditional tunnel and make the condition TRUE when i=4 (the fifth element in the array). Right click on the output and make it a single element then select conditional. Wire the result of the comparison to the conditional terminal.

0 Kudos
Message 10 of 13
(80 Views)