Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions

Question

Understand the basic elements of the promotion mix.

Answered: 1 week ago

Question

=+ Consider practical approaches to policy development.

Answered: 1 week ago