I think the problem is that around a dimension of 1434 or 1435, the values of MatrixExp
overflow and become arbitrary precision. Perhaps the variation in the length of the computation from one to a couple hundred seconds depends on when in the process the overflow occurs. Here is the value where the overflow occurs:
$MaxMachineNumber
Log[%]
(*
1.79769*10^308
709.783
*)
Here are a couple of moderately slow 1433 x 1433 matrix-exp examples:
SeedRandom[43];
mat = RandomReal[{0, 1}, {1433, 1433}];
AbsoluteTiming[MatrixExp[mat]] // {First[#], Max[#]} &
SeedRandom[46];
mat = RandomReal[{0, 1}, {1433, 1433}];
AbsoluteTiming[MatrixExp[mat]] // {First[#], Max[#]} &
(*
{1.0524, 1.95253982970992315484748662011721804771`15.954589770191005*^308}
{5.24424, 2.0507373364279982188754557848574924788`15.954589770191005*^308}
*)
Here is a relatively fast 2000 x 2000 example:
SeedRandom[43]; (* any seed will do, I think *)
mat = RandomReal[{0, 1/10}, {2000, 2000}];
AbsoluteTiming[MatrixExp[mat]] // {First[#], Max[#]} &
(*
{0.797571, 1.5334042747017165`*^40}
*)
The slower ones are arbitrary-precision and the faster are machine-precision. Sometimes the arbitrary-precision examples are only a little slower. The slowest example I have observed was a 1435 x 1435 matrix at 360 sec.
This 5000 x 5000 example takes around 11 sec. even though it stays at machine precision. It's a fairly large matrix, though.
SeedRandom[1];
mat = RandomReal[{0, 1/10}, {5000, 5000}];
AbsoluteTiming[MatrixExp[mat]] // {First[#], Max[#]} &
(*
{10.7786, 7.99613*10^104}
*)
Note the max entry of the matrix exponential of an $n \times n$ matrix with uniformly distributed entries between $0$ and $b$ seems to be around $\exp(b n/2)/n$. Compare with the previous $n=5000,\ b=1/10$ example:
Exp[1/10 * 5000 / 2.] / 5000
(*
7.49291*10^104
*)
I don't know if this asymptotic approximation is the case — surely it would be known if it is. It has just seemed to be the case in the examples I have run. It also gives an idea why $n=1434,\ b=1$ is around the the machine-to-arbitrary precision jump in timing:
Exp[1434/2.*1]/1434
$MaxMachineNumber
(*
1.708418923521*10^308
1.79769*10^308
*)
0.36
for the1433
size and a wapping 157 seconds for the 1435 size. This could be related to which version on Intel MKL is used if any by Mathematica. I had similar sudden change of timing when doing Matrix rank. see cpu-timing-for-matrix-rank-calculation At matrix size over 2500, even by just one, a dramatic speed increase was seen. In your case it is sudden speed decrease. $\endgroup$MatrixExp
will help. screen shot i.sstatic.net/L9935bdr.png $\endgroup$