ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 13 Mar 2016 12:46:20 +0100How to enumerate the generalised inverse of given matrix?https://ask.sagemath.org/question/32785/how-to-enumerate-the-generalised-inverse-of-given-matrix/ Let $A$ be a given singular matrix over a finite field. Then how to enumerate the solutions of the system of equation
$$Ax=b, b \in R(A), \text{range of } A $$
Since, $A$ is singular matrix I can find the generalized inverse $G$ (i.e., AGA=A) of $A$ . Note that, $Gb$ is one of the solution. And so the set of all solution can be written as
$$\{Gb+(I-GA)u: u \text{ is arbitrary }\}$$
Now, how to incorporate these ideas in sagemath?
I am a newbie to sagemath. So, the answerers kindly give me with the details.
Thanks in advance.Sun, 13 Mar 2016 07:30:30 +0100https://ask.sagemath.org/question/32785/how-to-enumerate-the-generalised-inverse-of-given-matrix/Answer by tmonteil for <p>Let $A$ be a given singular matrix over a finite field. Then how to enumerate the solutions of the system of equation</p>
<p>$$Ax=b, b \in R(A), \text{range of } A $$</p>
<p>Since, $A$ is singular matrix I can find the generalized inverse $G$ (i.e., AGA=A) of $A$ . Note that, $Gb$ is one of the solution. And so the set of all solution can be written as
$${Gb+(I-GA)u: u \text{ is arbitrary }}$$ </p>
<p>Now, how to incorporate these ideas in sagemath?</p>
<p>I am a newbie to sagemath. So, the answerers kindly give me with the details.</p>
<p>Thanks in advance.</p>
https://ask.sagemath.org/question/32785/how-to-enumerate-the-generalised-inverse-of-given-matrix/?answer=32795#post-id-32795There is an important mathematical notion for dealing with such problems : the **kernel** of a matrix, and i strongly suggest you to learn about it. If $K$ is the (right) kernel of $A$, if $x_0$ is a solution of the equation $Ax=b$, then the set of solutions of the equation is the set $x_0+K = \\{x_0+k \mid k \in K\\}$.
So, you can do the following:
Setting:
sage: A = random_matrix(GF(3),4,6) ; A
[2 1 2 2 0 2]
[2 2 0 1 2 0]
[0 2 2 1 2 2]
[2 0 0 1 0 2]
sage: b = vector(GF(3),(2,2,0,2)) ; b
(2, 2, 0, 2)
Find parameters $x_0$ and $K$:
sage: x0 = A.solve_right(b)
sage: x0
(1, 0, 0, 0, 0, 0)
sage: K = A.right_kernel() ; K
Vector space of degree 6 and dimension 2 over Finite Field of size 3
Basis matrix:
[1 0 1 1 0 0]
[0 1 2 1 0 1]
Enumerate solutions:
sage: solutions = [x0 + k for k in K] ; solutions
[(1, 0, 0, 0, 0, 0),
(2, 0, 1, 1, 0, 0),
(0, 0, 2, 2, 0, 0),
(1, 1, 2, 1, 0, 1),
(2, 1, 0, 2, 0, 1),
(0, 1, 1, 0, 0, 1),
(1, 2, 1, 2, 0, 2),
(2, 2, 2, 0, 0, 2),
(0, 2, 0, 1, 0, 2)]
You can check:
sage: for i in solutions:
....: print A*i
(2, 2, 0, 2)
(2, 2, 0, 2)
(2, 2, 0, 2)
(2, 2, 0, 2)
(2, 2, 0, 2)
(2, 2, 0, 2)
(2, 2, 0, 2)
(2, 2, 0, 2)
(2, 2, 0, 2)Sun, 13 Mar 2016 12:46:20 +0100https://ask.sagemath.org/question/32785/how-to-enumerate-the-generalised-inverse-of-given-matrix/?answer=32795#post-id-32795