Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Fill the functions with codes as instructed >> #include //For the sqrt() function #define MATRIX_MAX 100 //Define new types for Vectors and Matrices //Notice that
Fill the functions with codes as instructed >> #include //For the sqrt() function #define MATRIX_MAX 100 //Define new types for Vectors and Matrices //Notice that the MATRIX_MAX constant is used to limit the maximum //size of a matrix or vector. typedef double Vector[MATRIX_MAX]; typedef double Matrix[MATRIX_MAX][MATRIX_MAX]; //In all of the functions below, all arguments of type Matrix //or Vector are passed by reference (since they are array types).
/* identity(M, size) Set the elements of the provided matrix M to be an identity matrix of the specified size. Do not set any other elements outside the bounds of the requested size. By definition, the identity matrix is square (so the number of rows and the number of columns are equal). */ void identity(Matrix M, int size); /* matrix_copy(A, B, rows, cols) Given an input matrix A (with the provided number of rows and columns) and an output matrix B, copy all elements of A into B. Do not set any elements of B outside the bounds provided. Do not modify any elements of the input matrix A. */ void matrix_copy(Matrix A, Matrix B, int rows, int cols); /* transpose(A, T, rows, cols) Given an input matrix A (with the provided number of rows and columns) and an output matrix T, set T to be the transpose of A. Note that the number of rows in T will be the number of columns in A and the number of columns in T will be the number of rows in A (by definition of the transpose). Do not modify any elements of the input matrix A. */ void transpose(Matrix A, Matrix T, int rows, int cols); /* add_matrices(A, B, C, rows, cols) Given two input matrices A and B (both with the number of rows/columns provided), set C to be the elementwise sum of A and B. Do not set any elements of C outside of the bounds provided. Do not modify any elements of the input matrices A and B. */ void add_matrices(Matrix A, Matrix B, Matrix C, int rows, int cols); /* matrix_vector_multiply(A, V, Vout, rows, cols) Given an n x k matrix A and a vector V (which will have k entries), compute the product A*V (which will have n entries) and store the product in the provided output vector Vout. Do not set any elements of Vout outside of the required elements for the computation. Do not modify any elements of the input matrices A and B or the input vector V. */ void matrix_vector_multiply(Matrix A, Vector V, Vector Vout, int n, int k); /* matrix_multiply(A, B, C, Arows, Acols, Brows, Bcols) Given matrices A and B, compute the product C = A*B and store it in the matrix C provided. The number of rows and columns of each input matrix are provided in parameter values. The output matrix C will have the same number of rows as A and the same number of columns as B. If the number of columns in A is not equal to the number of rows in B, the multiplication is impossible. In this case, the function will return 0 and make NO MODIFICATION to the output matrix C. If the multiplication is possible, the matrix C will contain the result and the function will return 1. Do not modify any elements of the input matrices A and B. */ int matrix_multiply(Matrix A, Matrix B, Matrix C, int Arows, int Acols, int Brows, int Bcols);
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