ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 07 Feb 2018 05:44:18 -0600How to generate a cyclic matrixhttp://ask.sagemath.org/question/41000/how-to-generate-a-cyclic-matrix/ How to generate all 8×8 cyclic matrix $A$ with the first row $(a_0, a_1, \ldots, a_7)$,
the matrix $A\in GL(8, 2)$ and the first row $a_0 + a_1 + \ldots + a_7 \neq 0$
Tue, 06 Feb 2018 12:22:26 -0600http://ask.sagemath.org/question/41000/how-to-generate-a-cyclic-matrix/Comment by omgggggg for <p>How to generate all 8×8 cyclic matrix $A$ with the first row $(a_0, a_1, \ldots, a_7)$,</p>
<p>the matrix $A\in GL(8, 2)$ and the first row $a_0 + a_1 + \ldots + a_7 \neq 0$</p>
http://ask.sagemath.org/question/41000/how-to-generate-a-cyclic-matrix/?comment=41007#post-id-41007A cyclic matrix means a circulant matrix.
We need the first row the property that the sum of entries is not zero so that this cyclic matrix could be a invertible matrix.Wed, 07 Feb 2018 01:38:44 -0600http://ask.sagemath.org/question/41000/how-to-generate-a-cyclic-matrix/?comment=41007#post-id-41007Comment by dan_fulea for <p>How to generate all 8×8 cyclic matrix $A$ with the first row $(a_0, a_1, \ldots, a_7)$,</p>
<p>the matrix $A\in GL(8, 2)$ and the first row $a_0 + a_1 + \ldots + a_7 \neq 0$</p>
http://ask.sagemath.org/question/41000/how-to-generate-a-cyclic-matrix/?comment=41002#post-id-41002What is a **cyclic** matrix?
Why should have the first row the property that the sum of entries is not zero? (It would maybe be enough to have a non zero row vector, if the question becomes clear.)Tue, 06 Feb 2018 16:09:44 -0600http://ask.sagemath.org/question/41000/how-to-generate-a-cyclic-matrix/?comment=41002#post-id-41002Answer by dan_fulea for <p>How to generate all 8×8 cyclic matrix $A$ with the first row $(a_0, a_1, \ldots, a_7)$,</p>
<p>the matrix $A\in GL(8, 2)$ and the first row $a_0 + a_1 + \ldots + a_7 \neq 0$</p>
http://ask.sagemath.org/question/41000/how-to-generate-a-cyclic-matrix/?answer=41008#post-id-41008Here are some possibilities to generate a circulant matrix, having as input its first row `a`:
def circulantMatrix0( a ):
n = len(a)
R = range(n)
return matrix( [ [ a[ (j-k) % n ] for j in R ] for k in R ] )
def circulantMatrix1( a ):
n = len(a)
R = range(n)
return matrix( [ [ a[j-k] for j in R ] for k in R ] )
def circulantMatrix2( a, field=GF(2) ):
n = len(a)
T = matrix( F, n, n, [1 if k==(j+1)%n else 0
for j in range(n)
for k in range(n) ] )
return sum( [ a[j]*T^j for j in range(n) ] )
def circulantMatrix3( a, field=GF(2) ):
n = len(a)
b = [a[j] for j in range(n)]
b = b+b
return matrix( n, n, [ b[n-j:2*n-j] for j in range(n) ] )
# Tests:
F = GF(2)
a = vector( F, 8, [1,0,0,0,1,0,0,1] )
A = circulantMatrix0(a)
B = circulantMatrix1(a)
C = circulantMatrix2(a)
D = circulantMatrix3(a)
Then we have:
sage: print A
[1 0 0 0 1 0 0 1]
[1 1 0 0 0 1 0 0]
[0 1 1 0 0 0 1 0]
[0 0 1 1 0 0 0 1]
[1 0 0 1 1 0 0 0]
[0 1 0 0 1 1 0 0]
[0 0 1 0 0 1 1 0]
[0 0 0 1 0 0 1 1]
sage: A==B and A==C and A==D
True
sage: A.charpoly().factor()
(x + 1)^8
sage: A.jordan_form()
[1 1 0 0 0 0 0 0]
[0 1 1 0 0 0 0 0]
[0 0 1 1 0 0 0 0]
[0 0 0 1 1 0 0 0]
[0 0 0 0 1 1 0 0]
[0 0 0 0 0 1 1 0]
[0 0 0 0 0 0 1 1]
[0 0 0 0 0 0 0 1]
sage:
Wed, 07 Feb 2018 02:30:27 -0600http://ask.sagemath.org/question/41000/how-to-generate-a-cyclic-matrix/?answer=41008#post-id-41008Comment by dan_fulea for <p>Here are some possibilities to generate a circulant matrix, having as input its first row <code>a</code>:</p>
<pre><code>def circulantMatrix0( a ):
n = len(a)
R = range(n)
return matrix( [ [ a[ (j-k) % n ] for j in R ] for k in R ] )
def circulantMatrix1( a ):
n = len(a)
R = range(n)
return matrix( [ [ a[j-k] for j in R ] for k in R ] )
def circulantMatrix2( a, field=GF(2) ):
n = len(a)
T = matrix( F, n, n, [1 if k==(j+1)%n else 0
for j in range(n)
for k in range(n) ] )
return sum( [ a[j]*T^j for j in range(n) ] )
def circulantMatrix3( a, field=GF(2) ):
n = len(a)
b = [a[j] for j in range(n)]
b = b+b
return matrix( n, n, [ b[n-j:2*n-j] for j in range(n) ] )
# Tests:
F = GF(2)
a = vector( F, 8, [1,0,0,0,1,0,0,1] )
A = circulantMatrix0(a)
B = circulantMatrix1(a)
C = circulantMatrix2(a)
D = circulantMatrix3(a)
</code></pre>
<p>Then we have:</p>
<pre><code>sage: print A
[1 0 0 0 1 0 0 1]
[1 1 0 0 0 1 0 0]
[0 1 1 0 0 0 1 0]
[0 0 1 1 0 0 0 1]
[1 0 0 1 1 0 0 0]
[0 1 0 0 1 1 0 0]
[0 0 1 0 0 1 1 0]
[0 0 0 1 0 0 1 1]
sage: A==B and A==C and A==D
True
sage: A.charpoly().factor()
(x + 1)^8
sage: A.jordan_form()
[1 1 0 0 0 0 0 0]
[0 1 1 0 0 0 0 0]
[0 0 1 1 0 0 0 0]
[0 0 0 1 1 0 0 0]
[0 0 0 0 1 1 0 0]
[0 0 0 0 0 1 1 0]
[0 0 0 0 0 0 1 1]
[0 0 0 0 0 0 0 1]
sage:
</code></pre>
http://ask.sagemath.org/question/41000/how-to-generate-a-cyclic-matrix/?comment=41010#post-id-41010P.S. Sorry, the `field` is declared as switch in two of the routines, the last one does not need it, please remove, the other one does not use the `field`, but the global `F`, please use the `field` as base field in the definition of the returned matrix.
The question is interesting! one up...Wed, 07 Feb 2018 05:44:18 -0600http://ask.sagemath.org/question/41000/how-to-generate-a-cyclic-matrix/?comment=41010#post-id-41010