Possible issue with multiplication of matrices
Afficher commentaires plus anciens
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 commentaires
Please show us exactly what these two commands print:
fprintf('%.30f\n',x)
fprintf('%.30f\n',CALIB_ratios1(count_c))
Note that just like any computer language, the displayed and the stored values are two different things:
>> 876.9758 / 541 % displays five significant figures only!
ans = 1.6210
>> sprintf('%.30f',876.9758 / 541)
ans = 1.621027356746765235584462061524
For a more accurate representation of the stored value, you should use this FEX submission:
David
le 6 Juil 2016
Stephen23
le 6 Juil 2016
Is 1.6210273504257202 equal to 1.6210 ?
David
le 6 Juil 2016
"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.
Réponses (1)
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!