Created
August 31, 2012 23:16
-
-
Save chribben/3560851 to your computer and use it in GitHub Desktop.
Matrix multiplication
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
let mulVectors v1 v2 = List.fold2(fun s x y -> s + x * y) 0 v1 v2 | |
let mulMatr m1 m2 = | |
let rec mulMatr'' m1 m2 m3 = | |
let rec mulMatr' m1 m2 v = | |
match m1, m2 with | |
| h1::t1, h2::t2 -> mulMatr' t1 m2 ((mulVectors h1 h2)::v) | |
| [], _ -> List.rev v | |
| _ -> failwith "error in format" | |
match m1, m2 with | |
| h1::t1, h2::t2 -> let v = mulMatr' m1 m2 [] | |
mulMatr'' m1 t2 (v::m3) | |
| _, [] -> List.rev m3 | |
| _ -> failwith "error in format" | |
mulMatr'' m1 m2 [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment