topic Re: Help adding elements in an array in LabVIEW
https://forums.ni.com/t5/LabVIEW/Help-adding-elements-in-an-array/m-p/3696893#M1039618
<P>Hmm. I just saw the earlier response, and my understanding of the Problem may be flawed. I thought the task was to add together the five numbers that were closest to 1000, but (as I was hinting) this is so simple that it is probably the "wrong question", namely find the five numbers in the set whose <U>sum</U> was closest to 1000. That's an interesting (and much more challenging) problem. </P>
<P> </P>
<P>Do you know about Permutations and Combinations? There are "10 Choose 5" or (by my back-of-the-envelope) 252 combinations to check. But the number doesn't really matter. What you need to do is something like this:</P>
<UL>
<LI>Figure out how to enumerate each of the combinations of 5 from the 10 numbers.</LI>
<LI>Associate with each combination their sum.</LI>
<LI>Find the 5 sums closest to 1000 (my erroneous interpretation of the original problem may suggest a way to do this).</LI>
</UL>
<P>Bob Schor</P>Mon, 02 Oct 2017 01:53:00 GMTBob_Schor2017-10-02T01:53:00ZHelp adding elements in an array
https://forums.ni.com/t5/LabVIEW/Help-adding-elements-in-an-array/m-p/3696882#M1039613
<P>I must create a program that generates 10 random numbers between 195 and 205, then add the 5 that together approach 1000 the closest. I already made a program that generates the numbers in an array, but I have no idea how to evaluate the numbers. Can anyone please help me?</P>Mon, 02 Oct 2017 00:12:05 GMThttps://forums.ni.com/t5/LabVIEW/Help-adding-elements-in-an-array/m-p/3696882#M1039613Yerry212017-10-02T00:12:05ZRe: Help adding elements in an array
https://forums.ni.com/t5/LabVIEW/Help-adding-elements-in-an-array/m-p/3696883#M1039614
<P>First, get rid of that local variable. It will get read before the indicator terminal receives data and the sum is thus meaningless. Just wire to the array coming from the FOR loop.</P>
<P> </P>
<P>To pick five that that have a sum closest to 1000, you need quite a bit more code. The brute force method would be to generate all possible ways to pick five out of 10 and pick the combination with the closest sum (there might be duplicate solutions, of course).</P>
<P> </P>
<P>(You also have a mathematical problem that the edge values in the selected range only have half the probability of the other values. Try to find a solution for that too)</P>Mon, 02 Oct 2017 01:29:20 GMThttps://forums.ni.com/t5/LabVIEW/Help-adding-elements-in-an-array/m-p/3696883#M1039614altenbach2017-10-02T01:29:20ZRe: Help adding elements in an array
https://forums.ni.com/t5/LabVIEW/Help-adding-elements-in-an-array/m-p/3696887#M1039615
<BLOCKQUOTE><HR /><LI-USER uid="585884"></LI-USER> wrote:<BR />
<P>I must create a program that generates 10 random numbers between 195 and 205, then add the 5 that together approach 1000 the closest. I already made a program that generates the numbers in an array, but I have no idea how to evaluate the numbers. Can anyone please help me?</P>
<HR /></BLOCKQUOTE>
<P>Well, I can't open your VI because I don't have a (working) PC with LabVIEW 2017 installed (I had two with LabVIEW 2017 installed, including this one, but they became "no-longer-working" and had to be rebuilt). So here are some things:</P>
<UL>
<LI>I assume you know how to generate 10 random numbers between 195 and 205.</LI>
<LI>Let's assume the array contains [200.1, 196.2, 203.2, 199.4, 197.3, 204.1, 198.3, 196.3, 198.5, 201.3].</LI>
<LI>Can you think of a quick way to answer the question "Which number is closest to 1000?"? Hint -- don't think about programming, think about answering the question.</LI>
<LI>Did answering the preceding question generate the "Aha! Moment" for you? Is the algorithm to answer your question now both simple and obvious?</LI>
</UL>
<P>Bob Schor</P>Mon, 02 Oct 2017 01:30:10 GMThttps://forums.ni.com/t5/LabVIEW/Help-adding-elements-in-an-array/m-p/3696887#M1039615Bob_Schor2017-10-02T01:30:10ZRe: Help adding elements in an array
https://forums.ni.com/t5/LabVIEW/Help-adding-elements-in-an-array/m-p/3696889#M1039616
<BLOCKQUOTE><HR /><LI-USER uid="95728"></LI-USER> wrote:</BLOCKQUOTE>
<BLOCKQUOTE>
<UL>
<LI>Can you think of a quick way to answer the question "Which number is closest to 1000?"? </LI>
</UL>
<HR /></BLOCKQUOTE>
<P>The question is which combination of 5 of the 10 numbers form a sum that is closest to 1000.</P>Mon, 02 Oct 2017 01:39:54 GMThttps://forums.ni.com/t5/LabVIEW/Help-adding-elements-in-an-array/m-p/3696889#M1039616altenbach2017-10-02T01:39:54ZRe: Help adding elements in an array
https://forums.ni.com/t5/LabVIEW/Help-adding-elements-in-an-array/m-p/3696893#M1039618
<P>Hmm. I just saw the earlier response, and my understanding of the Problem may be flawed. I thought the task was to add together the five numbers that were closest to 1000, but (as I was hinting) this is so simple that it is probably the "wrong question", namely find the five numbers in the set whose <U>sum</U> was closest to 1000. That's an interesting (and much more challenging) problem. </P>
<P> </P>
<P>Do you know about Permutations and Combinations? There are "10 Choose 5" or (by my back-of-the-envelope) 252 combinations to check. But the number doesn't really matter. What you need to do is something like this:</P>
<UL>
<LI>Figure out how to enumerate each of the combinations of 5 from the 10 numbers.</LI>
<LI>Associate with each combination their sum.</LI>
<LI>Find the 5 sums closest to 1000 (my erroneous interpretation of the original problem may suggest a way to do this).</LI>
</UL>
<P>Bob Schor</P>Mon, 02 Oct 2017 01:53:00 GMThttps://forums.ni.com/t5/LabVIEW/Help-adding-elements-in-an-array/m-p/3696893#M1039618Bob_Schor2017-10-02T01:53:00Z