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.Sun, 13 Aug 2017 12:24:51 +0200how to get a specific eigenvector only for a given eigenvalue of a matrix say of order 2 by 2 or 3 by 3?https://ask.sagemath.org/question/38501/how-to-get-a-specific-eigenvector-only-for-a-given-eigenvalue-of-a-matrix-say-of-order-2-by-2-or-3-by-3/ how to get a specific eigenvector only for a given eigenvalue of a matrix say of order 2 by 2 or 3 by 3?Thu, 10 Aug 2017 11:15:31 +0200https://ask.sagemath.org/question/38501/how-to-get-a-specific-eigenvector-only-for-a-given-eigenvalue-of-a-matrix-say-of-order-2-by-2-or-3-by-3/Answer by tmonteil for <p>how to get a specific eigenvector only for a given eigenvalue of a matrix say of order 2 by 2 or 3 by 3?</p>
https://ask.sagemath.org/question/38501/how-to-get-a-specific-eigenvector-only-for-a-given-eigenvalue-of-a-matrix-say-of-order-2-by-2-or-3-by-3/?answer=38502#post-id-38502You should better provide concrete examples so that we understand your question.
Let us first create a 3 by 3 random matrix:
sage: m = random_matrix(QQ,3,3) ; m
[ -2 1 -2]
[ 0 0 -2]
[ 0 0 -1/2]
We can find its eigenvalues:
sage: L = m.eigenvalues() ; L
[0, -1/2, -2]
Then, if the interesting one is `-1/2`, let us find its position in the list:
sage: L.index(-1/2)
1
According to the documentatnion of `m.eigenvectors_right`, we can find the list of rignt eigenvectors as a list of tuples "`(e,V,n)` where e is the eigenvalue, V is a list of eigenvectors forming a basis for the corresponding right eigenspace, and n is the algebraic multiplicity of the eigenvalue.":
sage: m.eigenvectors_right()
[(0, [
(1, 2, 0)
], 1), (-1/2, [
(1, 3, 3/4)
], 1), (-2, [
(1, 0, 0)
], 1)]
The are ordered in the same way as with `m.eigenvalues()`, so we can find the tuple associated to the eigenvalue `-1/2` as follows;
sage: m.eigenvectors_right()[L.index(-1/2)]
(-1/2, [
(1, 3, 3/4)
], 1)
We want an eigenvector, so the second entry (with index 1) of this tuple is interesting:
sage: m.eigenvectors_right()[L.index(-1/2)][1]
[
(1, 3, 3/4)
]
SInce we do only want one eigenvector (not the whole basis), let us pick the first entry (with index 0):
sage: m.eigenvectors_right()[L.index(-1/2)][1][0]
(1, 3, 3/4)
Thu, 10 Aug 2017 11:51:07 +0200https://ask.sagemath.org/question/38501/how-to-get-a-specific-eigenvector-only-for-a-given-eigenvalue-of-a-matrix-say-of-order-2-by-2-or-3-by-3/?answer=38502#post-id-38502Comment by rewi for <p>You should better provide concrete examples so that we understand your question.</p>
<p>Let us first create a 3 by 3 random matrix:</p>
<pre><code>sage: m = random_matrix(QQ,3,3) ; m
[ -2 1 -2]
[ 0 0 -2]
[ 0 0 -1/2]
</code></pre>
<p>We can find its eigenvalues:</p>
<pre><code>sage: L = m.eigenvalues() ; L
[0, -1/2, -2]
</code></pre>
<p>Then, if the interesting one is <code>-1/2</code>, let us find its position in the list:</p>
<pre><code>sage: L.index(-1/2)
1
</code></pre>
<p>According to the documentatnion of <code>m.eigenvectors_right</code>, we can find the list of rignt eigenvectors as a list of tuples "<code>(e,V,n)</code> where e is the eigenvalue, V is a list of eigenvectors forming a basis for the corresponding right eigenspace, and n is the algebraic multiplicity of the eigenvalue.":</p>
<pre><code>sage: m.eigenvectors_right()
[(0, [
(1, 2, 0)
], 1), (-1/2, [
(1, 3, 3/4)
], 1), (-2, [
(1, 0, 0)
], 1)]
</code></pre>
<p>The are ordered in the same way as with <code>m.eigenvalues()</code>, so we can find the tuple associated to the eigenvalue <code>-1/2</code> as follows;</p>
<pre><code>sage: m.eigenvectors_right()[L.index(-1/2)]
(-1/2, [
(1, 3, 3/4)
], 1)
</code></pre>
<p>We want an eigenvector, so the second entry (with index 1) of this tuple is interesting:</p>
<pre><code>sage: m.eigenvectors_right()[L.index(-1/2)][1]
[
(1, 3, 3/4)
]
</code></pre>
<p>SInce we do only want one eigenvector (not the whole basis), let us pick the first entry (with index 0):</p>
<pre><code>sage: m.eigenvectors_right()[L.index(-1/2)][1][0]
(1, 3, 3/4)
</code></pre>
https://ask.sagemath.org/question/38501/how-to-get-a-specific-eigenvector-only-for-a-given-eigenvalue-of-a-matrix-say-of-order-2-by-2-or-3-by-3/?comment=38503#post-id-38503Thank you.Thu, 10 Aug 2017 11:58:06 +0200https://ask.sagemath.org/question/38501/how-to-get-a-specific-eigenvector-only-for-a-given-eigenvalue-of-a-matrix-say-of-order-2-by-2-or-3-by-3/?comment=38503#post-id-38503Answer by dan_fulea for <p>how to get a specific eigenvector only for a given eigenvalue of a matrix say of order 2 by 2 or 3 by 3?</p>
https://ask.sagemath.org/question/38501/how-to-get-a-specific-eigenvector-only-for-a-given-eigenvalue-of-a-matrix-say-of-order-2-by-2-or-3-by-3/?answer=38513#post-id-38513One can go directly for the corresponding kernel. For instance:
sage: A = matrix( QQ, 3,3, [4,1,1, 1,4,1, 1,1,4] )
sage: A
[4 1 1]
[1 4 1]
[1 1 4]
sage: E = matrix.identity( A.nrows() )
sage: A.eigenvalues()
[6, 3, 3]
sage: ( A - 3*E ).kernel().basis()
[
(1, 0, -1),
(0, 1, -1)
]Sun, 13 Aug 2017 12:24:51 +0200https://ask.sagemath.org/question/38501/how-to-get-a-specific-eigenvector-only-for-a-given-eigenvalue-of-a-matrix-say-of-order-2-by-2-or-3-by-3/?answer=38513#post-id-38513