Given an m-by-n matrix A and an n-by-k matrix B, the product of A and B is an m-
ID: 3848676 • Letter: G
Question
Given an m-by-n matrix A and an n-by-k matrix B, the product of A and B is an m-by-k matrix whose entry in position (i, j) is the inner product of row i of A with column j of B. For example, (1 4 2 5 3 6) (0 3 1 1 2 2) = (9 21 11 26) Write an uncurried F# function to do matrix multiplication (assuming the dimensions of two given matrices are appropriate): > multiply ([1; 2; 3]; [4; 5; 6]], [[0; 1]; [3; 2]; [1; 2]]);; val it: int list list = [[9; 11]; [21; 26]]Explanation / Answer
inner and List map let rec transpose = function | (_::_)::_ as M -> List.map List.head M :: transpose (List.map List.tail M) | _ -> [] Matrix multiplication code: let multiply xa ya = [for rows in xa -> [for cols in transpose ya -> inner rows cols]]
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.