Answered step by step
Verified Expert Solution
Link Copied!

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
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
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=1852275898251S=(AB)transpose(D)+CA73316390757482397243761879356845721876059465995210522783693879863

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

Advances In Databases And Information Systems Second East European Symposium Adbis 98 Poznan Poland September 1998 Proceedings Lncs 1475

Authors: Witold Litwin ,Tadeusz Morzy ,Gottfried Vossen

1st Edition

3540649247, 978-3540649243

More Books

Students also viewed these Databases questions

Question

Technology. Refer to Case

Answered: 1 week ago