Question: F# Programming The transpose of a matrix M is the matrix obtained by reflecting M about its diagonal. For example, the transpose of / 1
F# Programming
The transpose of a matrix M is the matrix obtained by reflecting M about its diagonal. For example, the transpose of
/ 1 2 3 \
\ 4 5 6 /
is
/ 1 4 \
| 2 5 |
\ 3 6 /
An m-by-n matrix can be represented in F# as a list of m rows, each of which is a list of length n. For example, the first matrix above is represented as the list
[[1;2;3];[4;5;6]]
Write an efficient F# function to compute the transpose of an m-by-n matrix:
> transpose [[1;2;3];[4;5;6]];;
val it : int list list = [[1; 4]; [2; 5]; [3; 6]]
Assume that all the rows in the matrix have the same length.
Hints: transpose [] should give an error message --- Use failwith
transpose [[]] is [] // Input argument is a list with one element, the empty list.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
