Created
January 20, 2014 00:26
Revisions
-
nnabeyang revised this gist
Jan 30, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ cofactor i j m = [dropAt j v| (v, k) <- zip m [0..], i /= k] det :: Matrix -> Int type Matrix = [[Int]] dropAt :: Int -> [a] -> [a] dropAt i xs = as ++ bs where (as, _ :bs) = splitAt i xs cofactor :: Int -> Int -> Matrix -> Matrix cofactor i j m = [dropAt j v| (v, k) <- zip m [0..], i /= k] det :: Matrix -> Int -
nnabeyang revised this gist
Jan 21, 2014 . No changes.There are no files selected for viewing
-
nnabeyang revised this gist
Jan 21, 2014 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -14,3 +14,9 @@ det m = case m of [[e]] -> e (xs:xss) -> sum [(-1) ^ i * e * (det . cofactor 0 i) m | (e, i) <- zip xs [0..]] ex :: Int ex = det [[1, 2], [3, 4]] -- 1*4 - 2 * 3 = 4 - 6 = -2 -
nnabeyang revised this gist
Jan 21, 2014 . 1 changed file with 10 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,10 +4,13 @@ dropAt i xs = [x| (x, j) <- zip xs [0..], i /= j] cofactor :: Int -> Int -> Matrix -> Matrix cofactor i j m = [dropAt j v| (v, k) <- zip m [0..], i /= k] det :: Matrix -> Int type Matrix = [[Int]] dropAt :: Int -> [a] -> [a] dropAt i xs = [x| (x, j) <- zip xs [0..], i /= j] cofactor :: Int -> Int -> Matrix -> Matrix cofactor i j m = [dropAt j v| (v, k) <- zip m [0..], i /= k] det :: Matrix -> Int det m = case m of [[e]] -> e (xs:xss) -> sum [(-1) ^ i * e * (det . cofactor 0 i) m | (e, i) <- zip xs [0..]] -
nnabeyang created this gist
Jan 20, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ type Matrix = [[Int]] dropAt :: Int -> [a] -> [a] dropAt i xs = [x| (x, j) <- zip xs [0..], i /= j] cofactor :: Int -> Int -> Matrix -> Matrix cofactor i j m = [dropAt j v| (v, k) <- zip m [0..], i /= k] det :: Matrix -> Int det m | n == 1 = m !! 0 !! 0 | n > 1 = sum [(-1) ^ i * e * (det . cofactor 0 i) m | (e, i) <- zip v [0..]] where v = m !! 0 n = length m