Question: Matrix multiplication in OCAML Please help with a question in OCaml This problem deals with operations on matrices of numbers. To represent matrices, we will
Matrix multiplication in OCAML
Please help with a question in OCaml
This problem deals with operations on matrices of numbers. To represent matrices, we will use a list of lists of numbers, where the ith list corresponds to the ith row of the matrix. For example, the list
[ [3; 17; 32]; [2; 10; 4]; [7; 5; 9] ]
corresponds to a 3 3 matrix whose first row has the numbers 3, 17 and 32, whose second row has the numbers 2, 10 and 4 and whose last row has the numbers 7, 5 and 9.
For a list of lists of this kind to qualify as a matrix, every row must have an equal number of columns. Define a function
is_matrix : (int list) list -> bool
that returns true or false depending on whether or not the given list of lists of integers represents a "good" matrix.
Define a function
matrix_scalar_multiply : (int list) list -> int -> (int list) list
that will generate a new matrix from a given one by multiplying each element by the given number. For example, you should see the following kind of interaction based on this function:
# matrix_scalar_multiply [ [3; 17; 32]; [2; 10; 4]; [7; 5; 9] ] 5;; - : int list list = [[15; 85; 160]; [10; 50; 20]; [35; 25; 45]] #
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
