LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you look in a 5x5 matrix for the prime numbers that are in it?

I  have a 5x5 matrix full of 1-25 in order, but they ask me to look for the prime numbers that are inside it and to store them in another array, I could not do it

0 Kudos
Message 1 of 9
(3,228 Views)

Tengo una matriz 5x5 llena de 1-25 en orden, pero me piden que busque los numeros primos que estan dentro de ella y los consigne en otro array, no he podido hacerlo 

0 Kudos
Message 2 of 9
(3,215 Views)

Since I don't have LabVIEW 2017, I can't directly comment on your homework problem.  However, it seems to be to be designed to ask if you can do the following tasks:

  • Write code that isolates each of the 25 elements of the 5x5 2D array (you should know how to access array elements one at a time).
  • Write code that, given a number, determines whether or not it is a prime.  To do this, you need to know something about numbers, Prime numbers, how to tell if a number is Prime or not.
  • Given a series of numbers and a test that says "This number is a member of the Output Set" (or not), collect the numbers that are part of the Output Set.

I would think that if you read all of the tutorial material you can find on For loops, Arrays, and output tunnels, you should have no trouble with this assignment.  If I do it for you, you won't learn anything.

 

Bob Schor

0 Kudos
Message 3 of 9
(3,221 Views)

I send you the 2015 version, it did not really manage to just identify the prime numbers. I'm missing that from the exercise

0 Kudos
Message 4 of 9
(3,214 Views)
 
 
 
 
 
Can you tell me the functions with which that is done? Actually I am learning to use the program, and I have come a long way, however I have tried and I have not found the answer
0 Kudos
Message 5 of 9
(3,208 Views)

Hi Daniavt,

 

I  have a 5x5 matrix full of 1-25 in order,

You create an array. As a matrix is something different in LabVIEW please use the correct term "array" as well as array functions…

Hint: to make your live easier you could also use a 1D-array containing the number 1 to 25 and only reshape the array for UI display!

 

they ask me to look for the prime numbers that are inside it and to store them in another array,

Who is "they" and why did "they" ask you?

Hint: check each of those numbers for being prime (LabVIEW has a function for this!). Output only the primes into a new array.

 

I could not do it

What have you tried so far?

Did you develop an algorithm - on a sheet of paper?

Did you take the beginner lessons to learn LabVIEW? (Did you notice those tutorials mentioned in the header of this LabVIEW board?)

Did you take any "computer science" (aka programming) lessons at all?

 

Hints:

- Use a 1D array to hold your numbers.

- Use an autoindexing FOR loop.

- Use the "Check Prime" function.

- Use a conditional output tunnel of the FOR loop.

With those 4 hints your are (nearly) done with your task!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 9
(3,183 Views)

Follow GerdW's hints.  If any step sounds "mysterious" to you, go back to the Tutorials, or read the Help descriptions from Array functions, or use Quick Drop (what's that, you ask?  Do a Web Search) to find the function.

  • You have a 2D Array.  How do you get a 1D Array from it?
  • Do you know what "Autoindexing" means for a For Loop?  If not, back to the Tutorials ...
  • I, myself, didn't know about the "Check Prime" function ...
  • It's not clear to me in what form you need the output, but you should be able to get a Boolean (Prime?) for each of the Array elements you test, and thus be able to create the proper Output structure.

Give it a try.  I would definitely start with a new, blank, VI and try to do things slowly, methodically, etc.  I must confess I didn't see in the code you submitted any indication of progress towards solving this particular problem ...

 

Bob Schor

0 Kudos
Message 7 of 9
(3,161 Views)

Looking at your code:

  • recognizing prime numbers should not depend on the shape of the array.
  • I don't see any code that has anything to do with prime numbers.
  • Ever wonder what would happen if you remove the "=true" and just wire directly?
  • What is the purpose of the case structure? Makes no sense.
  • Your loop is spinning as fast as the computer allows, repeating the same thing over. Once is enough!
  • Don't use matrix operations on 2D arrays.
  • Prime numbers are integers, there should be no orange anywhere!
  • None of your local variables are needed. Just place the terminals outside the case structure.
  • You don't define what "store them in another array" is. There are millions of possibilities.

 

0 Kudos
Message 8 of 9
(3,157 Views)

@Daninavt wrote:

I  have a 5x5 matrix full of 1-25 in order, but they ask me to look for the prime numbers that are inside it and to store them in another array, I could not do it


So, what's the focus of this exercise? Is it about array manipulations or prime numbers?The answer will make a big difference here!

 

Yes, as has been said, LabVIEW now has the "check prime?" function, which is quite good. (Introduced in LabVIEW 2015). However, maybe you should roll your own, start with my 2016 NI Week talk. In one slide I compare many different ways to deal with prime numbers, so maybe you can learn something. The "dumb" algorithm is probably all you need :D)

 

I really have absolutely no idea what the purpose of all your numeric scalar controls are. They make no sense for this problem. Why are they even there?

0 Kudos
Message 9 of 9
(3,145 Views)