Python to MATLAB accuracy

35 vues (au cours des 30 derniers jours)
Oliver Horrobin
Oliver Horrobin le 16 Sep 2020
Commenté : Oliver Horrobin le 18 Sep 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 commentaires
the cyclist
the cyclist le 16 Sep 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 le 18 Sep 2020
This was very helpfull, thankyou.

Connectez-vous pour commenter.

Réponse acceptée

James Tursa
James Tursa le 16 Sep 2020
Modifié(e) : James Tursa le 16 Sep 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?

Plus de réponses (0)

Catégories

En savoir plus sur Python Package Integration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by