Question: I need to use bash shell scripting utilities to be able to create the multiply function which is tested by typing ./matrix multiply m1 m2

 I need to use bash shell scripting utilities to be ableto create the multiply function which is tested by typing "./matrix multiply

I need to use bash shell scripting utilities to be able to create the multiply function which is tested by typing "./matrix multiply m1 m2" which should be placed inside a temporary file, and data sent to stdout and stderr when applicable. I am confused about where to start working to multiply the two matrices together. I know I need to read each line of the matrix and use the expr command to multiply, but not sure on how exactly to do that.

Edit: added a different picture that captures the scope of the assignment/question.

matrix multiply MATRIX LEFT MATRIX RIGHT o Prints error message to stderr, nothing to stdout and return value != 0 if: Argument count does not equal 2 (e.g. Argument count is 2 but the file named by either argument is not readable (e.g. The dimensions of the input matrices do not allow them to be multiplied together following the rules of matrix multiplication. o Otherwise, prints the product of both matrices, with the first argument as the left matrix and the second argument as the right matrix, in a valid matrix format to stdout *matrix multiply ml m2 m3 `matrix multiply ml). or `matrix multiply ml no_such_file). nothing to stderr, and returns 0. ('matrix multiply A B' should return A*B, not B*A) In this assignment, you will write a bash shell script that calculates basic matrix operations using input from either a file or stdin. The input will be whole number values separated by tabs into a rectangular matrix. Your script should be able to print the dimensions of a matrix, transpose a matrix, calculate the mean vector of a matrix, add two matrices, and multiply two matrices. You will be using bash builtins and Unix utilities to complete the assignment. Some commands to read up on are while . cat, read, expr, cut, head, tail, uc , and sort. Your script must be called simply "matrix". The general format of the matrix command is: natrix OPERATION [ARGUMENT]... Refer to man(1) (You can do this with the command "man 1 man) for an explanation of the conventional notation regarding command syntax, to understand the line above. Note that many terminals render italic font style as an underline: natrix OPERATION (ARGUMENT]... Specifications Your program must perform the following operations: dims, transpose, mean, add, and multiply. Usage is as follows: matrix dins [MATRIX] matrix transpose [MATRIX] natrix mean [MATRIX] natrix add NATRIX_LEFT MATRIX_RIGHT natrix nultiply MATRIX_LEFT MATRIX_RIGHT The dims, transpose, and mean operations should either perform their respective operations on the file named MATRIX, or on a matrix provided via stdin. The add and multiply operations do not need to process input via stdin. dims should print the dimensions of the matrix as the number of rows, followed by a space, then the number of columns. transpose should reflect the elements of the matrix along the main diagonal. Thus, an MxN matrix will become an NxM matrix and the values along the main diagonal will remain unchanged. mean should take an MxN matrix and return an 1xN row vector, where the first element is the mean of column one, the second element is the mean of column two, and so on. add should take two MxN matrices and add them together element-wise to produce an MxN matrix. add should return an error if the matrices do not have the same dimensions. multiply should take an MxN and NxP matrix and produce an MxP matrix. Note that, unlike addition, matrix multiplication is not commutative. That is A'B != B*A. Here is a brief example of what the output should look like. S cat mi S cat m2 4. $ .atrix dims m1 24 S cat n2 |/matrix dims 4 2 $.atrix add m1 m1 10 12 14 16 S.atrix add m2 m2 10 12 14 16 S./matrix mean m1 $ /matrix transpose mi $ ./matrix multiply mi m2 50 60 114 140 You must check for the right number and format of arguments to matrix. This means that, for example, you must check that a given input file is readable, before attempting to read it. You are not required to test if the input file itself is valid. In other words, the behavior of matrix is undefined when the matrix input is not a valid matrix. for the purposes of this assignment, a valid matrix is a tab-delimited table containing at least one element, where each element is a signed integer, every entry is defined, and the table is rectangular

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!