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, 10 Jan 2020 23:05:24 +0100Eigenvalues and eigenspaces of orthogonal (or rotation) matriceshttps://ask.sagemath.org/question/49496/eigenvalues-and-eigenspaces-of-orthogonal-or-rotation-matrices/Given an orthogonal transformation of finite order, e.g.
Matrix([[0,0,0,-1],[1,0,0,-1],[0,1,0,-1],[0,0,1,-1]])
Its eigenvalues are going to be of the form
exp(I*pi/5),exp(2*I*pi/5),...,exp(2*I*pi*m),...
corresponding to a splitting of the matrix into rotation (and reflection) matrices. I'd like to extract these fractions `m` (mod ZZ) and study the corresponding (real rotation and reflection) eigenspaces.
My impression is that Sage isn't suitable for doing this directly, but that I should use e.g. the Maxima or Mathematica interface? Any suggestions for the most suitable method?Bob67846Fri, 10 Jan 2020 23:05:24 +0100https://ask.sagemath.org/question/49496/A way of checking that a multivariate system of equations has a solution?https://ask.sagemath.org/question/41913/a-way-of-checking-that-a-multivariate-system-of-equations-has-a-solution/Is there a way to check that a multivariate system of polynomial equations does indeed have a solution(or not)? The context i am using this in is as follows: say i have a system of multivariate polynomial equations over a finite field, i then put values in for some of the variables, and then i need to check if the resulting system in the remaining unassigned variables has a solution or not? If not, then i will reassign different values to the other variables until a system with a solution is yielded. Of course because the assigning of these values is random there is a high chance the system has a solution anyway, but in the event that it does not is where i need a way to check whether a solution exists or not.DalvirSun, 08 Apr 2018 20:40:45 +0200https://ask.sagemath.org/question/41913/Does anyone know how to implement a simple XL Algorithm in sage?https://ask.sagemath.org/question/41818/does-anyone-know-how-to-implement-a-simple-xl-algorithm-in-sage/I need to implement the XL algorithm in sage, which i can use to solve over-determined systems of polynomial equations (more equations than variables). Any help on how to do this?
DalvirThu, 29 Mar 2018 14:45:45 +0200https://ask.sagemath.org/question/41818/Finding the matrix of a linear affine transformation and its inversehttps://ask.sagemath.org/question/41629/finding-the-matrix-of-a-linear-affine-transformation-and-its-inverse/How do i get the matrix representation of an affine transformation and it's inverse in sage?
I am more so interested in doing this for random affine transformations as i am using them in a multivariate cryptography scheme but for example the following affine transformation over GF(3)
[1 0 0 2 0 2] [1]
[2 2 1 1 2 0] [1]
[2 0 0 2 2 2] [0]
x |-> [2 2 0 1 1 1] x + [1]
[1 0 2 0 2 0] [0]
[0 0 0 2 0 2] [2]DalvirMon, 19 Mar 2018 17:03:59 +0100https://ask.sagemath.org/question/41629/Hermite form, entries reduced over pivotshttps://ask.sagemath.org/question/37964/hermite-form-entries-reduced-over-pivots/ Hello!
I have a question concerning the function hermite_form. This function unfortunately does not reduce the entries above the pivots of the hermite normal form if I use the function on a matrix with polynomial entries. Is there another function or option which enables me to do that?
Following short example hopefully illustrates what I mean:
R.<x> = QQ[];
M = matrix(2,2, [x,x, 0,x]);
M.hermite_form()
This will give the exact same matrix M and not the matrix [x,0, 0,x] which I would expect or hope to get.
Especially if somebody wants to apply another algorithm to such a matrix in hermite form it can be difficult to work with non-reduced matrices.
Kind regards
Philippphilipp7Fri, 16 Jun 2017 17:24:41 +0200https://ask.sagemath.org/question/37964/How to decide if T maps R^5 onto R^5https://ask.sagemath.org/question/37765/how-to-decide-if-t-maps-r5-onto-r5/ Hi all,
New to SageMath, for a homework problem I have to use SageMath to solve a problem and this problem is, "Decide if T maps R^5 onto R^5." This is the matrix ([[9,13,5,6,-1],[14,15,-7,-6,4],[-8,-9,12,-5,-9],[-5,-6,-8,9,8],[13,14,15,2,11]]). How do I go about proving this in SageMath?
Thanksbeartato327Fri, 02 Jun 2017 18:24:59 +0200https://ask.sagemath.org/question/37765/converting linear map to matrix representationhttps://ask.sagemath.org/question/37493/converting-linear-map-to-matrix-representation/ I have a linear map $\alpha$ from $F_{p^n} \longrightarrow F_{p^n}$, where we see $F_{p^n}$ as a vector space over $F_p$ with a $V_i$ as base elements. I want to create the matrix representation for $\alpha$. For that I have to calculate $\alpha(V_i)$ and then write it in the basis $V_i$ to get my values for the matrix. How exactly do I do the last in sage ? For eg. a polynomial ring it's easy because the elements are already written according to its base but in general thats not the case...gelatine1Tue, 02 May 2017 23:13:58 +0200https://ask.sagemath.org/question/37493/Turning system of linear equations into a matrixhttps://ask.sagemath.org/question/37053/turning-system-of-linear-equations-into-a-matrix/I have a very long list of equations (10^3 order of magnitude), but all linear. There are around 10^2 variables.
I would like to solve these equations in $F_2$, that is, in the field of 2 elements. Questions:
1. Is there a handy-dandy "solve" command in Sage that allows me to list these equations, specify the field in which I want these equations to be interpreted, and Sage returns an answer?
2. Or, is there a handy-dandy way I can input a list of linear equations, and Sage automatically returns a matrix? So long as I can read off which entries/columns of the matrix correspond to which variables in my original equations, I'm happy to then use commands taking matrices as inputs, and use the answer to the question "Solve large system of linear equations over GF(2)" (I would put the link in, but I don't have the karma).noviceThu, 23 Mar 2017 18:03:46 +0100https://ask.sagemath.org/question/37053/finding rotation matrix in 3dhttps://ask.sagemath.org/question/9090/finding-rotation-matrix-in-3d/suppose I have a normalized vector perpendicular to a plane like
$x = \frac{(2i+3j+k)}{\sqrt{14}}$ , how can I find a rotation matrix A, such that it rotates x into the xy plane like so:
$Ax = y = \frac{(i, j)} {\sqrt{2}}$
ebsTue, 19 Jun 2012 03:14:29 +0200https://ask.sagemath.org/question/9090/condition number of a matrixhttps://ask.sagemath.org/question/36511/condition-number-of-a-matrix/ I am a novice Sage user, trying to get my Linear Algebra students to use Sage, too. One part of a problem I have assigned in the past asks a student to find the condition number of a matrix. In Maple, the command is just ConditionNumber(A), where A is a defined matrix. Is there a similar command in Sage?
Thanks for any help!srobbertThu, 09 Feb 2017 20:26:31 +0100https://ask.sagemath.org/question/36511/How to find Kernel of a Matrix in $\mathbb{Z}/n$https://ask.sagemath.org/question/33890/how-to-find-kernel-of-a-matrix-in-mathbbzn/ When I tried to find it directly using
A.kernel()
it said
Cannot compute a matrix kernel over Ring of integers modulo 11053185041
vishbThu, 23 Jun 2016 08:16:00 +0200https://ask.sagemath.org/question/33890/Accessing the "Echelon basis matrix" of kernel of a Matrixhttps://ask.sagemath.org/question/33897/accessing-the-echelon-basis-matrix-of-kernel-of-a-matrix/ For any matrix **A** when we type
A.kernel()
It returns
A.kernel()
Free module of degree 45 and rank 12 over Integer Ring
Echelon basis matrix:`[ 1 0 -1][ 0 1 2][ 0 0 0]`
How to I access this Echelon basis matrix directly?
I have tried this
A.kernel.echelon_form()
but it says
TypeError: echelon_form() takes at least 2 arguments (1 given)
vishbThu, 23 Jun 2016 16:15:06 +0200https://ask.sagemath.org/question/33897/Anticommutator of matriceshttps://ask.sagemath.org/question/9278/anticommutator-of-matrices/Dear all.
I was playing around with matrices, and found out that the commutator is defined, however, I didn't find the anti-commutator.
**Question**
- Is it implemented?
The implementation of commutator is about 5 lines (including comments), so the inclusion of it would be marginal.
Cheers.DoxThu, 30 Aug 2012 12:52:52 +0200https://ask.sagemath.org/question/9278/How to show the steps of Gauss' methodhttps://ask.sagemath.org/question/8840/how-to-show-the-steps-of-gauss-method/I am new to Sage, so I apologize if this is dopey. I can get a matrix in Sage and I can get its reduced echelon form. I can get Sage to show the result of a single Gauss' method row operation. But is there a way to get Sage do Gauss' method out to reduced echelon form, while showing the steps? It would be especially sweet if it showed the intermediate matrices.jhSat, 31 Mar 2012 14:09:50 +0200https://ask.sagemath.org/question/8840/Row reduction modulo prime powershttps://ask.sagemath.org/question/9163/row-reduction-modulo-prime-powers/Has any kind of row reduction been implemented modulo prime powers? Right now I'm simply trying to write a particular element of (Z/9Z)^d as a linear combination of a handful of other elements in this space. (I happen to know for other reasons that the original element is in the span of these handful of elements.)
I tried to do this by working with matrices over pAdicField(3,2), but this didn't work. (I guess some division by 3 messes things up.)
Is there anyway to do this without writing my own row reduction code??Robert PollackThu, 19 Jul 2012 14:55:30 +0200https://ask.sagemath.org/question/9163/How does one detect cyclic vectors in SAGE?https://ask.sagemath.org/question/27025/how-does-one-detect-cyclic-vectors-in-sage/
Given a vector $v$ and a matrix $A$ of dimension $n$, one would say that $v$ is a cyclic vector of $A$ if the following set is linearly independent $\{ v,Av,A^2v,..,A^{n-1}v \}$.
Is there a way to test this property on SAGE given a $v$ and a $A$? PhoenixThu, 04 Jun 2015 22:12:06 +0200https://ask.sagemath.org/question/27025/Symbolic Linear Algebrahttps://ask.sagemath.org/question/26952/symbolic-linear-algebra/I'd like to manipulate symbolic expression in linear algebra. More specifically, suppose that A,B, etc. are matrices and v,w,.. etc are column vectors. I have various expressions in them that I'd like expanded and grouped. It also should know about transpose (that it's an involution). For example, if I write the expression:
transpose(v-w)*A*(v-w). It should be able to expand this to
transpose(v)*A*v - transpose(v)*A*w - transpose(w)*A*v + transpose(w)*A*w
Also, I'd like to specify that A is symmetric -- A == transpose(A). In that case the above would simplify to
transpose(v)*A*v - 2*transpose(v)*A*w + transpose(w)*A*w
if we idenfity a 1 by 1 matrix with a scalar. It would also be nice, if we could specify symbolic scalars, and, for example to say that A in hom(V,W), where V,W are some vector spaces. In that case if we try to multiply things that are incompatible we would get an error. This looks like it should be part of some sort of universal algebra package. Does such a thing exist in SAGE?VictorWed, 27 May 2015 16:59:07 +0200https://ask.sagemath.org/question/26952/How to obtain elements from the matrix above the main diagonal?https://ask.sagemath.org/question/25949/how-to-obtain-elements-from-the-matrix-above-the-main-diagonal/ Assuming I have a matrix:
m = np.arange(16).reshape((4, 4))
m
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15]])
And I need to get a list of elements which are above the main diagonal (I don't care about the order as long as it is determined and will not change from call to call), I wrote:
def get_elements_above_diagonal(m):
for i in range(len(m)):
for j in range(i + 1, len(m)):
yield m[i, j]
list(get_elements_above_diagonal(m))
[1, 2, 3, 6, 7, 11]
But then I wondered, may be I am reinventing the wheel here. Is there a simpler way to obtain these elements as a flat list?EugeneFri, 27 Feb 2015 15:31:58 +0100https://ask.sagemath.org/question/25949/reverse a matrixhttps://ask.sagemath.org/question/25917/reverse-a-matrix/ We can count backwards to flip a matrix A upside down
with
sage: A[::-1,:]=A; A
Can we do it from left to right;
I mean, for the matrix A=
[ 3 2 -5 0]
[ 1 -1 1 -4]
[ 1 0 1 -3]
Is there an easy way to obtain the following matrix
[ 0 -5 2 3]
[-4 1 -1 1]
[ 3 1 0 1]
NONAMETue, 24 Feb 2015 15:30:07 +0100https://ask.sagemath.org/question/25917/How to stop Sage from finding erroneous complex roots?https://ask.sagemath.org/question/25587/how-to-stop-sage-from-finding-erroneous-complex-roots/ Consider the matrix,
A = matrix ( [0,1,w^a,1],[1,0,1,w^(k-b)],[w^(k-a),1,0,w^(k-c)],[1,w^b,w^c,0])
where w is the m^th of the k^th roots of unity, `w = exp((2*pi*I*m )/k`
for some k a positive integer, and 1 <= m <= (k-1)
and 1<= a,b,c <= (k-1)
Then the characteristic polynomial of the above matrix is,
`p(x) = x^4 - 6*x^2 -x *(w^(a-c) + w^(c-a) + w^b + w^(-b) + w^(b-c) + w^(c-b) + w^a + w^(-a)) + (3 -w^c - w^(-c) - w^(a+b-c) - w^(-a-b+c) - w^(a-b) - w^(-a+b) )`
- Is there a way to get sage to be able to calculate the above characteristic polynomial?
Now I try getting roots of the above by doing,
g(x)=real_part(p(x)).simplify()
g.solve(x)
- Now Sage seems to be generically detecting complex eigenvalues as roots of g!
(I tried on say k=6, m=a=b=c=1)
This can't happen since its a characteristic polynomial of a Hermitian matrix!
How to get across this trouble?
PhoenixWed, 21 Jan 2015 06:06:19 +0100https://ask.sagemath.org/question/25587/Solving linear matrix equationshttps://ask.sagemath.org/question/25059/solving-linear-matrix-equations/Hi everybody, I'm new to Sage and I'm pretty confused with the solving of matrix equations, I didn't fully understand the guide.
I've got these vectors:
V_fa = vector([V_f*cos(phi), V_f*sin(phi), 0])
V_ra = vector([V, 0, 0])
omega = vector([0, 0, L*psi_d])
P = vector([0, L*psi_d, 0])
And i want to implement the equation:
V_fa=V_ra+omega.cross_product(P)
to isolate and obtain the value of `psi_d`.
How can I do that?
Thank you very much
SilviaSun, 30 Nov 2014 19:35:22 +0100https://ask.sagemath.org/question/25059/Linear equations with errorshttps://ask.sagemath.org/question/24152/linear-equations-with-errors/I have a system of $n^2$ homogeneous linear equations in $n^2$ variables.
Each equation is sparse and only involves $2n$ variables.
I create a list of equations and use solve(). I only get the "all-zero" solution. This is because of inaccuracies in the equations. I know (from theory) that there is be a nonzero kernel.
So, I'd like to find an approximate solution. That is - a solution of norm 1, which "almost fulfills" the equations.
Behind the scenes I probably need the SVD decomposition of the matrix describing the equations (or at least, the input vectors corresponding to the small singular values).
> 1. Do I have to create a matrix to represent the equations, or can I use my equations directly?
> 2. Can it be a sparse matrix?
> 3. Do I have to use an SVD routine, or is there some convenient way to solve my problem directly?
> 4. Do you have an example of how to do it?orenTue, 16 Sep 2014 18:04:30 +0200https://ask.sagemath.org/question/24152/Newbie question: introducing symbols (variables) inside vectors and matriceshttps://ask.sagemath.org/question/23833/newbie-question-introducing-symbols-variables-inside-vectors-and-matrices/Hi,
I would like to have linear algebra operations to be evaluated with symbols instead of numerically.
For example, having the following matrix:
A = matrix(QQ,[
[2,1,2,-6],
[-1,2,1,7],
[3,-1,-3,-1],
[1,5,6,0],
[2,2,1,1]
])
I would like to multiply for a vector with symbolic variables as follows:
t = 'real'
var('x1')
assume(x1,t)
var('x2')
assume(x2,t)
var('x3')
assume(x3,t)
var('x4')
assume(x4,t)
xx = vector(QQ,[x1,x2,x3,x4])
A * xx.transpose()
Unfortunately building the `xx` vector is unsuccessful, producing this error message:
TypeError: Cannot evaluate symbolic expression to a numeric value.
This does not work, so how can I use symbols in sage's linear algebra framework?
thank you very much,
-FrancescostablumTue, 19 Aug 2014 18:18:57 +0200https://ask.sagemath.org/question/23833/Linear Transformation Matrix is Transposedhttps://ask.sagemath.org/question/11088/linear-transformation-matrix-is-transposed/I define a linear transformation object using the following syntax:
def f(v):
l1 = [2*v[0]+3*v[1], 5*v[0]-v[1]]
v1 = vector(l1)
return(v1)
lf = linear_transformation(RR^2, RR^2, f)
lf
The output includes the matrix [[2, 5], [3,-1]] instead of [[2,3], [5,-1]]. Is this a bug or am I doing something wrong?
EDIT: Specifying side="right" doesn't help.
jaiaMon, 05 May 2014 13:53:17 +0200https://ask.sagemath.org/question/11088/Yet another linear combinationhttps://ask.sagemath.org/question/10791/yet-another-linear-combination/Hi, I'm really new to Sage and to programming in general. I have 20 linear independent vectors of length 20, and a linear dependent vector. I would like to write this one as a linear combination of the others: I looked up on the internet all day, but nothing I found worked. The ways I tried are:
- define a vector space of dim 20 on the field I'm using, impose my vectors as a base, and use the method .coodinates(). PROBLEM: I couldn't impose the basis, I didn't find a command to do so.
- use G.solve_right(s), where G is a 20x20 matrix and s is my linear dependent vector. I thought I would have a vector as an output but instead I get something of dimension 20x8. Weird.
- I tried to do a linear system directly using equations with the vectors, in order to solve them with respect to some variables, but I got as an output that you can't do it using vectors.
So, what shall I try?
Thank you very much BubusetteteFri, 29 Nov 2013 18:49:42 +0100https://ask.sagemath.org/question/10791/Using sage to check if a vector is in a matrix's null spacehttps://ask.sagemath.org/question/10781/using-sage-to-check-if-a-vector-is-in-a-matrixs-null-space/I want to check if a given vector is inside a matrix's null space.
Here is what I have done:
#Define a matrix
A=Matrix([[1,-1,2,-1],[2,1,-2,-2],[-1,2,-4,1],[3,0,0,-3]],ring=QQ)
#Free variables to be used in the given vector
var('s t')
#The null space of the matrix A
ns=A.kernel()
s=2
t=1
#Create a vector
ans=s*vector([1,0,0,1])+t*vector([0,2,1,0])
#If ans is in the null space of A, then A*ans is the 0 vector
print A*ans
#If A*ans is the 0 vector, then the following should be true too
print ans in ns
I had expected the last print statement to be true since A*ans results in a zero vector, hence ans is in the null space of A.
Why isn't this the case?
ensabaTue, 26 Nov 2013 13:04:34 +0100https://ask.sagemath.org/question/10781/Plotting the effects of a linear transformation on a gridhttps://ask.sagemath.org/question/10691/plotting-the-effects-of-a-linear-transformation-on-a-grid/I am a student taking a first undergraduate course in linear algebra, and I would like to play around with plots of transformations of the type $T:\mathbb{R}^2\rightarrow\mathbb{R}^2$. I already know a bit of python, so I'm not looking for anyone to write a program for me, but I would really appreciate some tips/general outline of how to do things.
1) First I want to make a grid that I can plot, and then transform by multiplying it with a matrix. Where's the best way to start? Should I use parametric_plot, or maybe it can be done with just a list of **vector([x,y])**'s?
2) Second I want to run the grid through a linear transformation. If I could just plot vectors and offset them (not having them start at the origin), I would only only have to iterate over a list of vectors to get the transformed vectors, but I'm not sure if this is a smart way to do it.
Basically, is there a straight forward way to do this? It doesn't seem like it should be very difficult, if someone could give a rough outline of how to do this it would be greatly appreciated.
Thanks.
eodSun, 03 Nov 2013 09:13:24 +0100https://ask.sagemath.org/question/10691/Augmenting a vectorhttps://ask.sagemath.org/question/10618/augmenting-a-vector/There are simple ways to extend a matrix to form a larger matrix: I can `augment` it to add columns or `stack` it to add rows.
Is there something similar for simple vectors? Some method of a vector object which would return the same vector with one more element added to the end? Or do I have to write that myself?MvGThu, 17 Oct 2013 12:42:32 +0200https://ask.sagemath.org/question/10618/accessing the components of a vectorhttps://ask.sagemath.org/question/10386/accessing-the-components-of-a-vector/Is there a command in Sage that allows me to access the individual components of a vector? For example, suppose I've defined a vector like a=vector([1,2,3]). I want a command like "a.1" that returns the first component of the vector, so in this case I would want a.1 to return 1. Is there a command like this in Sage? Thanks!strangelove1221Sat, 21 Sep 2013 19:06:35 +0200https://ask.sagemath.org/question/10386/basis of hyperplanehttps://ask.sagemath.org/question/10276/basis-of-hyperplane/Hallo
I am new to sage and have this problem.
Given a hyperplane $H_u \subset GF(2^{n+1})$ define by $x |-> a^8 +a$
How do I determine the basis of $H_u$ over $GF(2)$?
RegardsJohanSat, 20 Jul 2013 16:40:54 +0200https://ask.sagemath.org/question/10276/