취소
다음에 대한 결과 표시 
다음에 대한 검색 
다음을 의미합니까? 

Defining arrays in MathScript

해결 완료!
솔루션으로 이동

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

0 포인트
1/8 메시지
3,417 조회수
솔루션
주제 작성자 Jiminy이(가) 승인함

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

2/8 메시지
3,406 조회수

I don't see what you are seeing. Are you doing this in a MathScript node, or the MathScript window? Which version of LabVIEW?

0 포인트
3/8 메시지
3,397 조회수

I'm using labview 2010 and a MathScript node.

 

See attached

0 포인트
4/8 메시지
3,395 조회수

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.

0 포인트
5/8 메시지
3,379 조회수

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.

 

0 포인트
6/8 메시지
3,357 조회수

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.

0 포인트
7/8 메시지
3,339 조회수

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

 

0 포인트
8/8 메시지
3,325 조회수