Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Week 2: Linear Algebra In this assignment, you will use Python and Nurmpy to answer questions about linear algebra. Please read the directions carofully to

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Week 2: Linear Algebra In this assignment, you will use Python and Nurmpy to answer questions about linear algebra. Please read the directions carofully to avold submitting answers that are marked incorrect due to formatting mistakes. inport numpy as np Part 1: Matrix Operations by hand 1.1 {1pt] Let F=[[1,2,a],[3,2,1+b],[2,2,2+c]] where a,b, and c ave variables. G=[[0,2+c,a],[3,b+c,1],[a,3,b]] where a, b, and c aro the same variables as in F. What is the value of F+G ? Please store the value in a string variable Sum. FQ written with valid python formatting (e.g. Sum. FG = ' [1,2, a), (3,2,1+b,12,2,2+c]? ). Em YG = Mane * youl coon irest. raitae Notritplethentedirreror () Hidden ceata foz probleie 1,1 are within thin oeld 1.2[1 pt Assurne F and G as above, What is the product of F and G? Please store your answers in a string variable Prod_FG written with vaind python formatting (e,9) Prod FG =1,2,a],{3,2,1+b],[2,2,2+c). Part 2: Matrix Operations with Python 2.1 [1 pt] Write a function called Matrices that takes two matrices A and B, and then returns a dictionary that has four key-value pairs: - sum: the sum of A and B, - difference: A minus B, - product the product of A and B, - elementwise: the elementwise product of A and B. Inputs will be represented as numpy arrays and outputs should also be numpy arrays. In i It def Matrices (A,B) : f rour CODE HKRE raise NotTtpleaentedsrror() In I It ohidden testa for prableat 2.1 are within thia cell 2.2[1 pi] Assume A=252621884 and B=1018482634. What are the addition, subtraction, muitiplicatiort, and elernentwioe prociuct of A and B? Please store your answers in a variable ANS22 formatted as a cictionary as in problem 2.1. Une the function from 2.1. ansert type(Sum_PG) wn str, "Problem 1.1t type of value stored in variable sum_FG does not nateh the expected typo." Thidden tests for problem 1.1 are within this cel1 1.2 [1 pt] Assume F and G as above. What is the product of F and G ? Please store your answers in a string variable Prod_FG written with valid python formating (e.g. Prod_FG =[11,2,a],[3,2,1+b],[2,2,2+c]]). It Prod_FG = None - YOUR CODE HERE rase NotimplementedError() It. assert type(Prod_EG) =w at.r, "Problem 1.21 type of value stored in variable Prod_FC does not Rateh the oxpected type," Phidden testa for problem 1.2 are vithin thia cell 1.3[1pt ) What is the transpose of F? Please store your answers in a string variable Trans F written with valid python formatting (e.g. Trans F a 'il1, 2, a), (3. 2,1+b],[2,2,2+c]2) 1. Franu_y=tone f rOch CODF ERE raise tiotinplementedrrxor() hhidded centar for probdeni 1.3 are within thia celd. 1.4 [1 pt] What is the determinant of F? Plesse store your answers in a string variable Det. F written with valid thon formatting (eg, Dot F " "2 + a -b'? 2.7 [1 pt] What is the determinant of A? Please store the value into a variable A deter. Use A from problem 2.2. For grading purposes, A_deter should be type numpy, float64. in 1 t ehidden teats for probiem 2.7 are within thin cell. 2.8[1pt] What is the determinant of BA? Please store the value into a variable BA deter. Use A and B from problem 2.2. For grading purposes, BA_deter should be type numpy.float 64. Ini1:BAdeterelioneYougcoosMrsrasiseNotroplementedBrror() In I 11 fhidden teata for problem 2.8 are within chin cell 2.9 [1. pt] Change negative values of A to 1 and store the result into a variable A pos. Use A from problem 2.2. Hinti look into tha technique of "bockean array indexing?. iniitApos=NonefrouncoosmantraiseNotimplemantedsrror() In I 11 ohididen tests for prablen 2.9 are vitain thia eel1 I It assert type(CD_trans) m= np-ndarray, "Problen 2.4: type of value stored in variable co trana does not mateh the expeci thidden teste for problem 2.4 arowithin this qoll 2.5 [1 pt] What is the inverse of E? Please store it in a variable E_inv. For grading purposes, E Inv should be a numpy array. In I 11 ghidden ceata for problem 2.5 are within thia cell 2.6 [1 pt] if AD=I, where A is as in Problem 2.2 and I is the identity matrix, what is matrix D ? Please store matrix D in a varlable D. Use A from arobiem 2.2. For grading purposes, D should be a numpy array. In&1:D=Fione-yoonecoorhirrer.raiseNotriplenentedError() 2.7[1pf] What is the determinant of A? Please store the value into a variable A.deter, Use A from problom 2.2. I It assert type(CD_trans) m= np-ndarray, "Problen 2.4: type of value stored in variable co trana does not mateh the expeci thidden teste for problem 2.4 arowithin this qoll 2.5 [1 pt] What is the inverse of E? Please store it in a variable E_inv. For grading purposes, E Inv should be a numpy array. In I 11 ghidden ceata for problem 2.5 are within thia cell 2.6 [1 pt] if AD=I, where A is as in Problem 2.2 and I is the identity matrix, what is matrix D ? Please store matrix D in a varlable D. Use A from arobiem 2.2. For grading purposes, D should be a numpy array. In&1:D=Fione-yoonecoorhirrer.raiseNotriplenentedError() 2.7[1pf] What is the determinant of A? Please store the value into a variable A.deter, Use A from problom 2.2. Rhidden tosts for problem-2.2 worwithinhthis aed 2.3 [1 pt] What is the transpose of C? Please store the transpose of C into a variable Ctrans.. For grading purposes, C.trans should be a numpy array. Inf14c=np.array([11,1,2],{3,5,81])C.transmNoneYOURCODEHEREraiseNotTmplementederror() In ( I: assert type(c_trans) mw np.ndarray, "Problem 2.3; type of value stored in variable c_trans doeis not match the expected Qhidden tertis for pooblem. 23 are with in this cord 2.4[1pt] What is (CD)T? ? Please store the value into CD_trans. For grading purposes, CD_trans should be a numpy array. in,t=np,arcay{[{13],[21],{341])CDtrane-tionerotrcoDEMEREralseNotImplententederror() In 111 assert type(CD trana) = np,ndarray, "Problen 2.41 type of value utored in varlable cDitrana dons not fateh tae expecte 3.2 [3 pt) Given a matrix A (as an np.array), find a vector v (as an np.array with "shape" (3,)) as follows: If A it is bijective: find v such that Av=121. If A is surjective but not injective: find v such that Av=A111 where v does not equal 111. If A is injective but not surjective: find v such that its first two eloments are 1 and v is in the image of A. In otherwords: v=11z and v=Ax for some vector x. Essentially, in this case you must solve for z. Note: For this problem A will always be injective, surjective, or bijective (i) A=(122131) An np.array(t11, 2,1},[2,1,111) v= Nose T Your coos nere raine Notraplenentederror() In I to oniddan teuts for problen 3.2 (a) are within this cell Part 3: Matrices as Linear Mappings 3.1 [2 pt] implement the function ThreeVec that takes in three vectors in R3 each represented as an array, creates a matrix from stacking the arrays verticaly (each array is a row in a matrix), and returns a list in which: - the first element is the rank of the matrix, - the second element is the rank of its transpose, - the third element is its determinant, - the fourth element is the inverse if its inverse exists and is the string "no inverse" if it does not exist. 11 def Threevee (v1,v2,v3) : - YoU CODE ERE ralse Notrmplementedzrror() retura 0 ansert (Threevec(v1, v2, va) (0,2)=[2,21), "problen 3,11 your anaver for the firit and irecohd el ininte in the eutput assert(Threevee(v), 22,v3)(3) wh " no inverse"), "Problen 3.1: your antwer for the fourth elesent in the output of thre 2.10 [1 pt] We are going to find the trace of the sum of two scaled matrices. Find the trace of 2+A+3+B and store the valuo into a variable trace2AsB. Use A and B from problem 2.2. For grading purposes, trace2A3B should be type numpy.int64, In111trace2A3B-NoneYOUR.CODEREREraineMotriplementedError() In It ghidden ceata for problem 2.10 are within thin cell For grading purposes, AB trace should be fype numpyinte4. In. I I1 Als trace = Mose P. YOUE COPE IUERE raine NotTinplenentederror() Part 3: Matrices as Linear Mappings 3.1.7 ptl implemont the function ThreeVeo that takes in three vectors in R3 each represented as an array, creates a matrix from stacking the arrays vertically 4.3 [ 2 pt] Find a 22 matrix with integer entries that has 10 and 25 as elgenvalues with eigen vectors (1,4) and (1,1) respectively. Record it as a numpy array in matrix with integer entries. Hint: Put variables for entries in a 22 array (a11a21a12a22), write out the equations that must be satisfied, and solve. In t 1: matrix = None YOUR CODE HERE raise NotImplementedError() In t it ansert type(materix) =.. np.ndarray, "Problen 4.31 your anewer should be an array" assert matrix. ahape =(2,2), "Problen 4.31 your array ahould be dimenaton 22 ansert np.inclose(matrix o np.array (1,41), np.array (110,401)).al1 (1), "problen 4.4 your array ahouid have (1,4) an 4.1 [1 pt] What are the eigenvalue and eigenvectors of the matrix A=(1235) ? Please store the eigenvalues in the variable called vals. The datatype for vals should be a numpy array. 1: A= np. array ([11,3],[2,5]1) vals= None YOUR CODE HERE raise NotTmplenentedError() 11. Phidden testu for problem 4.1 are within this cel1 4.2[1 pt] What are the eigervectors of the matrix (1235) ? Please store the eigenwoctors in variables v1 and v2 as numpy amays of shape (2). It vecn= Mone f YOUR CODE HERE raise Notimplenentedsrror() I 11 Phidden teaty for problem 4.2 are within this cell 4.3[2 pq find a 22 matrix with integer entries that has 10 and 25 as eigerrvelues with eigen vectors (1,4) and (1,1) respectivoly. Alecord it an a numpy aeray in matrix with intogor entries. Hint: Put variables for entrias in a 22 array (a11a21a12a22), write out the equations that must be sathfled, and sove. I: Ahdden tests for problem 3.2 (a) are within this cell (b) A=1310246 n I It Mhiddon tests for problem 3,2(b) are within this cell (c) A=1342410356 In I Is A- np-array (1(1,2,3),[3,4,51,(4,10,6)1) ve None - youn cone usins raise NotImplementedError() In (11 thidden tente for problem 3,2(e) are within this cell Part 4: Eigenvalues/ Eigenvectors

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

Database Management System MCQs Multiple Choice Questions And Answers

Authors: Arshad Iqbal

1st Edition

1073328554, 978-1073328550

More Books

Students also viewed these Databases questions

Question

They provide space for marginal glosses.

Answered: 1 week ago

Question

3. Define the roles individuals play in a group

Answered: 1 week ago