[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: matrix-vector-op class ?
From: |
John W. Eaton |
Subject: |
Re: matrix-vector-op class ? |
Date: |
Thu, 6 Apr 2000 17:29:47 -0500 (CDT) |
On 6-Apr-2000, Paul Kienzle <address@hidden> wrote:
| Why not just stick with the ".*" operator? It is a natural extension
| since scalar .* matrix multiplies each element by that scalar,
| vector .* matrix multiplies each row/column (depending on shape) by
| that vector, and matrix .* matrix multiplies each element-wise. Shape
| must match in 0, 1 or 2 dimensions, and be of length 1 in the remaining
| dimensions.
OK, this has been discussed some before, but is still not
implemented even though it is something that even I would like to
have. So, if we can agree on semantics for the operators, I think I
could implement it reasonably soon.
I'm assuming that we can agree that the `dot' operators are acceptible
for this purpose. So we want to be able to write (for example)
v .* M
or
M .* v
to scale the rows (or columns) of a matrix M by the values in a vector
v, assuming that the length of v is consistent with the number of rows
(or columns) of M.
How should we decide whether the rows or columns are to be scaled?
A simple definition would be that
v .* M == diag (v) * M (row scaling)
M .* v == M * diag (v) (column scaling)
I like this because it is consistent and easy to describe. It is also
easy to tell from the code what is being scaled just by knowing that v
is a vector and M is a matrix.
I have also thought about allowing row or column scaling based on the
orientation of the vector. Then v .* M or M .* v could do either
operation, depending on the orientation of v. My idea is that if v
is a column vector, it scales the rows and if it is a row vector it
scales the columns.
The justification for using a column vector to do row scaling is that
it is easy for me to visualize:
[1] [1 2] [1 2]
[2] .* [4 5] => [8 10]
[3] [7 8] [21 24]
Similarly for column scaling by a row vector (just slide the row
vector above or below the matrix).
I expect to extend the meanings of the operators .+, .-, and ./ in
addition to the .* operator. Someone once suggested that it might
also make sense to have .== or .!= operators that work in a similar
way, but I'm not sure how useful that would be.
Comments?
Thanks,
jwe
-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.che.wisc.edu/octave/octave.html
How to fund new projects: http://www.che.wisc.edu/octave/funding.html
Subscription information: http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------