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.Fri, 19 Jan 2024 06:18:53 +0100How can I construct matrices over the octonions?https://ask.sagemath.org/question/75557/how-can-i-construct-matrices-over-the-octonions/Using QuaternionAlgebra, I can make and multiply matrices with quaternionic entries without difficulty.
Using OctonionAlgebra, if I try to make a matrix I get a type error telling me that my algebra is not a ring.
So far as I can track it down, Matrix_Spaces runs a test asking whether the algebra is in Rings.
QuaternionAlgebras are; OctonionAlgebras are not.
Is there a reasonable way to work around this issue? Manually add my octonion algebra to Rings? Disable the type check in Matrix_Spaces?? Something else?TDFri, 19 Jan 2024 06:18:53 +0100https://ask.sagemath.org/question/75557/Compute facts about moduleshttps://ask.sagemath.org/question/73963/compute-facts-about-modules/ I am new to programming in general but in my project, I am required to work with a finite set π={π΄_1,...,π΄_π}
of πΓπ
matrices over a finite ring π
, and the submodule π
they generate. To be more specific, I would like to compute facts such as: Maximal lin. indep. set of columns for each matrix, maximal lin. indep. subset of π
, minimal generating set of π
, span of S, length of π
and a composition series if it exists, and free rank of largest free submodule of π
(or possibly the set of all submodules/free submodules of π
, which is finite since π
and π
are finite). However, while browsing through the documentation in the Sage website, I found very little in terms of commands that compute the above facts for suitable π
, could someone point out a package or set of commands that compute (some of) the above stuff? I apologize in advance if the question violates forum rules.ExtraJokerFri, 20 Oct 2023 14:23:13 +0200https://ask.sagemath.org/question/73963/Column space of a matrixhttps://ask.sagemath.org/question/73746/column-space-of-a-matrix/Hello Everyone,
I am new to Sage, and I am trying to use its linear algebra capabilities.
As a first exercise, I am trying to compute the column space of a matrix:
A = matrix([[1,3,8],[1,2,6],[0,1,2]])
According to the documentation, the column space of A is given by A.column_space(). This function returns me:
- Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[ 1 0 1]
[ 0 1 -1]
when I was expecting
[1 3]
[1 2]
[0 1]
I clearly missed something. Any clues? With Maxima, I got the expected colum space.
I thank you in advance for any help.
Best,
alefWed, 04 Oct 2023 08:23:15 +0200https://ask.sagemath.org/question/73746/Factorizing matrix entries that are polynomialshttps://ask.sagemath.org/question/72850/factorizing-matrix-entries-that-are-polynomials/Suppose i have a polynomial matrix like:
var('x')
g=graph.CompleteGraph(4)
h=g.am()
t=h-x*identity_matrix(4)
t1=t.adjugate()
t1
Then, how do i get `t1` in the factorized/simplified form. Specifically, I see that there are exactly two distinct entries in `t1`, and each of them can be factorized into two distinct monomial powers. But, how do I get this directly, without having to factorize each element separately. Any hints? Thanks beforehand.
vidyarthiTue, 22 Aug 2023 14:25:39 +0200https://ask.sagemath.org/question/72850/Extracting specific rows of a matrixhttps://ask.sagemath.org/question/72581/extracting-specific-rows-of-a-matrix/ Suppose I have a matrix `A` which is `m x n` in order. How do I extract a submatrix of specified rows and colums from `A`. Like I want a `p x q` submatrix of `A`. Will the `expanded_submatrix` method help in this regard? Thanks beforehand.vidyarthiWed, 16 Aug 2023 00:46:36 +0200https://ask.sagemath.org/question/72581/How to control counters generating a matrix with lambda?https://ask.sagemath.org/question/68761/how-to-control-counters-generating-a-matrix-with-lambda/I am trying to generate this famous matrix without the expected diagonal of 1's. So the expected output is as follows:
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
[1,] 1 0 0 0 0 0 0 0 0 0 0
[2,] 1 2 0 0 0 0 0 0 0 0 0
[3,] 1 3 3 0 0 0 0 0 0 0 0
[4,] 1 4 6 4 0 0 0 0 0 0 0
[5,] 1 5 10 10 5 0 0 0 0 0 0
[6,] 1 6 15 20 15 6 0 0 0 0 0
[7,] 1 7 21 35 35 21 7 0 0 0 0
[8,] 1 8 28 56 70 56 28 8 0 0 0
[9,] 1 9 36 84 126 126 84 36 9 0 0
[10,] 1 10 45 120 210 252 210 120 45 10 0
[11,] 1 11 55 165 330 462 462 330 165 55 11
I generated it with the following loop in R:
n = 11
asymmetric.lower.triang.Pascal = matrix(0,n,n)
for(i in 1:n){
for(k in 0:(i-1))
asymmetric.lower.triang.Pascal[i,k+1] = choose(i,k)
}
I can generate the Pascal matrix in SageMath with the loop:
r = 10
matrix(ZZ, r, lambda i, j: binomial(i, j))
[ 1 0 0 0 0 0 0 0 0 0]
[ 1 1 0 0 0 0 0 0 0 0]
[ 1 2 1 0 0 0 0 0 0 0]
[ 1 3 3 1 0 0 0 0 0 0]
[ 1 4 6 4 1 0 0 0 0 0]
[ 1 5 10 10 5 1 0 0 0 0]
[ 1 6 15 20 15 6 1 0 0 0]
[ 1 7 21 35 35 21 7 1 0 0]
[ 1 8 28 56 70 56 28 8 1 0]
[ 1 9 36 84 126 126 84 36 9 1]
but I want to get rid of the diagonal of 1's with the same manipulation of the counters or indices I used above. I have no idea what `lambda` does, having found the basic code for matrix construction in SageMath online. So the question amounts to whether I could make `i` run from `1` to `n` while `j` runs from `0` to `n - 1` or viceversa.toniSat, 27 May 2023 04:02:57 +0200https://ask.sagemath.org/question/68761/sagemath 9.8 matrices do not display properly in Jupyter notebookshttps://ask.sagemath.org/question/67814/sagemath-98-matrices-do-not-display-properly-in-jupyter-notebooks/ My sagemath 9.8 is not displaying matrices properly in jupyter notebooks. when launching sage from the command line using sage-n on a notebook that contains matrices the notebook loads with no problem but the matrices only display the normal size parentheses around the middle row of each matrix with no scaling. This occurred after I upgraded my Fedora
37 install to F38. does anyone know why this is happening. I had no problem with this before the upgrade. Thanks for any help.jimb417Sun, 23 Apr 2023 09:14:40 +0200https://ask.sagemath.org/question/67814/Accelerating for-loophttps://ask.sagemath.org/question/67524/accelerating-for-loop/I have a loop like
n = 3
M = MatrixSpace(Integers(n),n)
L = []
for m in M:
if condition:
L += [m]
In the case $n=3$, there are $3^{3^2} = 19683$ such matrices in `M`, which the computers nowadays can do within a few seconds, but if $n=4$, there are already $4^{4^2} β 4.3\cdot10^9$ matrices in `M` to check, but I expect only about 100 hits (i.e. such `m` for which the condition is true). Is there a faster way to make this possible, for example by parallelization?ThrashThu, 13 Apr 2023 00:21:33 +0200https://ask.sagemath.org/question/67524/How to get selective outputs printedhttps://ask.sagemath.org/question/67158/how-to-get-selective-outputs-printed/After running my code
> -------------------
-------------------
if................
show((x,y,z))
The output is a collection of list of triplets of square matrices of same order.
I want only those output to be printed which contain same set of three matrices, keeping the first matrix fixed.
That is, for example, suppose I am getting the following outputs:
1.[A1,P,Q]
2.[A1,Q,P]
3.[P,Q,A1]
4.[A2,L,M]
5.[A2,M,L]
6.[A2,X,Y]
7.[Q,L,A1]
Now consider the first three outputs . The first two outputs are to be considered same. But the third output is to be considered different, though all three outputs contain same set of matrices. So, first and third need only be printed.. Similarly , as fourth and fifth outputs are same, I want only fourth output to be printed and not the fifth one. And so onβ¦
mak3521Thu, 30 Mar 2023 08:34:25 +0200https://ask.sagemath.org/question/67158/Regarding remove() functionhttps://ask.sagemath.org/question/66881/regarding-remove-function/ I want to remove all symmetric matrices from the list of all possible 0,1 matrices of (say) 2nd order.
When I run this code, not all symmetric matrices are removed. Where am I wrong?`
>
T=Tuples((0,1),4)
W=[matrix(2,2,v) for v in T]
[W.remove(s) for s in W if s.is_symmetric() is true]
show(W)
mak3521Sat, 11 Mar 2023 13:11:21 +0100https://ask.sagemath.org/question/66881/Is it no longer possible to calculate SVD in sage?https://ask.sagemath.org/question/66289/is-it-no-longer-possible-to-calculate-svd-in-sage/ I recently noticed that the property `.SVD()` is no longer available for matrices defined over the `RDF` ring.
Is it no longer possible to calculate singular value decomposition in sage?more_weightWed, 08 Feb 2023 18:32:57 +0100https://ask.sagemath.org/question/66289/How to speed up this codehttps://ask.sagemath.org/question/65274/how-to-speed-up-this-code/Given a square matrix M, to find (say) five sets of, (say) 4 matrices A1,A2,A3,A4 such that
(i) each Ai is a unique 0,1 or 0,-1 matrix
(ii) each Ai is not - all zeroes or all ones or all minus ones matrix(that is, matrices with all entries same are not allowed)
(iii) M= A1+A2+A3+A4
(iv) Each matrix product AiAj (i,j=1,2,3,4)is a linear combination of A1,A2,A3,A4 with integer coefficients.
This is the same problem which was discussed in :
https://ask.sagemath.org/question/64286/cant-find-error-in-my-code/
But there we wanted βall possible combinationsβ satisfying the required conditions. There we basically discussed the process for first getting all combinations satisfying (iii) and then checked condition(iv). But for 3rd order and above no output even after one week.
So thought that rather than first collecting all combinations satisfying(iii) it would be better to check (iv) alongside individually and after say, five outputs , the program ends, as even this much would also help me for my work .
I have made the following code:
#Given Matrix
M = matrix(2,2, [1, 2, 2, -1])
show("M=",M)
n = int(input("Enter the order of the matrix M : "))
T = Tuples((0,1),(n^2))
#Removing all-zero and all-one tuples as not needed for our case"
R=T.list()[1:-1]
#Forming n by n matrices from list in R. Contains all {0,1 }matrices.
P = []
for v in R:
P.append(matrix(ZZ,n,n,v))
#Forming all n by n , {0,-1} matrices.
N=[]
for a in P:
b=-a
N.append(b)
test_sum = int(input("In how many matrices you want to break M :"))
num_nonneg = int(input("How many matrices with non-negative entries you want :"))
num_nonpos = (test_sum)-(num_nonneg)
nonneg_comb = Combinations(P, num_nonneg)
nonpos_comb = Combinations(N, num_nonpos )
#Defining a function which converts matrix to vector
def mat_to_vector(m):
return vector( sum(map(list,m.rows()), []), immutable=True )
Counter=0
X = ZZ^(n^2)
for a in nonneg_comb:
for b in nonpos_comb:
flag=0
V = X.span(mat_to_vector((a+b)[i]) for i in range(len((a+b))))
for i in range(test_sum):
for j in range(test_sum):
if( (sum(a+b)!=M) or (mat_to_vector((a+b)[i]*(a+b)[j]) not in V)):
flag=1
if(flag==0):
Counter+=1
show("(",Counter,").", a+b)
if Counter==5:
break;
But this is also time taking for higher orders. So, wanted to know how it can be speeded up or how the code given by Max Alekseyev in the above link can accordingly be edited.sgmthThu, 08 Dec 2022 06:13:33 +0100https://ask.sagemath.org/question/65274/Forming unique collections of matriceshttps://ask.sagemath.org/question/64630/forming-unique-collections-of-matrices/I am facing following two similar kind of problems:
Problem(1) Suppose I have the following code:
A=matrix(2,2,[1,1,1,1])
B=matrix(2,2,[2,2,2,2])
C=matrix(2,2,[3,3,3,3])
D=matrix(2,2,[4,4,4,4])
L1=[A,B,C]
L2=[C,B,A]
L3=[A,C,D]
show(L1,L2,L3)
Then in the output I want L1 and L3 only, as L1 and L2 contain same matrices.
Problem(2): Now suppose we have the following code:
P=matrix(2,2,[5,5,5,5])
Q=matrix(2,2,[6,6,6,6])
R=matrix(2,2,[7,7,7,7])
S=matrix(2,2,[8,8,8,8])
T1=[P,P,Q]
T2=[Q,P,P]
T3=[P,R,S]
show(T1,T2,T3)
Here also, in the output I want T1 and T3 only, as T1 and T2 contain same matrices. Note that I want T1 as it is, that is, P should be there twice.mak3521Wed, 26 Oct 2022 18:51:02 +0200https://ask.sagemath.org/question/64630/How to speed up the code?https://ask.sagemath.org/question/64373/how-to-speed-up-the-code/Given a matrix M, to find all 1,-1 matrices which satisfy the condition given in the code.
For n=3, I am getting the outputs easily. For n=6, it ran for around 12 hours and got "flint exception error".
I understand that len(T) is huge so there might be some memory issues. Is there anyway to get over it?
> n=3
T=Tuples((1,-1),n^2)
A=[matrix(n,n,t) for t in T]
for a in A:
if 3*a^2==M:
show(a)
mak3521Mon, 10 Oct 2022 16:59:47 +0200https://ask.sagemath.org/question/64373/Can't find error in my codehttps://ask.sagemath.org/question/64286/cant-find-error-in-my-code/Please refer to my question at
https://ask.sagemath.org/question/63878/making-code-faster-by-splitting-and-use-of-supercomputer/
According to the suggestion given in the end by Max Alekseyev I have made a complete code. Here I am showing only the initial part , as problem lies in it . I don't know what I am missing or what mistake I have made.
> M = matrix(3,3, [1, 1, 1, -1, 1, 1, -1, -1, 1])
List_S=[M^0,M^1,M^2]
n = 3
V = GF(2)^(n^2)
VL1=V.list()[1:]
# Removing the all-zero list because not needed for our purpose
VL2=VL1[:-1]
#Removing the all-ones list because not needed for our purpose
P=[]
for v in VL2:
P.append(matrix(ZZ,n,n,v))
#Forming n by n matrices from list in VL2. Contains all 0,1 matrices.
N=[]
for p in P:
k=-p
N.append(k)
#Forming n by n matrices from P by taking their negative. Contains all 0,-1 matrices
U = []
for a in P:
U.append(a)
for b in N:
U.append(b)
#Taking union of P and N
show("U=",len(U))
def mat_to_vector(m):
temp = []
for i in range(m.ncols()):
for j in range(m.nrows()):
temp.append(m[i][j])
return(vector(temp))
#Defining a function which converts matrix to vector
CAND=[]
for i in range(len(U)):
List_U=[U[i]]
List_SU=List_S+List_U
W=U[:]
W.remove(W[i])
T=tuple(List_SU)
X = ZZ^(n^2)
Y = X.span(mat_to_vector(T[i]) for i in range(len(T)))
for w in W:
if mat_to_vector(w) in Y:
CAND.append(mat_to_vector(w))
VTM=[matrix(ZZ,n,n,u) for u in CAND]
for b in VTM:
b.set_immutable()
B = set(VTM)
show("B=",len(B))
According to the suggestion, len(B) should come out to be less than len(U).
But it is coming out to be same as len(U). Kindly find the error.sgmthMon, 03 Oct 2022 16:34:28 +0200https://ask.sagemath.org/question/64286/Forming Combinations with conditionshttps://ask.sagemath.org/question/64104/forming-combinations-with-conditions/Suppose B is a finite collection of distinct square matrices of nth order.
And , A a subcollection of B.
I want unique combinations of four distinct elements -three from A and one from B.
I tried this
X=Combinations(A,3)
Y=Combinations(B,1)
for i in range(len(X)):
for j in range(3):
for k in range(len(Y)):
if ((X[i])[j])!=(Y[k]):
show(X[i]+Y[k])
I know problem is with my "if" command.
My question is how to change the βifβ command so that none of the matrices in X[i] equals Y[k], so that we get distinct matrices in a combination.
Further, how to get unique combinations.
Thanks.
sgmthTue, 20 Sep 2022 06:47:18 +0200https://ask.sagemath.org/question/64104/Matrix with negative indiceshttps://ask.sagemath.org/question/63397/matrix-with-negative-indices/Is there a way or hack to operate with matrices with negative indices? For example a 3x3 matrix with row indices {-1,0,1} and column indices {-1, 0, 1}. So one can do m[-1,-1] for first row and column entry, while still retain matrix operations (ring ops, determinant, etc.). I'm dealing with random walks where the symetry needs that.jesuslopMon, 25 Jul 2022 15:15:11 +0200https://ask.sagemath.org/question/63397/Matrix constructor runs out of memoryhttps://ask.sagemath.org/question/60673/matrix-constructor-runs-out-of-memory/I am trying to construct a matrix with entries in $\mathbb{Q}(q)$, from a list of Sage vectors. I do this using
`A = matrix(QQ['q'].fraction_field(), relations)
`
where the vectors in the list `relations` are Sage vectors over `QQ['q'].fraction_field()`.
The list `relations` is generated by a subroutine involving some randomness, and in many cases the above works fine but sometimes my script uses too much memory and is killed by the operating system. Tracing the memory allocation it is clear that the problem occurs at the given line where I construct the matrix from the list of vectors.
The sorts of matrices for which the script fails are tend to have about 100 columns and 50-100 rows. They are sparse (each row has <= 4 nonzero entries) and the nonzero entries are of the form `-2/q^x + 2` where `x` is in the range `10000 - 100000`.
It seems clear that when some combination of the order of magnitude of the exponents `x` and the matrix size is reached, then the matrix constructor uses too much memory. I wondered if there is a solution anyone can suggest, or even just explain a bit more about why this constructor seems to max out on memory?
(P.S. I plan to re-implement things using sparse matrices, and maybe this will help, though I'd still like to understand better why the dense version fails.)PatrickKinnearThu, 13 Jan 2022 19:01:24 +0100https://ask.sagemath.org/question/60673/Partitioning a (1,-1)square matrix into (0,-1,1)summand matriceshttps://ask.sagemath.org/question/60560/partitioning-a-1-1square-matrix-into-0-11summand-matrices/ Given a square matrix M with entries from {1,-1} how to find all possible sets of matrices A1,A2,A3.....(with entries from {0,-1,1}), such that M=A1+A2+A3....sgmthThu, 06 Jan 2022 16:25:20 +0100https://ask.sagemath.org/question/60560/Matrix with polynomial entries in Sage.https://ask.sagemath.org/question/59687/matrix-with-polynomial-entries-in-sage/ I am trying to define a function to produce matrices with polynomial entries. I defined the following
def BraidMatrices(i,n,z):
r=identity_matrix(n,n)
r[i,i]=0
r[i,i+1]=1
r[i+1,i]=1
r[i+1,i+1]=z
return r
z=VariableGenerator('z')
n=3
t1=BraidMatrices(1,n,z[1])
t1
But it has some errors:
1099 n = self.pyobject()
1100 except TypeError:
-> 1101 raise TypeError("unable to convert %r to an integer" % self)
1102 if isinstance(n, sage.rings.integer.Integer):
1103 return n
TypeError: unable to convert z1 to an integer
How to define a matrix with polynomial entries in Sage? Thank you very much.lijr07Thu, 11 Nov 2021 17:09:18 +0100https://ask.sagemath.org/question/59687/Assuming matrix is positive semi-definitehttps://ask.sagemath.org/question/58070/assuming-matrix-is-positive-semi-definite/ I'm trying to find moments of of transformations of the multivariate normal distribution.
Let $x,y,z\sim N(\mu, \Sigma)$, I want to find out (for example) $E[e^x], E[e^{2x}], E[e^xy]$.
I have defined the following:
x, y, z = var('x y z')
X = vector([x,y,z])
mx, my, mz = var('mx my mz')
mu = vector([mx, my, mz])
sx, sy, sz = var('sx sy sz')
sxy, sxz, syz = var('sxy sxz syz')
assume(sx > 0)
assume(sy > 0)
assume(sz > 0)
S = matrix(SR, [[sx^2, sxy, sxz], [sxy, sy^2, syz], [sxz, syz, sz^2]])
f = (1 / sqrt(S.det() * (2*pi)^3))*exp(-0.5*((X - mu) * S.inverse() * (X - mu)))
And now I'm trying some integration, for example:
(x*f).integrate(z, -Infinity, Infinity).integrate(y, -Infinity, Infinity).integrate(x, -Infinity, Infinity)
I'd expect this to yield `mx` but of course life ain't easy so I get errors related to the covariance matrix:
ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help (example of legal syntax is 'assume(sx^2*(sy^2*sz^2-syz^2)
>0)', see `assume?` for more details)
Is sx^2*(sy^2*sz^2-syz^2)
-sxy^2*sz^2
+2*sxy*sxz*syz
-sxz^2*sy^2 positive or negative?
Even for 1D integration (i.e only over $z$, `(x*f).integrate(z, -Infinity, Infinity)`) I get errors:
ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation *may* help (example of legal syntax is 'assume(sx^2*(sy^2*sz^2-syz^2)
>0)', see `assume?` for more details)
Is sx^2*(sy^2*sz^2-syz^2)
-sxy^2*sz^2
+2*sxy*sxz*syz
-sxz^2*sy^2 positive or negative?
I have tried assuming everything he asks but I still get the same errors. Is there any nice way of telling `SAGE` to assume the matrix `S` is positive-semidefinite?
PS I have managed to work with two 2D case, by using correlation and the "full" version of the formula (rather than the vectorized):
x = var('x')
y = var('y')
mux = var('mux')
muy = var('muy')
sx = var('sx')
sy = var('sy')
r = var('r')
assume(r<=1)
assume(r>=-1)
k = 1/(2*pi*sx*sy*sqrt(1-r^2))
fxy = k*exp(-(1/(2*(1-r^2)))*(((x-mux)/sx)^2 - 2*r*((x-mux)/sx)*((y-muy)/sy) + ((y-muy)/sy)^2))
If I run `integrate(integrate(x*fxy, y, -Infinity, Infinity), x, -Infinity, Infinity).simplify()`, the result is eventually the correct one (`mux`).guyaspWed, 21 Jul 2021 09:58:41 +0200https://ask.sagemath.org/question/58070/Define matrix indexed by partitionshttps://ask.sagemath.org/question/57814/define-matrix-indexed-by-partitions/ I want to define the following matrix in sage: $J$ is of size Partitions(n), and $J_{\lambda, \mu} = 1$ if $\lambda'=\mu$ and $0$ else.
Can someone please help? mathstudentTue, 29 Jun 2021 21:00:56 +0200https://ask.sagemath.org/question/57814/Finding centraliser algebras of a finite set of matriceshttps://ask.sagemath.org/question/57363/finding-centraliser-algebras-of-a-finite-set-of-matrices/Let $S$ be a finite set of $n \times n$-matrices over a field $K$ (lets say finite or the real or complex field).
Is it possible to obtain the $K$-algebra (or at least its vector space dimension) of $n \times n$-matrices X in Sage with $XY=YX$ for all $Y \in S$?
(I can only think of a way for doing this for finite field with very small $n$ by looking at all elements,but maybe there is a better technique in Sage)klaaaSun, 30 May 2021 13:48:31 +0200https://ask.sagemath.org/question/57363/matrix is found singular over CC, nonsingular over CDFhttps://ask.sagemath.org/question/56365/matrix-is-found-singular-over-cc-nonsingular-over-cdf/I am trying to take the inverse of complex valued matrix where every entry is either +/-1,+/-i,or 0. The matrices are quite large and I am getting substantial rounding errors when I construct the matrix using "matrix(CDF,array)" and then take the inverse, but I still get an output.
When I construct the matrix using the same array but using "matrix(CC,array)" and then take the inverse I get this error:
ZeroDivisionError: input matrix must be nonsingular
I am confused because the array when I use "matrix(CC,array)" is exactly the same as the array when I use CDF, however "matrix(CDF,array)" is nonsingular and the function inverse works.
Why is this happening and is there another way I can avoid large rounding errors when taking the inverse?
I hope this is enough detail. I'm not really sure how to provide an example of this error occurring since the smallest example of the array I am
working with is still quite large (52x52) and I haven't been able to get this error to occur with smaller simpler arrays.
This is the encoded matrix over the Gaussian Integers - I had been using QQbar() to run it since it worked to get the inverse.
`b = [286102294921876, 178813934326175001, 69849193096160908206250, 27284841053187847167978515625, 10658141036401502788066894531250000, 179100036621093756, 111937522888183596880, 69960951805114746112500, 43725594878196716328140625, 27343048714101314544736328125, 17080310499295592308075000000000, 10675194062059745192527954101562500, 1716613769531255, 112652778625488296880, 44004991650581359960953125, 17189449863508343696746875000000, 63948846218409016728401336669921875, 895500183105468780, 559687614440917984400, 349804759025573730562500, 218627974390983581640703125, 136715243570506572723681640625, 85401552496477961540375000000000, 53375970310298725962639770507812500, 8583068847656275, 563263893127441484400, 85947249317541718483734375000000, 319744231092045083642006683349609375, 4477500915527343900, 2798438072204589922000, 1749023795127868652812500, 1093139871954917907959375000, 683212419971823692323242187500, 427007762482389807701875000000000, 266879851551493629813198852539062500, 42915344238281375, 2816319465637207422000, 1100124791264533997803125000, 429736246587708592418671875000000, 1598721155460225418210033416748046875, 22387504577636719500, 13992190361022949610000, 8745118975639343264062500, 5465699359774589539796875000, 3416062099859118461616210937500, 2135038812411949038509375000000000, 1334399257757468149065994262695312500, 35762786865235000, 13969838619232179688125, 5456968210637569433595703125, 2131628207280300557632452392578125, 1332267629550187848508377075195312500]`
The issue I'm now having is that I expected the inverse this matrix to look much different - as well as the determinant to be much larger.beanplantzThu, 25 Mar 2021 02:03:28 +0100https://ask.sagemath.org/question/56365/Determinant Function on Qphttps://ask.sagemath.org/question/57057/determinant-function-on-qp/ See attachment[C:\fakepath\Screenshot (104).png](/upfiles/16206765974636286.png)
I basically have 2 matrices with entries in Qp. I cant exactly do Matrix2.charpoly() as this is det (xI-Matrix2) and I want determinant of (I-xMatrix2). So I decided to just type det(I-x*Matrix2) but it gives me error. Is there a way to fix this?
If you want me to be honest, I get an error just from I-x*Matrix2. So it might not even be the determinant function. whatupmattMon, 10 May 2021 22:01:39 +0200https://ask.sagemath.org/question/57057/Obtaining directed graphs associated to matriceshttps://ask.sagemath.org/question/56433/obtaining-directed-graphs-associated-to-matrices/Let $M$ be an $n \times n$-matrix with entries only 0 or 1 and all diagonal entries equal to 1. (usually $M$ is upper triangular)
Let $R$ be the same matrix as $M$ but with all diagonal entries set to zero.
Let $U=(u_{i,j})$ be the matrix with 1 as an entry if $R^2$ (the matrix product of $R$ with itself) has a non-zero entry in the same position and let $U$ have 0 in this entry if $R^2$ has 0 as an entry in this position.
Let $C=(c_{i,j})$ be the matrix $R-U$.
Let $G_M$ be the directed graph with $n$ vertices and there is an arrow from $i$ to $j$ if and only if $c_{i,j}$ is 1.
For example when $M$ is the matrix with rows $[1,1,1],[0,1,1],[0,0,1]$ then the graph $G_M$ has 3 vertices with an arrow from 1 to 2 and an arrow from 2 to 3.
My question is whether there is a quick method to obtain all such 0-1 matrices with Sage for a given $n$ and the associated graph $G_M$ displayed as a picture (and as a graph in sage).klaaaTue, 30 Mar 2021 17:51:14 +0200https://ask.sagemath.org/question/56433/A matrix containing differential operators acting on a matrix containing functionshttps://ask.sagemath.org/question/56311/a-matrix-containing-differential-operators-acting-on-a-matrix-containing-functions/Suppose I have a 2x2 operator matrix, D. Some of its elements are of the form (d/dx), and (d2/dx2).
Now when this matrix is multiplied with another matrix, f, whose elements are functions of x, I will get the final matrix whose corresponding elements are differentiated.
for example: **D = matrix([[d/dx, d3/dx3], [d2/dx2, d2/dx2]])** is an operator matrix which operates on a function matrix, **f(x) = matrix([[x, x^2], [x^3, x]])** as D(f(x)) = D*f(x), (simple matrix multiplication).
Writing D = matrix([[diff( , x), diff( , x, 3)], [diff( , x, 2), diff( , x, 2)]]) does not work as diff() function needs an input function.
So how can I write the D() operator matrix?
PS: I could use f.apply_map(lambda e: diff(e, x)), but then it applies d/dx to all elements in f(x). Whereas, I have 'diff()' operators of different orders in the D matrix.ApoorvMon, 22 Mar 2021 13:29:51 +0100https://ask.sagemath.org/question/56311/Finding positive matriceshttps://ask.sagemath.org/question/56173/finding-positive-matrices/ Hi. I am new in Sage, so please accept my apologies if my question is basic.
Let $L=[A1,A2,A3,...,A100]$ be a list of non-negative matrices. I want to find a list that contains all positive matrices. Thanks in advance.Blue skyMon, 15 Mar 2021 20:17:13 +0100https://ask.sagemath.org/question/56173/tensor_product of matrices over cyclotomic fieldhttps://ask.sagemath.org/question/54762/tensor_product-of-matrices-over-cyclotomic-field/Beginner question: I have created some matrices over a cyclotomic field and attempted to compute some of their tensor products:
N = 3
k.<w> = CyclotomicField(N)
Z = diagonal_matrix(k,N,[w^j for j in range(0,N)])
X = matrix(k,N,N,[1 if (i%N - floor(i/N)) % N == N-1 else 0 for i in range(0,N*N)])
I = identity_matrix(k,N)
I.tensor_product(X)
X.tensor_product(I)
Z.tensor_product(I)
Z.tensor_product(X)
#I.tensor_product(Z)
#X.tensor_product(Z)
If I uncomment either of the last two lines I get
> AttributeError: 'sage.matrix.matrix_generic_sparse.Matrix_generic_sparse' object has no attribute '_rational_matrix'
It seems my code is working when both matrices in the tensor product are rational or when self is non-rational, but not when self is rational and the argument is non-rational. Should I be somehow instructing sagemath to regard self as a matrix over the cyclotomic field?Will OrrickSat, 19 Dec 2020 20:38:38 +0100https://ask.sagemath.org/question/54762/counting number of matrices in finite fieldhttps://ask.sagemath.org/question/54520/counting-number-of-matrices-in-finite-field/I am new to sage and I want to count the number of matrices per rank in a given finite field.
Example: M=matrix([[x1, x2, x3],[ x4,-x1, x5],[x6,x7,x8]])
in Z/3ZsmokzetaWed, 02 Dec 2020 16:21:39 +0100https://ask.sagemath.org/question/54520/