octave-maintainers
[Top][All Lists]
Advanced

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

outer product


From: Fredrik Bülow
Subject: outer product
Date: Tue, 27 Jun 2006 11:59:38 +0200

Hi, on the wish list at
http://www.gnu.org/software/octave/projects.html i fund the following
request:

Given two vectors x and y of length m and n, implement a function
outer (x, y, f) that returns an m-by-n matrix with entries f (x(i),
y(j)). If f is omitted, multiplication is the default. Should probably
work for any vectors, not just if x is a column vector and y is a row
vector.

This can be done simply the one line

reshape (f (x(:)(:,ones(1,length(y)))  (:), \
              y(:)(:,ones(1,length(x))).'(:)),\
           length(x), length(y))

plus a test to see if f is set if the special case should be dealt
with as described.

/Fredrik


reply via email to

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