Prev: subplot colorbar problem
Next: how to find the center of the circle passing trrough two points no radiustwo
From: Ian Dew-Becker on 26 Mar 2010 05:57 I'm finding that to do an elementwise power, exp(a*log(x)) is about twice as fast as x.^a in many, though not all cases. Does anybody know why this is? I'm wondering if there's a general lesson here about computation speed. In particular, try >> tic; magic(100).^(20); toc Elapsed time is 0.004556 seconds. >> tic; exp(20*log(magic(100))); toc Elapsed time is 0.002557 seconds. this doesn't seem to work for all possible exponents, though. For example, magic(100).^9 works the same both ways. magic(100).^(-9) is again twice as fast using exp
From: Ian Dew-Becker on 26 Mar 2010 06:04
actually, do this instead, it doesn't involve such huge exponents, >> tic; magic(100).^(.2); toc Elapsed time is 0.004058 seconds. >> tic; exp(.2*log(magic(100))); toc Elapsed time is 0.002598 seconds. |