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.Mon, 29 Jan 2024 19:11:05 +0100How to take inverse of matrix with complex entrieshttps://ask.sagemath.org/question/75698/how-to-take-inverse-of-matrix-with-complex-entries/I am trying to find the similarity matrix between two 18 by 18 matrices `K_1` and `K_2` which are cospectral. The `is_similar()` function takes too long to run. We can compute the similarity matrix by finding the transition matrices `S` and Q which diagonalize both `K_1` and `K_2`. In other words, `S^(-1)*K_1*S = H = Q^(-1)*K_2*Q`, where `H` is a diagonal matrix. We then know that `Q*S^(-1)*K_1*S*Q^(-1) = K_2`. My problem now though is that we can't compute `Q^(-1)` or `S^(-1)` since both `Q` and `S` have nasty complex numbers and the inverse method in Sage doesn't run fast enough. Any thoughts on how to quickly compute these inverses?
fyi, I did try using the left and right eigenmatrices to find the similarity matrix, but the eigenvectors didn't line up.luke_mattgreenMon, 29 Jan 2024 19:11:05 +0100https://ask.sagemath.org/question/75698/Diagonalisability check Malfunctioninghttps://ask.sagemath.org/question/73064/diagonalisability-check-malfunctioning/I ran the following code:
```
A = matrix(QQbar, [[2,-1,0],[-1,2,1],[0,-1,2]]);
D, P = A.diagonalization()
```
This generated a value error saying that A is not diagonalisable. To see if there are workarounds, I replaced the `diagonalization` method by `eigenmatrix_right()`, and the results were weird.
`D` was twice the identity matrix, and `P` had zero vectors in its creation. I think writing `QQbar` to make the thing work in algebraic numbers is not proving fruitful at all, because replacing it with `QQ` yields exactly the same result.
UPD1: I thought that the issue might lie with the implementation of `QQbar`, so I tried it `Q[sqrt(2)]` instead, which does indeed contain the eigenvalues of my matrix: `2, 2 + \sqrt(2), 2 - \sqrt(2)`, and the entries of the corresponding eigenvectors as well, but to no avail. I think it's the matrix construction mechanism itself which is faulty here. Unless addressed soon, I suppose I would remove the `QQbar` tag from the question then.
UPD2: Closed, A wasn't entered correctly, was the issue.yeetcodeThu, 31 Aug 2023 03:45:54 +0200https://ask.sagemath.org/question/73064/"Affine diagonalization algorithm" in n-dimensions?https://ask.sagemath.org/question/55345/affine-diagonalization-algorithm-in-n-dimensions/Does Sage have a general implementation of the "affine diagonalization algorithm"
for n-dimensional vector spaces?
I found some pseudo-code, see page 15 (in section 3 "affine diagonalization" which begins on page 12) of
- [Lecture 21: Surfaces](https://cs.nyu.edu/yap/bks/egc/09/21Surfaces.pdf) in [Robust geometric computation](https://cs.nyu.edu/yap/bks/egc/)
Searching online led me also to this answer from 2008 where someone does it with Maple:
- [Maple primes: Normal forms for quadratic functions](https://www.mapleprimes.com/posts/38766-Normal-Forms-For-Quadratic-Functions)
but unfortunately, I cannot open the `.mws` file (I get an error message concerning the version number).
Thank you very much for the help.BernMon, 18 Jan 2021 19:59:25 +0100https://ask.sagemath.org/question/55345/quadraticform rational_diagonal_form?https://ask.sagemath.org/question/35985/quadraticform-rational_diagonal_form/I don't understand the factor of "2" ; which also appears in my real problem.
Here is the sample code from
doc.sagemath.org/html/en/reference/quadratic_forms/sage/quadratic_forms/quadratic_form.html#sage.quadratic_forms.quadratic_form.QuadraticForm.rational_diagonal_form
Q = QuadraticForm(ZZ, 4, range(10))
D, T = Q.rational_diagonal_form(return_matrix=True)
D
[ -1/16 0 0 0 ]
[ * 4 0 0 ]
[ * * 13 0 ]
[ * * * 563/52 ]
but
T.transpose() * Q.matrix() * T
[ -1/8 0 0 0]
[ 0 8 0 0]
[ 0 0 26 0]
[ 0 0 0 563/26]
Off by a factor of 2?
The description says.
OUTPUT: either D (if return_matrix is false) or (D,T) (if return_matrix is true) where
D – the diagonalized form of this quadratic form.
T – transformation matrix. This is such that T.transpose() * self.matrix() * T gives D.matrix().**
RayrrogersMon, 12 Dec 2016 16:34:50 +0100https://ask.sagemath.org/question/35985/Problem diagonalizing a antisymmetric matrix in sympyhttps://ask.sagemath.org/question/8982/problem-diagonalizing-a-antisymmetric-matrix-in-sympy/I am trying to diagonalize a anti-symmetric matrix in sympy. I constructed a random two by two anti-symmetric matrix in sympy and used the diagonalize command. It gives me an error saying it cannot calculate the eigenvectors. Is there a problem with sympy when the eigenvalues are purely imaginary?
import sympy
import numpy as np
mat1=np.random.rand(4)
m1=sympy.Matrix(2,2,mat1)
m2=-1.0e0*m1.transpose()
m=m1+m2
view(m)
m.diagonalize()ShashankSat, 26 May 2012 21:13:44 +0200https://ask.sagemath.org/question/8982/Is there a way to block diagonalize a matrix?https://ask.sagemath.org/question/8503/is-there-a-way-to-block-diagonalize-a-matrix/I am trying to block diagonalize a four by four symbolic matrix in to two matrices of dimension two by two matrices. Is there a simple way to do it in sage?
ShashankMon, 28 Nov 2011 03:30:46 +0100https://ask.sagemath.org/question/8503/