Python to MATLAB accuracy

31 visualizaciones (últimos 30 días)
Oliver Horrobin
Oliver Horrobin el 16 de Sept. de 2020
Comentada: Oliver Horrobin el 18 de Sept. de 2020
Hi, so I am translating code from Python to MATLAB and I am using very presice numbers in my calculations.
I am getting very small differences which have a very large impact on the final result. I need the MATLAB code to function the same as the Python.
For example, the numbers from Python are: mu20= 10.1859163332|80940 & mu02= 10.1859163332|81872
And the supposedly same numbers in MATLAB are: mu20 =10.1859163332|72582 & mu02 =10.1859163332|72116
As you can see the last 5 numbers in both are different. Is there anyway to make it so that they are the same in MATLAB as they are in Python?
Cheers,
Ollie
  2 comentarios
the cyclist
the cyclist el 16 de Sept. de 2020
For your current python calculation, do you have reason to believe that those trailing 5 digits are meaningful? If you are doing the python version as 64-bit floating-point, then I would assume they are not. It seems possible to me that you have a case of false precision.
And if that is the case, and if differences beyond 12 digits of precision are causing very large impact on your final result, then I'd question whether your final result is meaningful.
If your python result is such that you know all of those digits are meaningful, then 64-bit MATLAB (or 64-bit anything) calculations are not going to be able to replicate it.
Oliver Horrobin
Oliver Horrobin el 18 de Sept. de 2020
This was very helpfull, thankyou.

Iniciar sesión para comentar.

Respuesta aceptada

James Tursa
James Tursa el 16 de Sept. de 2020
Editada: James Tursa el 16 de Sept. de 2020
Probably not. The trailing bits of floating point calculations in general can't be trusted. It you change the order of the calculations even slightly, differences in results should be expected. Depending on what your calculations are, you may not be able to control this order of calculations. What exactly are the calculations you are doing? Are you sure you are starting with the exact same values in both cases? Any algorithm that depends on the trailing bits of floating point calculations raises red flags ... is your algorithm and data really reliable to that precision?

Más respuestas (0)

Categorías

Más información sobre Python Package Integration 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