Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Homework 1 Matrix Multiplication Due: January 30, 2019 In mathematics, matrix multiplication or the matrix product is a binary operation that produces a matrix from

image text in transcribed
image text in transcribed
image text in transcribed
Homework 1 Matrix Multiplication Due: January 30, 2019 In mathematics, matrix multiplication or the matrix product is a binary operation that produces a matrix from two matrices. If Aisan n m matrix and Bisan m p matrix, their matrix product AB is annxp matrix, in which the m entries across a row of A are multiplied with the m entries down a columns of B and summed to produce an entry of AB. For example, when two matrices A and B are: a1,1 a1a A 021 a2a2m their matrix product AB is: AB where In the above, auy is the value at the i-th row and j-th column of a matrix A. Write a program (called matrixprod.exx) that 1. receives list of file names, cach of which has data for a matrix such as row and column sizes and elements 2. create matrices (2D arrays) from the filenames, 3. calculate the matrix product of the matrices, and 4 write the matrix product to the console. If you run your program as ./matrixprod A.txt B.txt then your program should read the matrix A from A.txt, read the matrix B from B.txt, and write the matrix product AB to the console. You are provided the following startup files: /home/cmpsc122/s19/hw1/matrixprod.cxx You can find the main function in matrixprod.cxx. You can compile the program using the following command: sg -ansi -pedantic -Wall matrixprod.cxx -o matrixprod The startup program has the following three unimplemented or char* filepath, int& rows, ints cols); A_rows, int A cols, double** ReadMatrix(chars double* MatrixProduct (double A, int A double. B, int B_rows, int B_cols, int& rows, int& cols) int main(int arge, char* argv[]); 27.39 ath, and returns a 2D The ReadMatrix function reads a matrix from a file whose path The function also respectively. The rix function reads a matris from a file whose path is given by filepath, and returns a returns column width and row width of the returned matrix as col width a MatrixProduct function returns a 2D array that is the matrix product of A abyS width and row width as col width and rot Midth by references, respectively. The startup program also h finction that writes the matrix's column width, row width, and elements to the console. The main functio te from comma eadMatrix, MatrixProduct,and ritetar-x functions to perform the matrix product of matrices given from c line arguments, and write the matrix product to the console. Follow the following 3 steps to complete your homework 1. (30 points) Read a matrix from a file and write it to the console Let A.txt have the following contents 1.1 2.2 3.3 4.4 5.5 6.6 The first line indicates the size of the matric: 2 x 3. The second line shows the elements of the first row. The third next line shows the elements of the second row. The values in each line are separated by a Running your program as ./matrixprod A.txt should write the following output to the console 2 3 1.1 2.2 3.3 4.4 5.5 6.6 Note that output format is the same to the format of the input file (A.txt). 2. (40 points) Read two matrices and write their product to the console Let B.txt (for the matrix B whose size is 2 x 3) have the following contents 1.1 2.2 2.3 1.4 1.5 2.6 Running your program as ./matrixprod A.txt B.txt geld write the following output, which is AD, to th 11.22 14.88 27.39 34.54 s) Read more than two matrices and write their product to the console 3. ( let C.txt (for the matrix C whose size is 2 x 1) have the In a similar 2 1 3.2 Running your program as .atrixprodA.txt B.txt .txt should write the following output, which is ABC, to the console 2 1 57.398 140.657 Note that the above examples are given for you to test your program. When grading your homework, matrices that are no in the above will be used. Additionally, in the 3rd step, multiplying more than four matrices may be used. What to submit Electronic submission (Due: 11:59:59 PM, January 30, 2019) For electronic submission, use mai1122s2 command for section 2 and mai1122s3 command f Readme containing Your personal information at the top (see the syllabus) The exact commands to compile and execute your program The parts you implemented (matrixprod.cxx) Anything that you want the graders to know before grading your code * Use plain ASCII text file (No doc or docx files) o o o matrixprod.cxx o Do not submit any executables mai1122s2 and mail1122s3 will refuse to submit if you include any executables o Do not forget to put your personal information at the top of each file as comments See the syllabus for the information you need to include in your files. Note: If your program does not compile. you will get automatic zero as stated in the syillabus Hardcopy submission (Due: at the beginning of the class, January 31, 2019) -Hardcopies of your source code files - Readme . - Both of the above items must include your personal information at the top

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

Step: 3

blur-text-image

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

Databases Illuminated

Authors: Catherine M. Ricardo, Susan D. Urban, Karen C. Davis

4th Edition

1284231585, 978-1284231588

More Books

Students also viewed these Databases questions