Let us consider a system of linear equations :
$$
a_0+a_1+a_2+a_3=5
a_0+2a_1+4a_2+8a_3=14
a_0+3a_1+9a_2+27a_3=33
a_0+4a_1+16a_2+64a_3=5
$$
I want to solve this above system of equations over the integer modulo $p$, where $p$ is a prime number.
I have tried to solve this system of equations in python by using the following code, but it does not serve my purpose. Here is the code :
a = np.array([1,1,1,1],[1,2,4,8],[1,3,9,27],[1,4,16,64]])
b = np.array([5,14,33,68])
x = np.linalg.solve(a, b)
print(x)
It gives wrong answer. I have solved with Sage. It gives right answer : here is the code :
R = IntegerModRing(19)
M = Matrix(R, [[1,1,1,1],[1,2,4,8],[1,3,9,27],[1,4,16,64]])
b = vector(R, [5,14,33,68])
M.solve_right(b)
Answer : (0, 5, 18, 1)
How can I do the same in Python?
What I have tried:
I have tried to solve this system of equations in python by using the following code, but it does not serve my purpose. Here is the code :
a = np.array([1,1,1,1],[1,2,4,8],[1,3,9,27],[1,4,16,64]])
b = np.array([5,14,33,68])
x = np.linalg.solve(a, b)
print(x)
It gives wrong answer.