Question
Using F# language. Full and complete answers in order to get credit please ,thank you 1)The transpose of a matrix M is the matrix obtained
Using F# language. Full and complete answers in order to get credit please ,thank you
1)The transpose of a matrix M is the matrix obtained by reflecting Mabout 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-nmatrix:
> 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
2) In this problem and the next, I ask you to analyze code, as discussed in the last section of the Checklist. Suppose we wish to define an F# function to sort a list of integers into non-decreasing order. For example, we would want the following behavior:
> sort [3;1;4;1;5;9;2;6;5];; val it : int list = [1; 1; 2; 3; 4; 5; 5; 6; 9]
We might try the following definition:
let rec sort = function | [] -> [] | [x] -> [x] | x1::x2::xs -> if x1 <= x2 then x1 :: sort (x2::xs) else x2 :: sort (x1::xs)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started