octave-maintainers
[Top][All Lists]
Advanced

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

Re: About diagonal matrices


From: Jaroslav Hajek
Subject: Re: About diagonal matrices
Date: Sun, 22 Feb 2009 10:23:42 +0100

On Sat, Feb 21, 2009 at 10:59 PM, Søren Hauberg <address@hidden> wrote:
> lør, 21 02 2009 kl. 16:46 -0500, skrev John W. Eaton:
>> Yes, I understand that it is convenient for many uses for diagonal
>> and sparse matrices to have the properties you want.  But I'm also
>> don't like having things like
>>
>>   full_matrix == diag_matrix
>>
>> yet
>>
>>   diag_matrix * scalar != full_matrix * scalar
>>
>> for some values of scalar.
>
> I don't like this either. But I must say that I really like the reduced
> memory usage that comes with the diagonal matrix type (this has already
> saved me a couple of times). I guess I'm missing the obvious here, but
> couldn't the diagonal matrix class be extended to have a variable that
> holds the value of the non-diagonal elements of the matrix? Usually this
> would be zero, but when the matrix is multiplied with NaN or divided
> with zero, this value would change.
>
> Søren
>
>

Not really. You underestimate the complexity that these demands bring.
Try this in development version:

x = diag ([NaN, 3, 4]); y = diag ([1, 2, 3]);

Now, watch this:

x*y
ans =

   NaN     0     0
     0     6     0
     0     0    12

full (x) * full (y)
ans =

   NaN   NaN   NaN
     0     6     0
     0     0    12

See? Basically, any combination of rows (or columns) can end as NaN.
But it gets worse:
x = diag ([NaN, 3, Inf]); y = diag ([1, 2, 3]);
full (x) * full (y)
ans =

   NaN   NaN   NaN
     0     6     0
   NaN   NaN   Inf

Now imagine the added complexity for the diagonal operations.
One option is to not create a diagonal matrix object at all when NaN
is present. This solves *some* of the issues,
but adds another level of inconsistencies.


-- 
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]