# bug #30571: expm of diagonal matrices

 Submitted by: Marco Caliari Submitted on: Wed 28 Jul 2010 08:14:06 AM UTC Category: None Severity: 3 - Normal Priority: 5 - Normal Item Group: Feature Request Status: Fixed Assigned to: Jaroslav Hajek Originator Name: Open/Closed: Closed Release: 3.3.51 Operating System: GNU/Linux

You are not logged in

## Discussion

Thu 29 Jul 2010 08:04:00 AM UTC, comment #5:

Why do you need diagonal sparse matrices to be special cased? You're free to add that feature, of course, I just don't see much use for it.

Jaroslav Hajek <highegg>
Thu 29 Jul 2010 07:58:59 AM UTC, comment #4:

I'm just speaking of "diagonal sparse" matrices.
The exponential of "general" sparse matrices is not sparse, so I think it is not a problem if balance can't handle them.

Marco

Marco Caliari <caliari>
Thu 29 Jul 2010 07:49:17 AM UTC, comment #3:

Why does it matter?
Btw., expm is not working well with sparse matrices at all, because apparently balance() can't handle them.

Jaroslav Hajek <highegg>
Thu 29 Jul 2010 07:11:32 AM UTC, comment #2:

It seems that sparse diagonal matrices are excluded:

octave:1> typeinfo (speye (4))
ans = sparse matrix
octave:2> typeinfo (full (speye (4)))
ans = matrix
octave:3> matrix_type (speye (4))
ans = Diagonal

This was the reason to use matrix_type.

Marco

Marco Caliari <caliari>
Thu 29 Jul 2010 06:53:14 AM UTC, comment #1:

First, a scalar is a scalar, not a diagonal matrix.

Second, I'd say ignore the MatrixType check. This is mostly historical and will only be true for matrices that just happen to be diagonal as a result of a computation.

Third, like it or not, typeinfo names include class, so you can have "diagonal matrix" as well as "float complex diagonal matrix",
so using strfind is a better idea. Beware also of "scalar struct" (though scalars can be checked by isscalar()).

I checked in the following change instead:
http://hg.savannah.gnu.org/hgweb/octave/rev/1646bd8e3735

Jaroslav Hajek <highegg>
Wed 28 Jul 2010 08:14:06 AM UTC, original submission:

With the enclosed patch against 3.3.51, expm will reduce to exp on diagonal matrices. By the way, do we really need three comparisons to check if a matrix is diagonal?

Marco

Marco Caliari <caliari>

## Attached Files

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Comment:

Attached Files
file #21092:  expm.m.diff added by caliari (459B - text/x-patch)

## Dependencies

Depends on the following items: None found

Items that depend on this one: None found

Carbon-Copy List
• -email is unavailable- added by rik5 (Updated the item)
• -email is unavailable- added by highegg (Posted a comment)
• -email is unavailable- added by caliari (Submitted the item)
•

Do you think this task is very important?
This task has 0 encouragements so far.

Only project members can vote.