octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: diagonal matrices specializations


From: Jaroslav Hajek
Subject: Re: diagonal matrices specializations
Date: Wed, 3 Dec 2008 14:31:58 +0100

On Wed, Dec 3, 2008 at 1:40 PM, Søren Hauberg <address@hidden> wrote:
> ons, 03 12 2008 kl. 12:51 +0100, skrev Jaroslav Hajek:
>> What do you consider to be the best way of displaying a diagonal matrix?
>> One option is
>>
>> ans =
>> diagonal matrix (5x5)
>> diagonal = 1 2 3 4 5
>>
>> or
>>
>> ans =
>> diagonal matrix (5x5)
>> diagonal =
>> 1
>> 2
>> 3
>> 4
>> 5
>
> I think I'd prefer the latter of these two (perhaps, the numbers should
> be indented with a space or two, though). I don't have a strong opinion
> here, but in general I find column vectors easier to read than row
> vectors. Especially when the elements are complex and have many digits,
> like '1.2345 + 6.78901i'
>

Agreed. My preference was a column vector anyway, for similar reasons.

>> ans =
>> diagonal matrix (5x5)
>>    1       ..      0
>>        2
>>    :       3       :
>>                4
>>    0       ..      5
>>
>> the last form seems attractive, but maybe requires a bit more thinking
>> about how to place the dots etc.
>
> This I don't think will work. It would be very hard to read a 20x20
> matrix in a terminal with a width of 80 chars. But I agree, that it
> looks nice for small matrices.
>

But anyone trying to work visually with 20x20 matrices on a 80-column
terminal is bound to have problems.
I mean, the dense matrices suffer from the same problem, don't they. I
don't really much favor this form, but it's
closest to the existing display, while still emphasizing the diagonal
nature. I think I'll wait for further comments.

>> As a related question, what is the best way to display a permutation matrix?
>
> Hmm, I'm not sure. Perhaps something like
>
> ans =
> permutation matrix (5x5)
>  1 --> 5
>  2 --> 4
>  3 --> 3
>  4 --> 2
>  5 --> 1
>
> for the matrix
>
>  0 0 0 0 1
>  0 0 0 1 0
>  0 0 1 0 0
>  0 1 0 0 0
>  1 0 0 0 0
>
> But I'm not sure.
>
> Søren
>
>

The problem with displaying a permutation is that there are two ways
to view a permutation matrix:
a column permutation matrix (multiplication from the right) and row
permutation (multiplication from the left).
Of course, any permutation matrix can act in both ways, with inverse
permutations.

Btw. I've just discovered that a number of internet sources, including
Wikipedia, have got this wrong:
http://en.wikipedia.org/wiki/Permutation_matrix
(see the equation after "Multiplying a row vector h..." and try it in Octave:
(1:3) * eye(3)([2 3 1],:)
(its even a logical nonsense, because if x*P = x(p) and P*y = y(p),
then x*P*P*y = x*y for all x,y, which would mean that P*P is an
identity).
Another wrong source is
http://mathworld.wolfram.com/PermutationMatrix.html

I don't think there's a universal consensus about which form is the
default, although the two cited source both use row permutation.
An unambiguous way is to simply list the nonzero elements:
ans =
permutation matrix with nonzero elements:
(1,2)
(2,3)
(3,1)

of course, sorted by row/column index gives the row/column
permutation, but if we emphasize that the nonzero elements are listed,
no misinterpretation is possible.

Still, I'll rather wait for more people to comment on this issue. I'll
commit the patches without special printing/saving for the time being.

regards

-- 
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

[Prev in Thread] Current Thread [Next in Thread]