Question
1) Recall that the three types of elementary row operations are 1) multiplying a row by a scalar 2) interchanging two rows 3) Adding a
1) Recall that the three types of elementary row operations are 1) multiplying a row by a scalar 2) interchanging two rows 3) Adding a multiple of one row to another Write three separate Python python functions that each take an input matrix A and return the result of applying an elementary row operation to A. You must choose what the appropriate arguments for the function are to specify the row operation. You may call your functions ero sm, ero ri, ero asmr, (for scalar multiple, row interchange, add scalar multiple of row, respectively). Your functions should return a new matrix, but not modify the input matrix. You will need to copy the input matrix using the syntax B=A.copy() somewhere inside your functons.
2) Write a set of three functions that return the elementary matrices corresponding to these three types of row operations. Your functions should take as input the matrix size n, and the same arguments as you designed for your answers for problem 1). You may do this by creating an identity matrix and applying the row operation to the identity matrix using your functions from problem 1). See page 176 in the text, and theorem 3.10, for more information.
4) Write a Python function that takes a matrix A, and a scalar c, and returns the number of elements in A that have the value c. Do this using a nested for loop, i.e. explicitly looping over all of the elements in the matrix A, comparing them to c, and then incrementing a counter variable. Test your code by choosing your own matrix A, a value c that A contains at least once, and show the results of calling your code with these inputs.
5) Matrix Multiplication Write a Python function that takes two matrices A and B, checks if the inner dimensions are equal, and if so returns a matrix C that is equal to the matrix product AB. Otherwise your code may print an error message (or raise an Exception). You should do this using a triply nested for loop : first create a matrix C of all zeros, then loop over all of the elements of C, and then for each element of C compute the appropriate value using Ci,j = Pn k=1 Ai,kBk,j Validate your code by your own choosing matrices A and B and computing the matrix product using both your code and the built-in matrix multiplication operator
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started