11-20-2011 04:46 AM
I've noticed an issue when using arrays that have been defined using MathScript.
If I say enter A=0.1:0.1:3 then I get A=0.1, 0.2, 0.3...all the way up to and including 3.
However if I enter a larger final value, say A=0.1:0.1:10 then the array only goes up to 9.9.
Is there a deliberate reason for this or is it just some sort of bug?
James
Solved! Go to Solution.
11-20-2011 12:37 PM
James,
While I have not checked this with Mathscript, it is likely that what you are seeing is the common result of the finite representation of numbers in binary. Values like 0.1 are infinitely repeating fractions in binary. So when you sum 100 of them the accumulated error may be sufficient to cause the effect you have seen.
Lynn
11-21-2011 08:12 AM
I don't see what you are seeing. Are you doing this in a MathScript node, or the MathScript window? Which version of LabVIEW?
11-21-2011 08:49 AM
I'm using labview 2010 and a MathScript node.
See attached
11-21-2011 10:11 AM
I don't have the MathScript module for LV 2010, but I can tell you it does not happen in LV2011 (or 8.2 for that matter). One thing that seems odd about your image is that the "B" is on the wire, when it should be inside the box. Could be an artifact of whatever you used to capture the screenshot, though.
11-22-2011 04:03 AM
Just an update here,
If I save the vi and run it on other computers with exactly the same LabView build on them, it works! But it still wont work on mine.
I know other ways of defining arrays that work but I'd still like to know why this is happening.
11-24-2011 10:10 AM - edited 11-24-2011 10:10 AM
I've confirmed that the problem was indeed a cumulative error due to 0.1 not being exactly represented in binary. The data into and out of the Matscript node was single precision.
Switching to double solved the problem.
11-24-2011 08:23 PM
Jiminy,
Switching to double does not solve the problem - it just moves it several decimal points to the right. You may get the values you want for this particular problem, but in general the same issue exists.
Try generating an integer array from 1 to 30 and then divide it by 10. Compare the results to the array generated by your original code. Look at the attached VI and notice that you got lucky.
Lynn