Skip to content
Advertisement

I rewrite a matlab code in python but they result different outputs

the matlab code and the output i was expecting (gauss elimination method)

my code in python:

JavaScript

the output i got:

JavaScript

Advertisement

Answer

Your problem is related to casting. Without info, numpy cast your matrix to integer numbers, so when you divide, the result is not a float. For example 2 / 6 = 0 and not 0.33333. If you put

JavaScript

your result will be

JavaScript

In matlab there is not this problem because your starting matrix is already casted to floating point numbers.

Advertisement