help-octave
[Top][All Lists]
Advanced

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

product of empty vectors


From: Douglas Harder
Subject: product of empty vectors
Date: Fri, 23 May 2003 13:24:50 -0500

Octave's handling of empty matrices is a little odd:

>> a = 1:2 
a =
  1  2
>> a(1:0)
ans = []
>> ans * ans'   % this should be 0
ans = []
>> ans + 3
ans = []

In Matlab:

a =
     1     2
>> a(1:0)
ans =
   Empty matrix: 1-by-0
>> ans * ans'
ans =
     0
>> ans + 3
ans =
     3

Maple gives you the same result:

> V := <x>;
                               V := [x]
> V[1..0];
                                  []
> LinearAlgebra:-Transpose( % ) . %;
                                  0

The given matrix is a 1x0 (or in Maple's case, a 0x1) but in either case,
the product of a 1x0 and a 0x1 matrix should be 1x1, hence 0.

I suspect the author was trying to be 'correct', but this inconsistency
makes it difficult to generate general algorthms -- you always have to
check for the trivial case.

Actually, it seems that Octave is cheating:

>> a = 1:2 
a =
  1  2
>> a(1:0)
ans = []
>> size(ans)
ans =
        0        0

This should still be 1x0.  Hopefully this wasn't a design decision in
Octave to convert all empty matrices to 0x0.  While all the mathematicians
at Maple and MathWorks agreeing on something does not necessarily make it
correct, I think it suggests that it is worth looking at.  (I worked at WMI
for 5 years in the math group.)  I tried looking at the Octave source
code, but not knowing where to start, I thought it would be easier to
report this.

Thanks,

Douglas
-- 
# Douglas Wilhelm Harder -: 3- -.- =.- -: -3 .* =. -:- :- . -: .= -:- * -:- -.
# Department of Electrical and Computer Engineering   http://ece.uwaterloo.ca/
# University of Waterloo           http://cheetah.vlsi.uwaterl**.ca/~dwharder/
# .___ DC 2703  519-885-1211 x7023                  http://links.uwaterloo.ca/
# EII \      ."""".      .-----._____.-----._______.-----._____.-----._____.--
#  DGR \____/      --10--   http://www.scg.uwaterloo.ca/ http://mapleapps.com/



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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