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.Tue, 18 Aug 2015 09:57:25 -0500Eigenvalues of matrices of Laurent polynomialshttp://ask.sagemath.org/question/28844/eigenvalues-of-matrices-of-laurent-polynomials/Say that I have a matrix whose entries are univariate Laurent polynomials over complex numbers. In that case, I can substitute the variable for non-zero complex numbers to obtain an ordinary complex matrix. My question is the following: what the correct way to obtain the eigenvalues of the resulting complex matrix? My first guess was to do something like the following which just throws a NotImplementedError:
sage: R = LaurentPolynomialRing(CC, 'x')
sage: x = R.gens()[0]
sage: m = matrix([[x]])
sage: m.subs({x: 2}).eigenvalues()Fri, 14 Aug 2015 09:26:16 -0500http://ask.sagemath.org/question/28844/eigenvalues-of-matrices-of-laurent-polynomials/Answer by nbruin for <p>Say that I have a matrix whose entries are univariate Laurent polynomials over complex numbers. In that case, I can substitute the variable for non-zero complex numbers to obtain an ordinary complex matrix. My question is the following: what the correct way to obtain the eigenvalues of the resulting complex matrix? My first guess was to do something like the following which just throws a NotImplementedError:</p>
<pre><code>sage: R = LaurentPolynomialRing(CC, 'x')
sage: x = R.gens()[0]
sage: m = matrix([[x]])
sage: m.subs({x: 2}).eigenvalues()
</code></pre>
http://ask.sagemath.org/question/28844/eigenvalues-of-matrices-of-laurent-polynomials/?answer=28847#post-id-28847One structural way of obtaining the answer you want is to first define the homomorphism from the laurent series ring to CC (or whatever ring you want); in your case the one obtained from substituting a particular complex value for x:
sage: s=Hom(R,CC)(2)
sage: s
Ring morphism:
From: Univariate Laurent Polynomial Ring in x over Complex Field with 53 bits of precision
To: Complex Field with 53 bits of precision
Defn: 1.00000000000000*x |--> 2.00000000000000
Making sure this gets applied to a matrix properly is now just (tedious) bookkeeping:
sage: mm=matrix(s.codomain(),m.nrows(),m.ncols(),[s(n) for n in m.list()] )
sage: mm.eigenvalues()
... UserWarning ...
[2.00000000000000]
Ideally, sage would know how to do the bookkeeping so that the definition of `mm` above can be written as
sage: mm=m.change_ring(s)
<doesn't work currently>
Fri, 14 Aug 2015 13:22:36 -0500http://ask.sagemath.org/question/28844/eigenvalues-of-matrices-of-laurent-polynomials/?answer=28847#post-id-28847Comment by fuglede for <p>One structural way of obtaining the answer you want is to first define the homomorphism from the laurent series ring to CC (or whatever ring you want); in your case the one obtained from substituting a particular complex value for x:</p>
<pre><code>sage: s=Hom(R,CC)(2)
sage: s
Ring morphism:
From: Univariate Laurent Polynomial Ring in x over Complex Field with 53 bits of precision
To: Complex Field with 53 bits of precision
Defn: 1.00000000000000*x |--> 2.00000000000000
</code></pre>
<p>Making sure this gets applied to a matrix properly is now just (tedious) bookkeeping:</p>
<pre><code>sage: mm=matrix(s.codomain(),m.nrows(),m.ncols(),[s(n) for n in m.list()] )
sage: mm.eigenvalues()
... UserWarning ...
[2.00000000000000]
</code></pre>
<p>Ideally, sage would know how to do the bookkeeping so that the definition of <code>mm</code> above can be written as</p>
<pre><code>sage: mm=m.change_ring(s)
<doesn't work currently>
</code></pre>
http://ask.sagemath.org/question/28844/eigenvalues-of-matrices-of-laurent-polynomials/?comment=28859#post-id-28859Thanks for the answer. I'd upvote both of them if I had the karma.Tue, 18 Aug 2015 09:56:22 -0500http://ask.sagemath.org/question/28844/eigenvalues-of-matrices-of-laurent-polynomials/?comment=28859#post-id-28859Answer by vdelecroix for <p>Say that I have a matrix whose entries are univariate Laurent polynomials over complex numbers. In that case, I can substitute the variable for non-zero complex numbers to obtain an ordinary complex matrix. My question is the following: what the correct way to obtain the eigenvalues of the resulting complex matrix? My first guess was to do something like the following which just throws a NotImplementedError:</p>
<pre><code>sage: R = LaurentPolynomialRing(CC, 'x')
sage: x = R.gens()[0]
sage: m = matrix([[x]])
sage: m.subs({x: 2}).eigenvalues()
</code></pre>
http://ask.sagemath.org/question/28844/eigenvalues-of-matrices-of-laurent-polynomials/?answer=28845#post-id-28845Hello,
The problem with your code is that the substitution does a too naive substitution
sage: R = LaurentPolynomialRing(CC, 'x')
sage: x = R.gens()[0]
sage: m = matrix([[x]])
sage: mm = m.subs({x: 2})
sage: mm.base_ring()
Univariate Laurent Polynomial Ring in x over Complex Field with 53 bits of precision
In order to get eigenvalues, you need to say explicitely that the matrix is now defined over complex numbers
sage: mm.change_ring(CC).eigenvalues()
... UserWarning ...
[2.00000000000000]
EDIT: as mentioned in the comment, the above solution does not work. This is because there is no way to initialize a complex number from a power series, even if it is constant
sage: a = R(CC(2,1))
sage: CC(a)
Traceback (most recent call last):
...
TypeError: unable to coerce to a ComplexNumber: <type 'sage.rings.power_series_poly.PowerSeries_poly'>
In the case the constant is real it works by some strange magic.
VincentFri, 14 Aug 2015 09:45:39 -0500http://ask.sagemath.org/question/28844/eigenvalues-of-matrices-of-laurent-polynomials/?answer=28845#post-id-28845Comment by fuglede for <p>Hello,</p>
<p>The problem with your code is that the substitution does a too naive substitution </p>
<pre><code>sage: R = LaurentPolynomialRing(CC, 'x')
sage: x = R.gens()[0]
sage: m = matrix([[x]])
sage: mm = m.subs({x: 2})
sage: mm.base_ring()
Univariate Laurent Polynomial Ring in x over Complex Field with 53 bits of precision
</code></pre>
<p>In order to get eigenvalues, you need to say explicitely that the matrix is now defined over complex numbers</p>
<pre><code>sage: mm.change_ring(CC).eigenvalues()
... UserWarning ...
[2.00000000000000]
</code></pre>
<p>EDIT: as mentioned in the comment, the above solution does not work. This is because there is no way to initialize a complex number from a power series, even if it is constant</p>
<pre><code>sage: a = R(CC(2,1))
sage: CC(a)
Traceback (most recent call last):
...
TypeError: unable to coerce to a ComplexNumber: <type 'sage.rings.power_series_poly.PowerSeries_poly'>
</code></pre>
<p>In the case the constant is real it works by some strange magic.</p>
<p>Vincent</p>
http://ask.sagemath.org/question/28844/eigenvalues-of-matrices-of-laurent-polynomials/?comment=28860#post-id-28860Nifty. Hope that one goes through. I've accepted the other answer as it does the job for now.Tue, 18 Aug 2015 09:57:25 -0500http://ask.sagemath.org/question/28844/eigenvalues-of-matrices-of-laurent-polynomials/?comment=28860#post-id-28860Comment by vdelecroix for <p>Hello,</p>
<p>The problem with your code is that the substitution does a too naive substitution </p>
<pre><code>sage: R = LaurentPolynomialRing(CC, 'x')
sage: x = R.gens()[0]
sage: m = matrix([[x]])
sage: mm = m.subs({x: 2})
sage: mm.base_ring()
Univariate Laurent Polynomial Ring in x over Complex Field with 53 bits of precision
</code></pre>
<p>In order to get eigenvalues, you need to say explicitely that the matrix is now defined over complex numbers</p>
<pre><code>sage: mm.change_ring(CC).eigenvalues()
... UserWarning ...
[2.00000000000000]
</code></pre>
<p>EDIT: as mentioned in the comment, the above solution does not work. This is because there is no way to initialize a complex number from a power series, even if it is constant</p>
<pre><code>sage: a = R(CC(2,1))
sage: CC(a)
Traceback (most recent call last):
...
TypeError: unable to coerce to a ComplexNumber: <type 'sage.rings.power_series_poly.PowerSeries_poly'>
</code></pre>
<p>In the case the constant is real it works by some strange magic.</p>
<p>Vincent</p>
http://ask.sagemath.org/question/28844/eigenvalues-of-matrices-of-laurent-polynomials/?comment=28849#post-id-28849I also opened a [sage-devel thread](https://groups.google.com/forum/#!topic/sage-devel/n2Sc8moP7Jk) to modify **matrix.subs()**. It would also be cool to allow constant power series to be converted to their base ring.Sat, 15 Aug 2015 05:04:22 -0500http://ask.sagemath.org/question/28844/eigenvalues-of-matrices-of-laurent-polynomials/?comment=28849#post-id-28849Comment by vdelecroix for <p>Hello,</p>
<p>The problem with your code is that the substitution does a too naive substitution </p>
<pre><code>sage: R = LaurentPolynomialRing(CC, 'x')
sage: x = R.gens()[0]
sage: m = matrix([[x]])
sage: mm = m.subs({x: 2})
sage: mm.base_ring()
Univariate Laurent Polynomial Ring in x over Complex Field with 53 bits of precision
</code></pre>
<p>In order to get eigenvalues, you need to say explicitely that the matrix is now defined over complex numbers</p>
<pre><code>sage: mm.change_ring(CC).eigenvalues()
... UserWarning ...
[2.00000000000000]
</code></pre>
<p>EDIT: as mentioned in the comment, the above solution does not work. This is because there is no way to initialize a complex number from a power series, even if it is constant</p>
<pre><code>sage: a = R(CC(2,1))
sage: CC(a)
Traceback (most recent call last):
...
TypeError: unable to coerce to a ComplexNumber: <type 'sage.rings.power_series_poly.PowerSeries_poly'>
</code></pre>
<p>In the case the constant is real it works by some strange magic.</p>
<p>Vincent</p>
http://ask.sagemath.org/question/28844/eigenvalues-of-matrices-of-laurent-polynomials/?comment=28848#post-id-28848I edited my answer...Sat, 15 Aug 2015 04:45:57 -0500http://ask.sagemath.org/question/28844/eigenvalues-of-matrices-of-laurent-polynomials/?comment=28848#post-id-28848Comment by fuglede for <p>Hello,</p>
<p>The problem with your code is that the substitution does a too naive substitution </p>
<pre><code>sage: R = LaurentPolynomialRing(CC, 'x')
sage: x = R.gens()[0]
sage: m = matrix([[x]])
sage: mm = m.subs({x: 2})
sage: mm.base_ring()
Univariate Laurent Polynomial Ring in x over Complex Field with 53 bits of precision
</code></pre>
<p>In order to get eigenvalues, you need to say explicitely that the matrix is now defined over complex numbers</p>
<pre><code>sage: mm.change_ring(CC).eigenvalues()
... UserWarning ...
[2.00000000000000]
</code></pre>
<p>EDIT: as mentioned in the comment, the above solution does not work. This is because there is no way to initialize a complex number from a power series, even if it is constant</p>
<pre><code>sage: a = R(CC(2,1))
sage: CC(a)
Traceback (most recent call last):
...
TypeError: unable to coerce to a ComplexNumber: <type 'sage.rings.power_series_poly.PowerSeries_poly'>
</code></pre>
<p>In the case the constant is real it works by some strange magic.</p>
<p>Vincent</p>
http://ask.sagemath.org/question/28844/eigenvalues-of-matrices-of-laurent-polynomials/?comment=28846#post-id-28846Thanks for the answer. That almost works. If I replace the '2' of the example by a non-real, though, I get a TypeError instead. Can anything be done about that?Fri, 14 Aug 2015 10:04:18 -0500http://ask.sagemath.org/question/28844/eigenvalues-of-matrices-of-laurent-polynomials/?comment=28846#post-id-28846