function out=Diagprod(a,B)
Input:
- a:
column vector
- B:
matrix
Output:
- out:
The expression for the gradient in Eq. (3) ultimately
involves products of the form
 |
(11) |
Here,
takes a vector of length
and forms a very large,
diagonal
matrix, which then
multiples the matrix
. Again, this direct evaluation of the
expression is extremely wasteful of both time and space, and so we
shall provide an function which performs the operation in terms of a
more efficient selection of BLAS routines.
In terms of components, Eq. (11) becomes
Thus, each column of
may be computed independently as the
``.*'' product of
with the corresponding column of
, a
series of BLAS1 operations. Alternately, by using a little more
memory, the same operation may be carried out with BLAS2 operations
(which in this case run about 2 times faster) by first forming a
matrix of the same size as
with copies of
in each column
and then taking the ``.*'' product, c=(a*ones(1,size(B,2))).*B.
Using this strategy provide a function of the above prototype in the
file ``Diagprod.m''.
Subsections
Tomas Arias
2007-04-12