Created
April 5, 2011 18:25
-
-
Save FloooD/904182 to your computer and use it in GitHub Desktop.
should be pretty slow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function matrixpower(m, n) | |
local d = #m | |
local temp = {} | |
local mm = {} | |
for i = 1, d do | |
temp[i] = {} | |
mm[i] = {} | |
for j = 1, d do | |
mm[i][j] = m[i][j] | |
end | |
end | |
for k = 1, n - 1 do | |
for i = 1, d do for j = 1, d do | |
temp[i][j] = 0 | |
for ii = 1, d do | |
temp[i][j] = temp[i][j] + mm[i][ii] * m[ii][j] | |
end | |
end end | |
for i = 1, d do for j = 1, d do | |
mm[i][j] = temp[i][j] | |
end end | |
end | |
return mm | |
end | |
a=matrixpower({{1,2,3},{4,5,6} ,{7,8,9}}, 3) | |
for i=1,3 do for j=1,3 do print(a[i][j]) end end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment