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.Wed, 15 Nov 2017 15:38:29 +0100Calculation Kernel of a matrixhttps://ask.sagemath.org/question/39575/calculation-kernel-of-a-matrix/I'm trying to write a program in which one part is related to calculation of kernel of a matrix. Its output and expected output are different. For example,
A = [[1, 0, 1], [1, 0, 0], [0, 1, 1], [0, 1, 0], [0, 0, 1], [-1, 0, 0], [0, 0, -1], [0, -1, 1], [0, -1, 0], [-1, 0, 1]]
A is the matrix whose kernel is wanted.
When I calculate its kernel with some programs they give output different, my program is as well. But, when I try to calculate its kernel some others, like SAGE, give output,
1 0 0 0 0 0 0 -2 2 1
0 1 0 0 0 0 0 -1 1 1
0 0 1 0 0 0 0 -1 2 0
0 0 0 1 0 0 0 0 1 0
0 0 0 0 1 0 0 -1 1 0
0 0 0 0 0 1 0 1 -1 -1
0 0 0 0 0 0 1 1 -1 0
The above one is what I expect as output. What is the point that I may overlook?
Here is my procedure to calculate the kernel in my program,
A.transposeInPlace();
FullPivLU<MatrixXf> lu(A);
MatrixXf A_null_space = lu.kernel();
A_null_space.transposeInPlace();
But in that way, I get different then expected one, but SAGE gives the above matrix that actually I expect.
0.5 0 -1 1 0 0 0 0 0 0.5
-0.5 0 -0 0 1 0 0 0 0 -0.5
0.5 0 -0 0 0 1 0 0 0 -0.5
0.5 0 -0 0 0 0 1 0 0 0.5
-1 0 1 0 0 0 0 1 0 -1
-0.5 0 1 0 0 0 0 0 1 -0.5
-0.5 1 -0 0 0 0 0 0 0 0.5
**I'm really but really confused because both matrix seem right! How come?**
Sage's output proof,
https://i.stack.imgur.com/F3ryq.png
My program's output proof,
https://i.stack.imgur.com/7Mw8y.pngstudentboyWed, 15 Nov 2017 15:38:29 +0100https://ask.sagemath.org/question/39575/echelon_form not giving reduced echelon formhttps://ask.sagemath.org/question/35819/echelon_form-not-giving-reduced-echelon-form/According to the document(emphasis mine):
> echelon_form(algorithm='default', cutoff=0, **kwds)
>
> Return the echelon form of self.
>
> **OUTPUT**:
>
> The *reduced row echelon form* of self, as an immutable matrix.
Here is what I was doing:
sage: A = Matrix([[1,0,3,1,2],[-1,3,0,-1,1],[2,1,7,2,5],[4,2,14,0,6]])
sage: A.echelon_form()
[1 0 3 1 2]
[0 1 1 0 1]
[0 0 0 4 4]
[0 0 0 0 0]
While the result is in row echelon form, it's not in **reduced** row echelon form. What I expect is something like this:
[1 0 3 0 1]
[0 1 1 0 1]
[0 0 0 1 1]
[0 0 0 0 0]
Also, if this is merely a documentation bug, how can I get the reduced row echelon form of a matrix?sunqingyaoWed, 30 Nov 2016 15:24:42 +0100https://ask.sagemath.org/question/35819/Can I use the block_matrix command to create arbitrary sizes of block matrix arrays?https://ask.sagemath.org/question/26780/can-i-use-the-block_matrix-command-to-create-arbitrary-sizes-of-block-matrix-arrays/ Like say I want to create a $4k \times 4k$ size matrix by putting together certain $4\times 4$ matrices into a $k \times k$ array.
- Can the "block_matrix" command help me create such a $4k \times 4k$ array of 0s called $A$ ? (such later I can say something like $A[a,b] = X$ where $0 \leq a,b \leq k$ and $X$ is some $4\times 4$ matrix and that will assign the matrix $X$ at the $(a,b)$ array position) phoenixSat, 09 May 2015 20:40:56 +0200https://ask.sagemath.org/question/26780/How to build a matrix thought of as an array of smaller matrices?https://ask.sagemath.org/question/26764/how-to-build-a-matrix-thought-of-as-an-array-of-smaller-matrices/ Say I am given a data set which looks like $[ (0,2,A), (0,3,B), (1,2,C), (1,4,D) ]$ where $A,B,C,D$ are matrices all of the same dimension say $k$. (the data set will always have unique pairs of integers - as in if (1,2,*) tuple occurs then (2,1,*) tuple will not occur)
Now I want to create a 4x4 matrix say X of dimension $4k$ thought of as a 4x4 array of k-dimensional matrices.
The arrays in $X$ are to be defined as $X(0,2) = A, X(2,0) = A^{-1}, X(0,3) = B, X(3,0) = B^{-1}, X(1,2) = C, X(2,1) = C^{-1}, X(1,4) = D, X(4,1) = D^{-1}$ and all other array positions in $X$ are to be filled in with $0$ matrices of dimension $k$.
- How can one create such a X on SAGE?
X is a matrix of matrices and I am not sure how one can define this on SAGE. Like saying "X(0,3) = B" is not going to make any obvious sense to SAGE. I necessarily need X to be a matrix so that i can later say calculate its characteristic polynomial.
[I showed this above example with just $4$ tuples. I want to eventually do it with much larger data sets]
phoenixFri, 08 May 2015 19:38:32 +0200https://ask.sagemath.org/question/26764/How to do symbolic vector/matrix manipulations in Sage?https://ask.sagemath.org/question/11050/how-to-do-symbolic-vectormatrix-manipulations-in-sage/
Hello,
So I have a 2x1 vector $\mathbf{x} \in R^2$, and a function on it called $f(\mathbf{x}) = log(\mathbf{1}^T \mathbf{x})$ which of course, returns a scalar.
I would like to compute the Hessian of this function in Sage, symbolically. That is, I would like it so show me what the 2x2 Hessian matrix would look like, but in terms of the elements of $x$, or even better, in terms of the vector $\mathbf{x}$.
Is there such a way? Thanks. GravitusMon, 17 Feb 2014 12:35:27 +0100https://ask.sagemath.org/question/11050/Adjoint of symbolic matrix fails due to type conversionhttps://ask.sagemath.org/question/10366/adjoint-of-symbolic-matrix-fails-due-to-type-conversion/Trying the following code
var('x')
Matrix([[sqrt(x),x],[1,0]]).adjoint()
I get an error message
TypeError: no conversion of this rational to integer
This seems very strange to me. Computing the adjoint of any matrix should be possible, without requiring the elements to be rational, integral or anything else special. Over the symbolic ring in particular, it should always be possible to write the minors as expressions, perhaps without any evaluation or simplification in cases where doing more might cause trouble.
Surprisingly, computing the inverse works without issues. This is despite the fact that inversion requires division, and thus entails the danger of division by zero, where computing the adjoint does not. So one workaround might be multiplying the inverse by the determinant. But this will fail for some matrices where computing the adjoint should work. And it might also leave behind divisions within the elements, which might be difficult to get rid of without changing other radical changes to the form of the involved expressions. I just had a more complicated example where `simplify` left the division and `simplify_full` split square roots in a rather unreadable fashion.
Is there a valid explanation for the above behavior, or is this a bug?
Is there a better way to work around this problem?MvGFri, 19 Jul 2013 18:00:37 +0200https://ask.sagemath.org/question/10366/