Ask Your Question
3

Solving system of linear equations over GF(2)

asked 2016-01-10 16:02:14 +0100

giliev gravatar image

I tried solving system of equations using Matrix's solve_right(x) method. However, I want to check if the solution is unique. How can I achieve this? For a square matrix I do it by checking if A.determinant() != 0 (where A is the coefficients matrix). Is there some built in function to test uniqueness of matrix equation solution? I would like to return the solution if it is unique and show a message if there is no solution, or multiple solutions exist.

Thank you in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2016-01-10 20:00:41 +0100

tmonteil gravatar image

updated 2016-01-12 09:41:31 +0100

You should use the kernel of a linear map (or a matrix, in which case you should specify whether the action is left or right). Both are implemented in Sage.

Here is an example:

sage: A = random_matrix(ZZ,3,4)
sage: A
[  1  -3  -2   0]
[  2   1   1  -1]
[-31   1 -12   1]

sage: b = vector((1,1,1))
sage: a = A.solve_right(b)
sage: a
(26/29, 43/29, -66/29, 0)
sage: A*a == b
True

So, in this case there is a solution to the equation you are trying to solve (if there is no solution, Sage will raise a ValueError: matrix equation has no solutions, so you have to use a try: except: statement to deal with that).

Now, the set of solutions is the set of a+c where c belongs to the kernel of A. You can get this kernel as follows:

sage: K = A.right_kernel()
sage: K
Free module of degree 4 and rank 1 over Integer Ring
Echelon basis matrix:
[ 37  69 -85  58 ]

And check the previous statement:

sage: k = K.basis()[0]
sage: k
(37, 69, -85, 58)
sage: A*k
(0, 0, 0)
sage: A * (a+k) == b
True
sage: A * (a+42*k) == b
True
edit flag offensive delete link more

Comments

Hi, is there away to calculate the kernel of a matrix over integer ring. I have a matrix over Z6, And I want to know the solutions of Ax=b, but the right_kernel() methods returns "NotImplementedError: Echelon form not implemented over 'Ring of integers modulo 6'."

levi gravatar imagelevi ( 2023-04-10 05:12:15 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-01-10 16:02:14 +0100

Seen: 2,803 times

Last updated: Jan 12 '16