Possible issue with multiplication of matrices
2 次查看(过去 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!