ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 04 Apr 2018 14:10:21 -0500Simultaneously diagonalizing matrices exactlyhttp://ask.sagemath.org/question/40737/simultaneously-diagonalizing-matrices-exactly/I have a bunch of matrices with integer coefficients that simultaneously commute. I know that there is a basis that simultaneously diagonalizes all of them, and I want to find it exactly so that I can recover all the corresponding eigenvalues as algebraic numbers.
I've tried casting to QQbar and using eigenvectors, but this occasionally tries to divide by zero for no reason I can discern. Any ideas?Mon, 22 Jan 2018 11:43:40 -0600http://ask.sagemath.org/question/40737/simultaneously-diagonalizing-matrices-exactly/Comment by slelievre for <p>I have a bunch of matrices with integer coefficients that simultaneously commute. I know that there is a basis that simultaneously diagonalizes all of them, and I want to find it exactly so that I can recover all the corresponding eigenvalues as algebraic numbers.</p>
<p>I've tried casting to QQbar and using eigenvectors, but this occasionally tries to divide by zero for no reason I can discern. Any ideas?</p>
http://ask.sagemath.org/question/40737/simultaneously-diagonalizing-matrices-exactly/?comment=41871#post-id-41871Please provide an example of matrices for the computation you are asking about.
Ready-to-copy-paste examples make it way easier to explore a question,
thereby increasing chances of an answer.Tue, 03 Apr 2018 02:51:29 -0500http://ask.sagemath.org/question/40737/simultaneously-diagonalizing-matrices-exactly/?comment=41871#post-id-41871Comment by tmonteil for <p>I have a bunch of matrices with integer coefficients that simultaneously commute. I know that there is a basis that simultaneously diagonalizes all of them, and I want to find it exactly so that I can recover all the corresponding eigenvalues as algebraic numbers.</p>
<p>I've tried casting to QQbar and using eigenvectors, but this occasionally tries to divide by zero for no reason I can discern. Any ideas?</p>
http://ask.sagemath.org/question/40737/simultaneously-diagonalizing-matrices-exactly/?comment=40765#post-id-40765Let me join the club of asksage junkies : we need your code to understand your problem and (hopefully) provide a solution.Thu, 25 Jan 2018 04:26:24 -0600http://ask.sagemath.org/question/40737/simultaneously-diagonalizing-matrices-exactly/?comment=40765#post-id-40765Comment by dan_fulea for <p>I have a bunch of matrices with integer coefficients that simultaneously commute. I know that there is a basis that simultaneously diagonalizes all of them, and I want to find it exactly so that I can recover all the corresponding eigenvalues as algebraic numbers.</p>
<p>I've tried casting to QQbar and using eigenvectors, but this occasionally tries to divide by zero for no reason I can discern. Any ideas?</p>
http://ask.sagemath.org/question/40737/simultaneously-diagonalizing-matrices-exactly/?comment=40745#post-id-40745Please give us at least two of the many commuting matrices that can be diagonalized (simultaneously).Mon, 22 Jan 2018 14:55:42 -0600http://ask.sagemath.org/question/40737/simultaneously-diagonalizing-matrices-exactly/?comment=40745#post-id-40745Comment by vdelecroix for <p>I have a bunch of matrices with integer coefficients that simultaneously commute. I know that there is a basis that simultaneously diagonalizes all of them, and I want to find it exactly so that I can recover all the corresponding eigenvalues as algebraic numbers.</p>
<p>I've tried casting to QQbar and using eigenvectors, but this occasionally tries to divide by zero for no reason I can discern. Any ideas?</p>
http://ask.sagemath.org/question/40737/simultaneously-diagonalizing-matrices-exactly/?comment=40739#post-id-40739could you write the code?Mon, 22 Jan 2018 12:21:07 -0600http://ask.sagemath.org/question/40737/simultaneously-diagonalizing-matrices-exactly/?comment=40739#post-id-40739Answer by slelievre for <p>I have a bunch of matrices with integer coefficients that simultaneously commute. I know that there is a basis that simultaneously diagonalizes all of them, and I want to find it exactly so that I can recover all the corresponding eigenvalues as algebraic numbers.</p>
<p>I've tried casting to QQbar and using eigenvectors, but this occasionally tries to divide by zero for no reason I can discern. Any ideas?</p>
http://ask.sagemath.org/question/40737/simultaneously-diagonalizing-matrices-exactly/?answer=41872#post-id-41872Getting a simultaneous basis of diagonalization for a list of diagonalizable matrices that
pairwise commute is just a matter of getting a diagonalization basis for any one of them!
This can be obtained with `jordan_form` with the argument `transformation=True`.
For example, starting from these two matrices `a` and `b`:
sage: a = matrix(QQ, [[1, 1, 1], [-2, 3, 2], [0, 1, 2]])
sage: b = matrix(QQ, [[-1, 1, 1], [1, 1, -1], [-3, 1, 3]])
Check that they commute:
sage: a * b
[-3 3 3]
[-1 3 1]
[-5 3 5]
sage: b * a
[-3 3 3]
[-1 3 1]
[-5 3 5]
sage: a * b == b * a
True
If we diagonalize them separately:
sage: da, pa = a.jordan_form(transformation=True)
sage: db, pb = b.jordan_form(transformation=True)
we can notice that the transformation matrices `pa` and `pb` have the same columns, permuted:
sage: pa
[ 1 1 0]
[ 1 0 1]
[ 1 1 -1]
sage: pb
[ 0 1 1]
[ 1 1 0]
[-1 1 1]
Obtaining the simultaneous diagonal form is just a matter of reordering the columns of:
sage: da
[3|0|0]
[-+-+-]
[0|2|0]
[-+-+-]
[0|0|1]
sage: db
[2|0|0]
[-+-+-]
[0|1|0]
[-+-+-]
[0|0|0]
For instance, use the transformation matrix `pa` to get simultaneous diagonalizations:
sage: qa = ~pa
sage: qa * a * pa
[3 0 0]
[0 2 0]
[0 0 1]
sage: qa * b * pa
[1 0 0]
[0 0 0]
[0 0 2]Tue, 03 Apr 2018 03:34:07 -0500http://ask.sagemath.org/question/40737/simultaneously-diagonalizing-matrices-exactly/?answer=41872#post-id-41872Comment by slelievre for <p>Getting a simultaneous basis of diagonalization for a list of diagonalizable matrices that
pairwise commute is just a matter of getting a diagonalization basis for any one of them!</p>
<p>This can be obtained with <code>jordan_form</code> with the argument <code>transformation=True</code>.</p>
<p>For example, starting from these two matrices <code>a</code> and <code>b</code>:</p>
<pre><code>sage: a = matrix(QQ, [[1, 1, 1], [-2, 3, 2], [0, 1, 2]])
sage: b = matrix(QQ, [[-1, 1, 1], [1, 1, -1], [-3, 1, 3]])
</code></pre>
<p>Check that they commute:</p>
<pre><code>sage: a * b
[-3 3 3]
[-1 3 1]
[-5 3 5]
sage: b * a
[-3 3 3]
[-1 3 1]
[-5 3 5]
sage: a * b == b * a
True
</code></pre>
<p>If we diagonalize them separately:</p>
<pre><code>sage: da, pa = a.jordan_form(transformation=True)
sage: db, pb = b.jordan_form(transformation=True)
</code></pre>
<p>we can notice that the transformation matrices <code>pa</code> and <code>pb</code> have the same columns, permuted:</p>
<pre><code>sage: pa
[ 1 1 0]
[ 1 0 1]
[ 1 1 -1]
sage: pb
[ 0 1 1]
[ 1 1 0]
[-1 1 1]
</code></pre>
<p>Obtaining the simultaneous diagonal form is just a matter of reordering the columns of:</p>
<pre><code>sage: da
[3|0|0]
[-+-+-]
[0|2|0]
[-+-+-]
[0|0|1]
sage: db
[2|0|0]
[-+-+-]
[0|1|0]
[-+-+-]
[0|0|0]
</code></pre>
<p>For instance, use the transformation matrix <code>pa</code> to get simultaneous diagonalizations:</p>
<pre><code>sage: qa = ~pa
sage: qa * a * pa
[3 0 0]
[0 2 0]
[0 0 1]
sage: qa * b * pa
[1 0 0]
[0 0 0]
[0 0 2]
</code></pre>
http://ask.sagemath.org/question/40737/simultaneously-diagonalizing-matrices-exactly/?comment=41879#post-id-41879Good point.Wed, 04 Apr 2018 14:10:21 -0500http://ask.sagemath.org/question/40737/simultaneously-diagonalizing-matrices-exactly/?comment=41879#post-id-41879Comment by nbruin for <p>Getting a simultaneous basis of diagonalization for a list of diagonalizable matrices that
pairwise commute is just a matter of getting a diagonalization basis for any one of them!</p>
<p>This can be obtained with <code>jordan_form</code> with the argument <code>transformation=True</code>.</p>
<p>For example, starting from these two matrices <code>a</code> and <code>b</code>:</p>
<pre><code>sage: a = matrix(QQ, [[1, 1, 1], [-2, 3, 2], [0, 1, 2]])
sage: b = matrix(QQ, [[-1, 1, 1], [1, 1, -1], [-3, 1, 3]])
</code></pre>
<p>Check that they commute:</p>
<pre><code>sage: a * b
[-3 3 3]
[-1 3 1]
[-5 3 5]
sage: b * a
[-3 3 3]
[-1 3 1]
[-5 3 5]
sage: a * b == b * a
True
</code></pre>
<p>If we diagonalize them separately:</p>
<pre><code>sage: da, pa = a.jordan_form(transformation=True)
sage: db, pb = b.jordan_form(transformation=True)
</code></pre>
<p>we can notice that the transformation matrices <code>pa</code> and <code>pb</code> have the same columns, permuted:</p>
<pre><code>sage: pa
[ 1 1 0]
[ 1 0 1]
[ 1 1 -1]
sage: pb
[ 0 1 1]
[ 1 1 0]
[-1 1 1]
</code></pre>
<p>Obtaining the simultaneous diagonal form is just a matter of reordering the columns of:</p>
<pre><code>sage: da
[3|0|0]
[-+-+-]
[0|2|0]
[-+-+-]
[0|0|1]
sage: db
[2|0|0]
[-+-+-]
[0|1|0]
[-+-+-]
[0|0|0]
</code></pre>
<p>For instance, use the transformation matrix <code>pa</code> to get simultaneous diagonalizations:</p>
<pre><code>sage: qa = ~pa
sage: qa * a * pa
[3 0 0]
[0 2 0]
[0 0 1]
sage: qa * b * pa
[1 0 0]
[0 0 0]
[0 0 2]
</code></pre>
http://ask.sagemath.org/question/40737/simultaneously-diagonalizing-matrices-exactly/?comment=41878#post-id-41878If A has a higher dimensional eigenspace then an eigenvector of A is not necessarily an eigenvector of B. Example: A=[0,1; -1,-1] and B=[1,0; 0,1]. They commute, B is already in diagonal form, and A is not. You need to intersect the eigenspaces of A with those in B and make a basis out of those smaller spaces.Wed, 04 Apr 2018 10:36:03 -0500http://ask.sagemath.org/question/40737/simultaneously-diagonalizing-matrices-exactly/?comment=41878#post-id-41878