eigenvalues and eigenvectors for matrices

27 views
Skip to first unread message

Jason Grout

unread,
Apr 3, 2008, 6:38:55 AM4/3/08
to sage-...@googlegroups.com
Currently, depending on the matrix type, there are several different
ways to get eigenvalues and eigenvectors and it is hard to remember
which function goes with which type.

How about we unify the interface?

Proposal:

eigenspaces: Return a list of tuples, the first element being an
eigenvalue and the second being the associated eigenspace.

eigenvalues: Return a list of eigenvalues.

eigenvectors(left=True, right=False): Return a list of eigenvalues and
an associated matrix (or matrices) containing associated eigenvectors.

*should we have the following?*

eigenvectors_right, eigenvectors_left: Wrapper calls to eigenvalues
which return the eigenvalues and either the left or right eigenvalues.
The function here *starts* with eigen so that tab completion is helpful.

For comparison, Matlab does this with the eig and eigs functions. Mma
has Eigenvalues, Eigenvectors, and Eigensystem (which returns
eigenvalues and eigenvectors).

Thoughts on keeping the current right_eigenvectors and left_eigenvectors?


Thanks,

Jason

David Joyner

unread,
Apr 3, 2008, 6:56:56 AM4/3/08
to sage-...@googlegroups.com
On Thu, Apr 3, 2008 at 6:38 AM, Jason Grout <jason...@creativetrax.com> wrote:
>
> Currently, depending on the matrix type, there are several different
> ways to get eigenvalues and eigenvectors and it is hard to remember
> which function goes with which type.
>
> How about we unify the interface?
>
> Proposal:
>
> eigenspaces: Return a list of tuples, the first element being an
> eigenvalue and the second being the associated eigenspace.
>
> eigenvalues: Return a list of eigenvalues.
>
> eigenvectors(left=True, right=False): Return a list of eigenvalues and
> an associated matrix (or matrices) containing associated eigenvectors.

I like your idea in general but what does eigenvectors(left=True, right=False)
mean?

>
> *should we have the following?*
>
> eigenvectors_right, eigenvectors_left: Wrapper calls to eigenvalues
> which return the eigenvalues and either the left or right eigenvalues.
> The function here *starts* with eigen so that tab completion is helpful.

+1

Jason Grout

unread,
Apr 3, 2008, 7:17:19 AM4/3/08
to sage-...@googlegroups.com
David Joyner wrote:
> On Thu, Apr 3, 2008 at 6:38 AM, Jason Grout <jason...@creativetrax.com> wrote:
>> Currently, depending on the matrix type, there are several different
>> ways to get eigenvalues and eigenvectors and it is hard to remember
>> which function goes with which type.
>>
>> How about we unify the interface?
>>
>> Proposal:
>>
>> eigenspaces: Return a list of tuples, the first element being an
>> eigenvalue and the second being the associated eigenspace.
>>
>> eigenvalues: Return a list of eigenvalues.
>>
>> eigenvectors(left=True, right=False): Return a list of eigenvalues and
>> an associated matrix (or matrices) containing associated eigenvectors.
>
> I like your idea in general but what does eigenvectors(left=True, right=False)
> mean?

Sorry for the confusion:

I want a way to tell eigenvectors that I would like either the right or
left or both sets of eigenvectors. I'm inspired by the interface from
scipy (the scipy.linalg.decomp.eig function):

eigenvectors() returns the eigenvalues and left eigenvectors
eigenvectors(left=True) returns the eigenvalues and left eigenvectors
eigenvectors(right=True) returns the eigenvalues and right eigenvectors
eigenvectors(left=True, right=True) returns the eigenvalues and both
sets of eigenvectors

so basically, I mean the function is defined as

def eigenvectors(left=False, right=False)

but if both are false, then we set left=True anyway so that we have
something to return.

The eig function mentioned above has this signature:

def eig(a,b=None, left=False, right=True, overwrite_a=False,
overwrite_b=False):

So by default, it returns the right eigenvectors. a is the original
matrix; b is the matrix for computing generalized eigenvalues, and the
overwrite parameters are there to tell lapack that it's okay to
overwrite the matrices for speed.


Oh, and the eigenspaces function should have similar left and right
keyword arguments, as well as eigenspaces_left and eigenspaces_right
wrappers.

Thanks,

Jason

Justin C. Walker

unread,
Apr 3, 2008, 10:27:42 AM4/3/08
to sage-...@googlegroups.com

On Apr 3, 2008, at 03:38 , Jason Grout wrote:
>
> Currently, depending on the matrix type, there are several different
> ways to get eigenvalues and eigenvectors and it is hard to remember
> which function goes with which type.
>
> How about we unify the interface?
>
> Proposal:
>
> eigenspaces: Return a list of tuples, the first element being an
> eigenvalue and the second being the associated eigenspace.
>
> eigenvalues: Return a list of eigenvalues.
>
> eigenvectors(left=True, right=False): Return a list of eigenvalues and
> an associated matrix (or matrices) containing associated eigenvectors.

+1 for the above.

> *should we have the following?*
>
> eigenvectors_right, eigenvectors_left: Wrapper calls to eigenvalues
> which return the eigenvalues and either the left or right eigenvalues.
> The function here *starts* with eigen so that tab completion is
> helpful.


I don't see the need, and I'm always leery of overpopulating the
namespace :-} You already have the functionality, and with '?', it is
easily accessible.

Justin

--
They said it couldn't be done, but sometimes,
it doesn't work out that way.
- Casey Stengel
--

William Stein

unread,
Apr 3, 2008, 10:47:25 AM4/3/08
to sage-...@googlegroups.com

+1 to everything Justin just said.

William

Alex Ghitza

unread,
Apr 3, 2008, 10:52:45 AM4/3/08
to sage-...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

+1 as well. And while we're at it, if this gets voted in, we should
change kernel to have a consistent behavior as well, i.e. have

kernel(left=True, right=False)

and get rid of left_kernel() and right_kernel().

Alex


- --
Alexandru Ghitza
Assistant Professor
Department of Mathematics
Colby College
Waterville, ME 04901
http://bayes.colby.edu/~ghitza/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFH9O89dZTaNFFPILgRAgTYAKCNa3phUJk0OPeE+8RGW76h0elJvACfdO/Z
Bw2iHJ9tlSm5N3xa3O9w9aQ=
=UB0u
-----END PGP SIGNATURE-----

Justin C. Walker

unread,
Apr 3, 2008, 11:08:04 AM4/3/08
to sage-...@googlegroups.com

On Apr 3, 2008, at 07:52 , Alex Ghitza wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> William Stein wrote:
> | On Thu, Apr 3, 2008 at 7:27 AM, Justin C. Walker <jus...@mac.com>
> wrote:
> |>
> |> On Apr 3, 2008, at 03:38 , Jason Grout wrote:
[snip]

> |> I don't see the need, and I'm always leery of overpopulating the
> |> namespace :-} You already have the functionality, and with '?',
> it is
> |> easily accessible.
> |>
> |> Justin
> |>
> |
> | +1 to everything Justin just said.
> |
> | William
> |
>
> +1 as well. And while we're at it, if this gets voted in, we should
> change kernel to have a consistent behavior as well, i.e. have
>
> kernel(left=True, right=False)
>
> and get rid of left_kernel() and right_kernel().

+1 for (non-foolish[*]) consistency.

Justin

[*] R.W. Emerson ("A foolish consistency is the hobgoblin of little
minds")

--
Justin C. Walker, Curmudgeon-At-Large
Institute for the Enhancement of the Director's Income
--------
Experience is what you get
when you don't get what you want.
--------

John Cremona

unread,
Apr 3, 2008, 12:27:03 PM4/3/08
to sage-...@googlegroups.com
What about including the eigenvalue multiplicities as well?

John

Robert Bradshaw

unread,
Apr 3, 2008, 12:30:02 PM4/3/08
to sage-...@googlegroups.com
On Apr 3, 2008, at 3:38 AM, Jason Grout wrote:
>
> Currently, depending on the matrix type, there are several different
> ways to get eigenvalues and eigenvectors and it is hard to remember
> which function goes with which type.
>
> How about we unify the interface?

+1 This has bothered me too.

Nick Alexander

unread,
Apr 3, 2008, 2:22:57 PM4/3/08
to sage-...@googlegroups.com
> I don't see the need, and I'm always leery of overpopulating the
> namespace :-} You already have the functionality, and with '?', it is
> easily accessible.

I don't always support synonyms but I do want all those little helper
functions. The point is to make it easy to read code -- eigensystem
() makes the intention clear, whereas (eigenvalues(), eigenvectors())
obscures the meaning. I don't want to lose that declaration of
intent just to keep the namespace small.

Nick

Justin C. Walker

unread,
Apr 3, 2008, 7:30:57 PM4/3/08
to sage-...@googlegroups.com

I'm not objecting to your suggestion above, but:

My comment was mainly about the _right/_left names, but clearly, some
of this is in the eye (or ear) of the beholder. 'eigensystem'
doesn't seem to have the impact for me that it does for you; I could
scratch my head a while trying to dope out what it intended.

Justin

--
Justin C. Walker, Curmudgeon-At-Large

Institute for the Absorption of Federal Funds
--------
If you're not confused,
You're not paying attention
--------

Reply all
Reply to author
Forward
0 new messages