Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python and Matlab differences in linear algebra calculates

I need to write a program for linear algebra calculates. I switched from Matlab to python and worked with numpy and scipy. There are some small differences in precision between Python and Matlab which cause different result in the end. For example for the matrix

A =[2       -25,
    -25     -622]

in Matlab det(A) = 627.0 while in python it is 626.9999999999978. When I check the variables, these tiny differences for all the variables will significantly change the results. what shall I do?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Floating points are finicky. When you run into precision problems
you can examine the numbers here:

Floating point representation of 626.9999999999978

In this case 626.9999999999978 is 627.
Admitted the number formatter could have done a better job.

For more advice on floating point numbers:
https://floating-point-gui.de/errors/comparison/

If you know that all you matrix entries are integers,
then consider using a representation of matrices
that doesn’t use floating points.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading