This file contains hidden or 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 m_pow(matrix, n) | |
local tr = matrix[1][1]+matrix[2][2] -- trace of matrix | |
local s = math.sqrt((matrix[1][1]-matrix[2][2])^2+4*matrix[1][2]*matrix[2][1]) -- sqrt(tr^2 - 4*determinant) | |
local r1 = 0.5*(tr+s) --1st eigenvalue | |
local r2 = tr-r1 --2nd eigenvalue | |
local r1n = r1^n | |
local r2n = r2^n |