# CS512 Assignment 2 – Working with Square Matrix solution

\$25.00

Original Work ?

## Description

5/5 - (1 vote)

• Write an object oriented program in python that does the following:

• Part a)
• Interactively get a positive number, “n”, from a user
• If “n” is less or equal to 3 report an error and quit the program.
• Otherwise, try to get n*n numbers from the first file.
• For example, if n=5 you are required to get 25 numbers from the first file in order to make a 5 by 5 matrix.
• Therefore, If there is less than 25 numbers in the file, report error and quit the program
• If there are more than 25 numbers (for size 5) from the file, get the first 25 numbers, make a matrix of 5 by 5 and ignore the other numbers

• Part b)
• try to get n*n numbers from the second file.
• If the value of “n” to create the first matrix, you must use the same value “n” to create the second matrix.
• The two matrix should have the same size. So if the first size of the first matrix is 5, the size of the second matrix must be 5 too.
• Again read the integer number from the second file.
• For n=5, If there is less than 25 numbers (for size = 5) in the second file, report error and quit the program
• If there are more than 25 numbers from the file, get the first 25 numbers, make the second matrix of 5 by 5 and ignore the other numbers

• Part c)
• Do the product of the two matrices and print the resulting matrix with proper heading
• Do the dot product of the two matrices and print the resulting matrix with proper heading
• Transpose the first and the second matrices and multiply them with each other and print the resulting matrix with proper heading
• Do the dot product of the transposed matrices and print the resulting matrix with proper heading
• Divide the first matrix by the second one. In case of division by zero you need to show the word “undefined” in the proper matrix location. Print the resulting matrix with proper heading

As I mentioned above, you need to create a class with several function. Your main program should call the appropriate class function and print all your output in an output file with proper heading

Main program should consist of the following:

• N = get a size for a square matrix
• Create an object call it myMatrix
• M1 = myMatrix. GetMatrix(N, file1)
• M2 = myMatrix. GetMatrix(N, file2)
• M1_Multiply_M2 = myMatrix.Product(M1, M2)
• M1_DotMultiply_M2 = myMatrix.DotProduct(M1, M2)
• M1_Trans = myMatrix.Transpose(M1)
• M2_Trans = myMatrix.Transpose(M2)
• M1Trans_Multiply_M2Trans = myMatrix.Product(M1_Trans, M2_Trans)
• M1Trans_DotMultiply_M2Trans = myMatrix.DotProduct(M1_Trans, M2_Trans)

• Print(M1)
• Print(M2)
• Print(M1_Multiply_M2)
• Print(M1_DotMultiply_M2)
• Print(M1_Trans)
• Print(M2_Trans)
• Print(M1Trans_Multiply_M2Trans)
• Print(M1Trans_DotMultiply_M2Trans)