Borrar filtros
Borrar filtros

Possible issue with multiplication of matrices

3 visualizaciones (últimos 30 días)
David
David el 6 de Jul. de 2016
Editada: Stephen23 el 6 de Jul. de 2016
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 comentarios
David
David el 6 de Jul. de 2016
Similar to what I stated to the other answer on this question; treating the numbers to a higher precision doesn't solve the issue.
The final value (which is essentially the sum of all these "calibrated" values divided by a different factor) is an order of magnitude out (6.156e+4 instead of 1.7412e+5).
My thoughts were that it could be the act of this multiplication (or my handling of it?) could be causing the issue. This isnt a simple print precision issue.
Stephen23
Stephen23 el 6 de Jul. de 2016
Editada: Stephen23 el 6 de Jul. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Torsten
Torsten el 6 de Jul. de 2016
You should print CALIB_ratios1(count_c) in full precision. My guess is that it is something like 1.621027357.
Best wishes
Torsten.
  1 comentario
David
David el 6 de Jul. de 2016
Treating things to a higher precision doesn't seem to fix the issue. As when looking at the final results (which are essentially the sum of all this calibrated data, divided by another factor), the values are orders of magnitude out.
Example being 6.156e+4 instead of the value it should be which is 1.7412e+5. I feel the multiplication of this data (or maybe by handling of it?) is causing issues.
Thanks

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by