سؤال

I am really confused about the computation speed of Matlab or Octave.

How is it possible to give the result of a computation like 5^5^5^5 (= 2.351*10^87 if you wanna know) instantly?

I found some results about the speed for matrix computations (this article), but nothing about other matters. And this is not the explanation (my (naive) implementation in Python is running for about 5 minutes right now).

هل كانت مفيدة؟

المحلول

5^5^5^5 doesn't require so many operations after all. For example, at each power step, say a^b, you can compute exp(log(a)*b), which gives the same result.

I'm not saying this is necessarily how Matlab does it, and there may be numerical precision issues. But this illustrates that a multiple-power operation is not so hard as its direct computation would suggest.

As for numerical precision:

>> format long
>> 5^5^5^5
ans =
    2.350988701644576e+087
>> exp(log(exp(log(exp(log(5)*5))*5))*5)
ans =
    2.350988701644561e+087

The relative error is

>> 1 - (5^5^5^5 / exp(log(exp(log(exp(log(5)*5))*5))*5))
ans =
   -6.661338147750939e-015

which is not very far from eps.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top