Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does matlab run this code so quickly?

Tags:

matrix

matlab

I have this code in matlab

b = 0.25*ones(4)
a = [0 1 1 1 ; 1/3 0 0 0 ; 1/3 0 0 0; 1/3 0 0 0] 

m = .85*a + .15*b

v = [1/4 1/4 1/4 1/4]

m^1e308*v'
  1. How does matlab run m^1e308*v' so quickly? it should mutiply the matrix 1e300 times, but it probably do some other calculation, what is it?
  2. why does m^1e309*v' gives :

    ans =

       NaN
       NaN
       NaN
       NaN
    
  3. how can I see what m^inf is without using symbolic variables?

like image 298
0x90 Avatar asked Aug 04 '26 21:08

0x90


1 Answers

How does matlab run m^1e308*v' so quickly?

I can't tell you what the internals of Matlab are doing, but note that in general, A^n can be done in O(log n) time, not O(n) time.

For example, A^16 = (((A^2)^2)^2)^2.

You can also use the eigendecomposition to turn this into scalar powering, i.e. if A = U*V*U', then the power is U * V^N * U', where V is a diagonal matrix.

why does m^1e309*v' give NaN?

Double-precision cannot represent 1e309.

how can I see what m^inf is without using symbolic variables?

Use the eigendecomposition described above. If any of the eigenvalues are smaller than 1, they will go to 0, if any of them are greater than 1, they will go to infinity.

like image 98
Oliver Charlesworth Avatar answered Aug 07 '26 21:08

Oliver Charlesworth