From owner-help-octave at bevo dot che dot wisc dot edu Thu Nov 14 20:20:14 1996 Subject: Re: Efficient multiplication by a diagonal matrix From: SANDS at VSDEC dot NL dot NUWC dot NAVY dot MIL To: mstorti at galileo dot unl dot edu dot ar Cc: help-octave at bevo dot che dot wisc dot edu Date: Thu, 14 Nov 1996 21:19:59 -0400 (EDT) Mario Storti writes: [stuff deleted] >But it is equivalent to kron(v,ones(1,m)) and it has the same problems >of inefficiency as mentioned in the original post: Not so! In B=kron(v,ones(1,m)).*A; the first factor (kron(v,ones(1,m))) is calculated by actually carrying out a number of scalar multiplications in the computer (if you look at the source for kron you'll see that you have the additional overhead of performing loops in the high level MATLABish language-- very costly!) However by using "Tony's Trick" the first factor in B=v(:,ones(1,m)) .* A; is determined by simply copying the elements of v into memory--a potentially *much* faster operation (depending on your hardware). I'm not sure about how Tony's Trick is carried out in octave but I'm fairly certain that the MATLAB interpreter is smart about how it executes such indexing operations. I've never performed actual tests to compare the two (because I never thought of using kron to accomplish this operation) so I can't say with absolute certainty which is faster. Scott Sands