Answer the question
In order to leave comments, you need to log in
Why did Cramer's method fail?
Hello! I am writing my Cramer method in python. There was a problem with the formation of the following matrices. According to my logic, the code should work fine, because the argument of the defaultMatrix function does not change in any way, and only the variables that store the original array change, but the python thinks otherwise ... What could be wrong? Thanks
Here is the code:
def CramersRule(defaultMatrix, values):
matrix1 = defaultMatrix
for i in range(3):
matrix1[i][0] = -values[I]
matrix2 = defaultMatrix
for i in range(3):
matrix2[i][1] = -values[I]
matrix3 = defaultMatrix
for i in range(3):
matrix3[i][2] = -values[i]
# ...
Answer the question
In order to leave comments, you need to log in
defaultMatrix does not change in any way, but only the variables that store the original array change
import copy
matrix1 = copy.deepcopy(defaultMatrix)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question