
124 Accelerating MATLAB
®
Performance
% Using repeated multiplication - 25x faster!
b = a.*a.*a.*a;
⇨ Elapsed time is 0.031922 seconds.
John D’Errico’s HPF (Big Decimal Arithmetic) utility
310
includes a variety of similar opti-
mizations for numeric computations, including optimizing Taylor expansions
311
and itera-
tive Newton’s method
312
for rapid convergence. A simple example of strength reduction is
replacing a division by 5 by a decrement of the exponent (=/10) and a single shift of the
mantissa (=*2).
The HPF utility is massive (~7000 lines of code) but extremely well documented, and is
well worth reviewing. Quoting John from HPF’s webp