# Is there any numerical reason for not using repeated multiplication instead of integer powers?

I recently discovered that, in MATLAB 2013b at least, it is significantly faster to do repeated multiplication rather than integer powers. That is,

tic;test4p = a.^4;toc


is much slower than

tic;test4m = a.*a.*a.*a;toc


See http://www.walkingrandomly.com/?p=5377 for full details. Is there any numerical reason (accuracy etc) why repeated multiplication might be a bad idea?

• Are you sure that matlab is using integer powers? If you try with a biger number (20) test4p is taking amost the same time but test4m is taking much more than before. – sebas Feb 27 '14 at 0:36
• What happens if you try a.^3.14 ? If MATLAB is using a general purpose exponentiation routine (e.g. by using log() and exp()), then it should take the same time as a.^4. – Brian Borchers Feb 27 '14 at 4:58