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.Tue, 22 Dec 2020 21:02:35 +0100Matrix-scalar and vector-scalar operationshttps://ask.sagemath.org/question/54844/matrix-scalar-and-vector-scalar-operations/ Consider :
sage: b=vector([var("b_{}".format(u)) for u in (1..3)])
sage: B=matrix(b).transpose()*matrix(b)
Unsurprisingly :
sage: B*x
[ b_1^2*x b_1*b_2*x b_1*b_3*x]
[b_1*b_2*x b_2^2*x b_2*b_3*x]
[b_1*b_3*x b_2*b_3*x b_3^2*x]
This is less obvious (but intuitively compatible with associativity) :
sage: B+x
[b_1^2 + x b_1*b_2 b_1*b_3]
[ b_1*b_2 b_2^2 + x b_2*b_3]
[ b_1*b_3 b_2*b_3 b_3^2 + x]
This also is unsurprising :
sage: b*x
(b_1*x, b_2*x, b_3*x)
But there is nothing "obviously expectable" from this :
sage: b+x
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-29-58bd66da7aa5> in <module>
----> 1 b+x
/usr/local/sage-9/local/lib/python3.9/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__add__ (build/cythonized/sage/structure/element.c:10988)()
1230 # Left and right are Sage elements => use coercion model
1231 if BOTH_ARE_ELEMENT(cl):
-> 1232 return coercion_model.bin_op(left, right, add)
1233
1234 cdef long value
/usr/local/sage-9/local/lib/python3.9/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel.bin_op (build/cythonized/sage/structure/coerce.c:11708)()
1248 # We should really include the underlying error.
1249 # This causes so much headache.
-> 1250 raise bin_op_exception(op, x, y)
1251
1252 cpdef canonical_coercion(self, x, y):
TypeError: unsupported operand parent(s) for +: 'Vector space of dimension 3 over Symbolic Ring' and 'Symbolic Ring'
However,
sage: vector([u+x for u in b])
(b_1 + x, b_2 + x, b_3 + x)
would be a possible candidate, but I have trouble visualizing the consequences in the rest of algebraic computation rules in Sage. Is this documented ?Emmanuel CharpentierTue, 22 Dec 2020 21:02:35 +0100https://ask.sagemath.org/question/54844/Linear Independence in Spaces of Matrices (or even tensors)https://ask.sagemath.org/question/52251/linear-independence-in-spaces-of-matrices-or-even-tensors/Let's say I have a vector space $V$ of dimension $n$, and I have various elements of $V \otimes V$, which you can think of as $n \times n$ matrices. I want to check whether these elements are linearly dependent, and in some cases find a relation. But if I create a matrix space MS, it has no attribute linear_dependence, like with vector spaces.
Do I have to just create a $n^2$-dimensional vector space $W$ and then define the bilinear mapping from $V$ to $W$? And what about rank $3$ tensors, which form a $n^3$-dimensional space?davidac897Mon, 29 Jun 2020 03:05:08 +0200https://ask.sagemath.org/question/52251/Unimodular matrices with additional restrictionshttps://ask.sagemath.org/question/50203/unimodular-matrices-with-additional-restrictions/I'd like to generate some unimodular matrices over ZZ with some restrictions:
1. the entries are between -2 and 2
2. the matrix is symmetric: $A = A^t$
Item (1) above can be addressed with the option `upper_bound`. Simply searching for matrices satisfying (1) and (2),
for j in [1..1000]:
A = random_matrix(ZZ,3,3, algorithm = 'unimodular', upper_bound = 3, max_tries = 1000)
if A == A.transpose():
A
becomes extremely inefficient, especially as the dimension grows.
Is there a way to enforce items (1),(2) within the unimodular algorithm? Or another workaround?
Edit: I originally also wanted the diagonal entries fixed at 2, but this is a bit too restrictive.Daniel LMon, 09 Mar 2020 18:56:08 +0100https://ask.sagemath.org/question/50203/Elements of finitely presented modulehttps://ask.sagemath.org/question/47977/elements-of-finitely-presented-module/Hello everyone,
I am computing group homology and have to deal with huge boundary matrices. The result should be a finitely presented Z-module. But I got the following problem
M = Matrix(ZZ,3,[2,1,0,0,0,0,0,0,0])
V = M.left_kernel()
N = Matrix(ZZ,2,[0,2,2,0,0,0])
W = N.image()
Q = V/W
Q.0
Then I got the warning
"repr(sage.modules.fg_pid.fgp_module.FGP_Module_class_with_category.element_class at 0x7ff4aad554b0) failed: AttributeError: 'sage.matrix.matrix_integer_sparse.Matrix_integer_sparse' object has no attribute '_clear_denom'
Do you have any idea how I can get through this? I want to know information about the generators of Q.
I can't even ask for its additive order
x = Q.0
x.additive_order()
Thank you!Tuan BuiThu, 19 Sep 2019 16:54:30 +0200https://ask.sagemath.org/question/47977/How to solve this system of equation in sage?https://ask.sagemath.org/question/44988/how-to-solve-this-system-of-equation-in-sage/How to solve this system of equations in sage?
$x_1+l_1x_2+l_1^2x_3+\dots+l_1^{k-1}x_k=c_1+r $.
$x_1+l_2x_2+l_2^2x_3+\dots+l_2^{k-1}x_k=c_2+r^2$
$\dots $
$x_1+l_kx_2+l_k^2x_3+\dots+l_k^{k-1}x_k=c_k+r^k$
where $l_i$'s are different positive integers and $c_i,r$ are integers in $[0,256]$
In particular, we can solve with sage. Here is the code :
a0, a1,a2,b3,b4, b5,r,l1,l2,l3 = var('a0,a1,a2,b3,b4,b5, r,l1,l2,l3')
X=solve([a0+l1*a1+l1^2*a2==b3+r^3, a0+l2*a1+l2^2*a2==b4+r^2,a0+l3*a1+l3^2*a2==b5+r^1], a0,a1, a2)MKSThu, 10 Jan 2019 18:31:02 +0100https://ask.sagemath.org/question/44988/how to extract a common factor of vector componentshttps://ask.sagemath.org/question/42784/how-to-extract-a-common-factor-of-vector-components/ v=vec([a*x,a*y])
# should give
a*vec([x,y])
# by a command. Which command?rewolfSat, 30 Jun 2018 13:18:38 +0200https://ask.sagemath.org/question/42784/Gram-Schmidt with arbitrary inner product?https://ask.sagemath.org/question/40123/gram-schmidt-with-arbitrary-inner-product/ Hi,
I'd like to find an orthonormal basis of polynomials using an arbitrary inner product. I know how to do this in Maxima:
ip(f, g) := integrate(f * g, x, -1, 1); /* for example */
y : gramschmidt([1, x, x^2], ip);
But is there a nice way to do this in sage?
Thanks!
-Andrew
ElpimientoTue, 12 Dec 2017 10:48:50 +0100https://ask.sagemath.org/question/40123/Eigenvalues of hecke operatorshttps://ask.sagemath.org/question/40588/eigenvalues-of-hecke-operators/For a project I am trying to build a program that computes a basis for cusp forms of weight 2 over $\Gamma_0(N)$. At one point, I want to represent eigenvalues of multiple Hecke operators. For example, (for $N=23$) I have found the following matrices for the Hecke operators:
$
T_2=\begin{pmatrix} -2 & -1/2 ;
2 & 1 \end{pmatrix}, T_3=\begin{pmatrix} 3 & 1 ;
-4 & -3 \end{pmatrix} \quad T_5=\begin{pmatrix} -2 & -1/2 ;
2 & 1 \end{pmatrix} \quad
$
so we have the following characteristic polynomials $f_2=x^2+x-1$, $f_3=x^2-5$, $f_5=x^2 +2x-4$. Suppose we denote the solution of $f_2$ (eigenvalues of $T_2$) by $a$ and it's conjugate. Then we can denote the solution of $f_3$ by $2a+1$ and of $f_5$ by $2a$.
I am trying to figure out how I can 'make' Sage represent these eigenvalues in this way. Say I have found these matrices above, I can create k.< a >=NumberField(x^2+x-1), then $a$ represents the root of the polynomial. So the question for me is, how can I make Sage give me the eigenvalues of $T_3$ and $T_5$ in terms of $a$?
Furthermore, I am wondering how to get the jordan normal form of $T_2$, or eigenmatrix in terms of $a$. If I ask for jordan_form, I get an error, and if I ask for eigenmatrix_right, I only get a numerical expression.
Remark: A little context, the goal for this project is to represent newforms in a similar way as Sage does, when you ask for example Newforms(23,2,names='a'). We need the eigenvalues of the hecke operators since they correspond with the coefficients of the Fourier series.
----------TheBeiramSat, 13 Jan 2018 11:32:29 +0100https://ask.sagemath.org/question/40588/Rounding entries of a random vectorhttps://ask.sagemath.org/question/39697/rounding-entries-of-a-random-vector/Hello,
I am trying to generate a random diagonal matrix, defined by a random vector over a field RR. The problem is that I need to round all the values to two decimal places, make entries evenly positive and negative (not necessary of equal amount) and, ideally, avoid zeroes.
I have a code
`[round(4*random()-2,2)for i in[1 .. 8]]`
that produces a list of values that I need of size 8. However, I am struggling to combine it with a command `diagonal_matrix` and insert it there.
Also, I don't really understand why do we need to multiply it by 4 in here
`[round(4*random()-2,2)for i in[1 .. 8]]`
and why it produces negative values only, if I multiply it by 2 instead of 4. Could someone explain it please?
Is there any other simpler and more elegant way to solve this problem? Thank you.XeniaTue, 21 Nov 2017 14:53:11 +0100https://ask.sagemath.org/question/39697/