Possible issue with multiplication of matrices
조회 수: 6 (최근 30일)
이전 댓글 표시
Hi,
So I have a problem where I am calibrating a set of data by separately determined ratios; this data takes the form of a matrix and the calibration is done be a calculated scaling factor.
The issue that I am having is that the multiplication is resulting in a different value that what is should. The simple line I am using is:
x= x .* CALIB_ratios1(count_c);
Which if we take an example value, if the value of x is 541 and CALIB_ratios1(count_c) is 1.6210 then the value should be 876.961, whereas the code is giving me 876.9758. This may not seem like much however this is occurring over many thousands of instances, making the final results (determined partially from summing all results) to be wrong.
All values are currently single precision, I have tried converting them to double and float yet the issue still arises.
Any help as to why these numbers are not entirely exact would be appreciated.
Thanks
댓글 수: 5
Stephen23
2016년 7월 6일
편집: Stephen23
2016년 7월 6일
"doesn't solve the issue" What issue? There is no issue with this multiplication because MATLAB is correctly multiplying the numbers that you have shown us:
>> format longg
>> 541 .* 1.6210 % what your question says that you have, but you don't really.
ans =
876.961
>> 541 .* 1.6210273504257202 % what you really have (from your comment above).
ans =
876.975796580315
The answer of 876.9758 (to four decimal places) is perfectly correct.
Note that changing to single doesn't make any significant [sic] difference:
>> single(541) .* single(1.6210273504257202)
ans =
876.9758
>> fprintf('%.30f\n',ans)
876.975769042968750000000000000000
Perhaps there are issues with your code, but this multiplication isn't one of them.
답변 (1개)
Torsten
2016년 7월 6일
You should print CALIB_ratios1(count_c) in full precision. My guess is that it is something like 1.621027357.
Best wishes
Torsten.
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!