[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Efficient multiplication by a diagonal matrix
From: |
Heber Farnsworth |
Subject: |
Re: Efficient multiplication by a diagonal matrix |
Date: |
Tue, 12 Nov 1996 14:34:22 -0800 (PST) |
There is a function called dmult written by KH <address@hidden>
which is available at
ftp://ftp.tsc.uvigo.es//pub/octave/contrib/m-files/lalgebra/dmult.m
I use it all the time. In my work I often have the need to do something
which is little more complicated but related. That is a row-wise
kronecker product of two matrices. If you need to do this let me know and
I'll send you an m-file I wrote which does it pretty fast.
Heber Farnsworth | Department of Finance
Univerity of Washington | Box 353200
tele: (206) 528-0793 home | Seattle, WA 98195-3200
tele: (206) 543-4773 finance web: http://weber.u.washington.edu/~heberf
fax: (206) 685-9392 email: address@hidden
On Tue, 12 Nov 1996, Mario Storti wrote:
>
> I found myself repeatedly with the following problem. Given a matrix
> A(n,m) and a vector v(n), I have to multiply each row A(j,:) by
> v(j). This is equivalent to compute:
>
> B = diag(v) * A (1)
>
> Now, for large n, (1) is very inefficient, because it requires
> constructing the square matrix diag(v) which requires storage and many
> redundant operations since most elements of diag(v) are null. If n>>m
> then:
>
> B= kron(v,ones(1,m)).*A (2)
>
> does the job and is better. But the more efficient way is computing
> row by row if m>>n and column by column if n>>m. However, I repeat, I
> find this problem so many times and in so many areas that it seems to
> me that some system call should do it.
>
> I wrote some code of my own to do this task, but I wonder if I'm
> redeveloping the wheel. Does anyone have a betetr solution?
>
> Mario
>
> %%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%
> Mario Alberto Storti | Fax: (54)(42) 55.09.44 |
> Grupo de Tecnologia Mecanica | Tel: (54)(42) 55.91.75 |
> INTEC, Guemes 3450 - 3000 Santa Fe | http://venus.unl.edu.ar/gtm-eng.html |
> Argentina | Home: Gob. Vera 3161 |
> Reply: address@hidden | (54)(42) 55.00.23 |
>