ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 21 Feb 2019 06:01:41 -0600Given a value and conditions, find a matrix with that value as its determinanthttps://ask.sagemath.org/question/45527/given-a-value-and-conditions-find-a-matrix-with-that-value-as-its-determinant/ I'm not sure if the title is named too obscurely, so I'll give an example of what I'm talking.
Say we have an integer matrix:
M= 0 a
b 0 (sorry for weird formatting; cannot seem to write matrices properly on here - any help with that as well? :P )
I want to find all values $(a,b) \in (-2,-1,0,1,2)$ such that $det(M)=2$.
I've tried the following but I'm not sure how to finish it off / if this is the right way to go:
import itertools
for (a,b) in itertools.product([-2,-1,0,1,2], repeat=2):
M = Matrix(ZZ, [[0,a],[b,0]])
if M.determinant()==2:
min_params.append((a,b))
elif
min_params = [(a,b)]
print 'Sets of parameters with this determinant:', min_params
As I say, I feel like the start would be a good way to go, but I'm stuck when reaching `elif`, and I'm not sure if this is the right way to tackle this anyway!
Any help would be great!LukeC93Thu, 21 Feb 2019 06:01:41 -0600https://ask.sagemath.org/question/45527/Minimal determinant of a matrix with varied entrieshttps://ask.sagemath.org/question/45367/minimal-determinant-of-a-matrix-with-varied-entries/I would like Sage to tell me to minimal value of the determinant of a matrix when a vary some entries over a set range.
For example, say with the 4x4 matrix A (sorry for weird layout, I can't get the Latex code to work properly?):
0 1 i j
1 0 1 k
0 1 0 1
0 0 1 0
I'd like to know, for $\{i,j,k} \in \{0, \pm1\}$, what the smallest non-trivial determinant is, and for which combination(s) of $i,j,k$ this is for.
I'm still pretty new to Sage, so I'm a bit unsure of how to do this effectively, if it is at all possible to do this?
Side note: I know I could of course write
sage A.determinant()
and this would give me the value of the determinant in terms of $i,j,k$. And in this example that would likely be much easier.
The idea is that I'd like to do this with larger matrices (that aren't as nice as this), more variables, etc. It would obviously be nicer to have have Sage simply compute the smallest determinant and give the corresponding values for the variables than me have to plug it in.LukeC93Fri, 08 Feb 2019 04:05:15 -0600https://ask.sagemath.org/question/45367/generation of certain matriceshttps://ask.sagemath.org/question/37860/generation-of-certain-matrices/I'd like to create a list of roughly 100-1000 $2 \times 2$ matrices $[A_1,A_2,...,A_N]$ that have the following properties:
1. $\det A_j = 1$
2. The entries of each $A_j$ are in an imaginary quadratic integer ring, such as $\mathbb{Z}[i]$, or $\mathbb{Z}[\sqrt{-2}]$
For example, the matrix
$$\begin{bmatrix}
1&2i \\\\
0&1
\end{bmatrix}$$
fits the above specifications when the ring is $\mathbb{Z}[i]$.
I know that I probably want to run some kind of loop over the entries of the matrix, but I'm not sure how to do this. Perhaps I want to initially treat the matrices as lists of length 4, and then run an iterative loop over the lists. Then, when the above specifications are met, that list is stored somewhere else. I think I'd also like to put a bound on the "size" of the matrix entries, but that should be easy to do afterwards.
Thanks! Daniel LThu, 08 Jun 2017 12:26:31 -0500https://ask.sagemath.org/question/37860/Compute the determinant of a symbolic 5x5 matrixhttps://ask.sagemath.org/question/26489/compute-the-determinant-of-a-symbolic-5x5-matrix/why does the following script fail to compute the determinant of a 5x5 matrix (same problem appears with larger similar matrices 6x6 and 7x7 matrix too) ?
version();
var ('a,b,c,d,e,f,g,h');
A4 = matrix(SR,4,4,[a,b,c,d,a,a,b,c,a,a,a,b,h,a,a,a]);
A5 = matrix(SR,5,5,[a,b,c,d,e,a,a,b,c,d,a,a,a,b,c,a,a,a,a,b,h,a,a,a,a]);
A4; A4.determinant().expand().factor();
A5; A5.determinant();
A5.determinant().expand().factor();
a spurious "_e" appears in the determinant
'Sage Version 6.5, Release Date: 2015-02-17'
(a, b, c, d, e, f, g, h)
[a b c d]
[a a b c]
[a a a b]
[h a a a]
a^4 - 3*a^3*b + 3*a^2*b^2 - 2*a^2*b*c + a^2*c^2 + a^3*d - a^2*b*d - b^3*h + 2*a*b*c*h - a*c^2*h - a^2*d*h + a*b*d*h
[a b c d e]
[a a b c d]
[a a a b c]
[a a a a b]
[h a a a a]
_e*a^4 + a^5 - 2*_e*a^3*b - 4*a^4*b + _e*a^2*b^2 + 6*a^3*b^2 - 4*a^2*b^3 + 3*a^2*b^2*c - a^3*c^2 - 2*a^2*b*c^2 + a^2*c^3 - 2*a^3*b*d + 2*a^2*b^2*d + 2*a^3*c*d - 2*a^2*b*c*d - _e*a^3*h + 2*_e*a^2*b*h - _e*a*b^2*h + b^4*h - 3*a*b^2*c*h + a^2*c^2*h + 2*a*b*c^2*h - a*c^3*h + 2*a^2*b*d*h - 2*a*b^2*d*h - 2*a^2*c*d*h + 2*a*b*c*d*h
Error in lines 13-19
Traceback (most recent call last):
File "/projects/cbc78de9-848d-4653-bf96-aa8a68749e86/.sagemathcloud/sage_server.py", line 879, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
File "sage/symbolic/expression.pyx", line 9266, in sage.symbolic.expression.Expression.factor (build/cythonized/sage/symbolic/expression.cpp:45045)
f = self.polynomial(QQ)
File "sage/symbolic/expression.pyx", line 5716, in sage.symbolic.expression.Expression.polynomial (build/cythonized/sage/symbolic/expression.cpp:31627)
return polynomial(self, base_ring=base_ring, ring=ring)
File "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 1163, in polynomial
converter = PolynomialConverter(ex, base_ring=base_ring, ring=ring)
File "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 999, in __init__
self.ring = PolynomialRing(self.base_ring, names=vars)
File "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_ring_constructor.py", line 477, in PolynomialRing
R = _multi_variate(base_ring, names, n, sparse, order, implementation)
File "/usr/local/sage/sage-6.5/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_ring_constructor.py", line 564, in _multi_variate
names = normalize_names(n, names)
File "sage/structure/parent_gens.pyx", line 207, in sage.structure.parent_gens.normalize_names (build/cythonized/sage/structure/parent_gens.c:2797)
names = _certify_names(names)
File "sage/structure/parent_gens.pyx", line 148, in sage.structure.parent_gens._certify_names (build/cythonized/sage/structure/parent_gens.c:2291)
raise ValueError, "first letter of variable name must be a letter"
ValueError: first letter of variable name must be a letter
PierreFri, 10 Apr 2015 16:38:04 -0500https://ask.sagemath.org/question/26489/