Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 10 Weeks Ago, 5 Days Ago |
Questions Answered: | 4870 |
Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
The computer language must be done in python, the problem is at the bottom of the page. The algorithms given need on the assignment need to be manipulated to work for dot multiplication of a matrix.
Introduction to ProgrammingMatrix MultiplicationThe following program willaddtwo “square arrays.” Note the change from the code we workedon in class.# add 2 square matricesdef add(a,b):lena=len(a)x=[lena*[0] for i in range(lena)]for i in range(lena):for j in range(lena):x[i][j]=a[i][j]+b[i][j]return xx=[[1,1],[1,1]]y=[[1,1],[3,4]]c=add(x,y)print(c)Write a function mult(a,b)thatwill “multiply” the two square matrices a and b as we discussedin class.If we write c=mult(a,b) then c[i][j] will be the dot product of rowiof matrix a with columnjofmatrix b.Recall that if we have 2 lists a and b of the same size, then we can define dot as follows:z=[1,2,3]v=[4,5,6]def dot(a,b):lena=len(a)g=0for i in range(lena):g=g+a[i]*b[i]return gprint(dot(z,v))Problem1. Ask your user for an integer n.2. Create two nXn matrices (two dimensional lists) filled with random integers. Call one A andthe other B.3. Print A and B.4. Multiply (by using the matrix multiplication algorithm) A and B to get matrix C.5. Print matrix C.6. Go back to step 1 and repeat until the user enters “done”.Test out your function on matrices of various sizes. The values in the matrices should begenerated by using randint(). I would suggest using small random numbers so that it will beeasier for you to check.
Attachments:-----------