In Mathematica 9, (I think) MatrixPower[matrix(m.m), n].vector has complexity $O(m^{2+\epsilon}\times\log(n))$ (Mathematica automatically find the algorithm that optimize the time), while MatrixPower[matrix(m.m), n, vector] has complexity $O(m^2\times n)$. It (the second form) always remain that complexity, sometimes it is good and sometimes bad.
For example:
mat = Table[RandomReal[1./500], {1000}, {1000}];
vec = Table[RandomReal[1./500], {1000}];
MatrixPower[mat, 1000]; // AbsoluteTiming
(* {6.831456, Null} *)
MatrixPower[mat, 1000, vec]; // AbsoluteTiming
(* {2.889963, Null}*)
MatrixPower[mat, 5000]; // AbsoluteTiming
(* {8.150533, Null} *)
MatrixPower[mat, 5000, vec]; // AbsoluteTiming
(* {15.022040, Null}*)
In the first case, it is good, and the second case, it is bad. This seems to be a mistake of the developers.
- How can I determine the power that optimize the time?
- Is that fixed in next versions?
10.4looping over 100 iterations gives me0.2967,0.1128,0.3945,0.6259respectively., so persists. – Feyre Aug 17 '16 at 16:26MatrixExp, http://mathematica.stackexchange.com/questions/121625/matrixexpm-v-not-always-faster-than-matrixexpm-v – user64620 Aug 17 '16 at 23:01