help-octave
[Top][All Lists]
Advanced

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

Re: Scalars and Matrices:


From: A. Scottedward Hodel
Subject: Re: Scalars and Matrices:
Date: Tue, 12 Oct 1999 21:36:44 -0500

----------
>From: Mike Miller <address@hidden>
>To: "A. Scottedward Hodel" <address@hidden>
>Cc: help-octave <address@hidden>
>Subject: Re: FW: Scalars and Matrices:
>Date: Tue, Oct 12, 1999, 3:51 PM
>

> Maybe someone can help me understand this.
>
>
>> There can be a difference between 1x1 matrices and scalars.
>>
>> Consider the matrix product A*B*C where
>>
>> A = [1 1]     B = [1]     C=[1]
>> [1]       [2]
>> [3]
>>
>> The product A*B*C is not defined because B*C is not defined.
>
>
> (I don't know what the free-floating [1], [2] and [3] are, so I'll ignore
> them even though I may be making an ass of myself.)
>
> Why is B*C not defined?  Mathematically speaking, isn't the product of a
> 1x1 matrix times a 1x1 matrix also a 1x1 matrix?  If it isn't, it should
> be!  :-)
>
> Is there anything more to the problem than this:  MATLAB doesn't allow use
> of a 1x1 matrix.  That is, MATLAB will redefine a 1x1 matrix as a scalar,
> and the user has no control over that.
>

Sorry; I forwarded the article without fixing mangled spacing.  The
values are:
A = [1,  1 ];     # 1 x 2 row vector
B = [1 ; 1];      # 2 x 1 column vector
C = [1 ; 2 ; 3];  # 3 x 1 column vector; could be any length, as long as its
                  # a column
this_works    = (A*B)*C;
this_does_too = A*B*C;
this_fails    = A*(B*C);

With scalar = 1x1 matrix, (A*B)*C is defined, but A*(B*C) is not.  It's an
annoying detail that the order of operations not only changes flop counts,
but even whether or not a result is defined.

There's a price to pay either way: either we accept scalar = 1x1 matrix and
have these "features," or we adopt stronger type casting and lose a lot of
the flexibility of m-files.  For stronger type casting, I suggest writing
C++ .oct files instead.

[and let's not get started on whether we should use C++, JAVA, or Ada,
please!]

--
A S Hodel Assoc. Prof. Dept Elect Eng, Auburn Univ,AL  36849-5201
On leave at NASA Marshall Space Flight Center (256) 544-1426
Address until 15 Mar 2000:Mail Code TD-55, MSFC, Alabama, 35812
http://www.eng.auburn.edu/~scotte



---------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.  To ensure
that development continues, see www.che.wisc.edu/octave/giftform.html
Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html
---------------------------------------------------------------------



reply via email to

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