From owner-help-octave at bevo dot che dot wisc dot edu Thu Nov 14 21:38:54 1996 Subject: Re: Efficient multiplication by a diagonal matrix From: "John W. Eaton" To: SANDS at VSDEC dot NL dot NUWC dot NAVY dot MIL Cc: mstorti at galileo dot unl dot edu dot ar, help-octave@bevo.che.wisc.edu Date: Thu, 14 Nov 1996 21:37:57 -0600 On 14-Nov-1996, SANDS at vsdec dot nl dot nuwc dot navy dot mil wrote: : B=kron(v,ones(1,m)).*A; Yes, kron will definitely be slow because it uses interpreted loops. : B=v(:,ones(1,m)) .* A; This will be fairly fast. In the test I ran, with v = rand (1000,1) and m = 10, it was nearly 600 times faster than kron. For some cases though, v * ones(1,m) .* A will actually be faster, at least in Octave. If the .* operator is overloaded to do the job of row and column scaling, then I would expect that v .* A will be faster than any of the other methods. It will also use less memory, which might turn out to be important if length(v) columns(A) are both large. It might even be easier to read, too. So, why am I writing this instead of implementing that? :-) jwe