Answered step by step
Verified Expert Solution
Question
1 Approved Answer
USE PYTHON Question I (30 pts): In this question, you are going to write methods that operate on matrices. The program reads values of matrices
USE PYTHON
Question I (30 pts): In this question, you are going to write methods that operate on matrices. The program reads values of matrices A, B, and C stored in a file called inputs.txt. This file should be placed under current directory where you have the program. The first line before each matrix contains the number of rows and the number of columns as shown below. 44 55555556 66666667 77777778 88888889 44 1234 2222 3333 4444 44 11121314 22242425 33343536 44454647 As a first step, the program reads data for matrices A, B and C from inputs.txt file and write them into console. A fourth matrix D is generated randomly and printed. A partial program code is given below. def +11MatrixRandonly(nueberofRows, nunberoficolunns ); matrix = [1 a Crote an entiy Itst for now in range(numberofkows); natrix, append([]) o add ant enpty new how for colum in range(numberofcolumns); natrix[ row ] - append (randon-fandInt (6,99)) return matrix def generatezeromatrix(nunberofkows, nunberofcolums) z natrix = [ [ a for i in range(numberofiows) ] for i in range(nunberotcolunns) I return matrix def addatrix (A,B) : c = generateZeroMatrix (len(A),len(A[e])) fer row in range (len(A)) : for column in range(len (A row ])) : return c [row][colunn] = A[row][column] + [row][column] A Redirect standard output device (consote) to output. txt file if print statements will write tnto output, txt file sys, stdout = open('output, txt", " ) print("Vnkeading data from inputs. tat file in current directaryln*) f=open(" inputs.txt","r) a head mutrix a 11ne = f.readline() nunberofiows, numberofColunns o [1nt (x) for x in 11ne.split(" ")] A = readiatrix(numberoftiows , nunberofColunns, f) print(" *ow matrix A "seo ") printMatrix(A) If Aread Natrix d line = f, readline(?) nunberofthows, numberofcolums =[ln(x) for x in line.split(" ")] B= readatrix(numberofkows, nunberoficolunns, f) print(" *ow matrix 8 *ow ") printMatrix(E) * finad Matrix c line = f-readilne() nunberofilows, numberofColunns =[ int (x) for x in line.split(" ")] c - readiatrix (numberoffows, numberafColunns, f ) print(" **w Materix c wow ) printMatrix(c) a Gienerate 44 mutria from randon nuatery. 0 a A111Matr Ixkandon1y (nunberofRows, numberDfColums) print ( * *owo Matirin D **** *) printKatrix(D) E Computr 5 = (A+B) + Tranipoie (D)=CA print ( V V *o Conputing S=(AB)+ Transpose (D)+C+A *n (A) E FI=A+B T1 = multiplydeatrlx {Ap,B} printmatedx(T1) main() (A,B) def transpose(A) def aanoftlenents(A) def subtracthatrix (A,B) The program will calculate S=(AB)+ Transpose(D) +C - A and find the maximum element in 5 . Complete the code given above so that it will produce an output the format of your output will be like as follows (numbers in the matrices can differ): Reading data fron inputs.txt file in current directory Computing S=(AB)+ Transpose(D) +CA 50127514867456807450736986935734Matrix55242425Matrix7346632975298177Matrix73866410T2=33343536T3(AB)+transpose(D)7976596671487523T4=(AB)+transpose(D)+C79906057Transpose(D)**4445464719517786994259921105787903 74967421***Matrix8638566874197333MaximumElementinS=18522![image text in transcribed](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66effb7ca6102_51666effb7c51a38.jpg)
![image text in transcribed](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66effb7d3e2e1_51666effb7cd0684.jpg)
![image text in transcribed](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66effb7dd47b2_51766effb7d7581d.jpg)
![image text in transcribed](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66effb7e5de7e_51866effb7e115f1.jpg)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
![blur-text-image](https://dsd5zvtm8ll6.cloudfront.net/includes/images/document_product_info/blur-text-image.webp)
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](https://dsd5zvtm8ll6.cloudfront.net/includes/images/document_product_info/blur-subtext-image.webp)
Step: 3
![blur-text-image](https://dsd5zvtm8ll6.cloudfront.net/includes/images/document_product_info/blur-subtext-image.webp)
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started