Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The objective of this assignment is to write a simple program library that computes the product of two dense matrices, C = A B. 1.

image text in transcribed

The objective of this assignment is to write a simple program library that computes the product of two dense matrices, C = A B. 1. Implement the function with the prototype double *malloc matrix(int nl, int n2); This function creates a two-dimensional matrix using dynamic memory allocation (use the built-in C function malloc() for this purpose) and returns a pointer to the structure that was created. The created matrix has nl rows and n2 columns. Each element of the matrix is a floating point, double precision number. The matrix must be structured using the array of pointers representation, i.e., the data for the two-dimensional matrix is stored in a set of one-dimensional arrays, one array for each row of the matrix, and an additional, separate one-dimensional array with each array element containing a pointer to the data for a single row. The function returns NULL if the operation failed, e.g., due to memory 2. Implement the function with the prototype void free matrix (int nl, int n2, double *a) Release the memory allocated for the matrix pointed to by a which has nl rows and n2 columns. Use the built-in C function free() to release a block of memory Implement the function with the prototype 3. int matrix multiply(int nl, int n2, int n3, double **a, double*, double *c)i The matrix A is stored in a and has dimensions nl by n2, and the matrix B is stored in b and has dimensions n2 by n3. When your function returns, the product C Ax Bis stored in matrix c. Your function should return 0 if the computation was successful, and nonzero otherwise (e.g, nl is negative, a NULL, or any other invalid condition). From the function prototype above, note that memory for the arrays must be allocated outside the matrix multiply function. 4. Implement the function with the prototype void fill, matrix(int nl, int n2, double **A); that fills the matrix a with random values between 0.0 and 10.0. 5. Implement the function with the prototype void print matrix(int nl, int n2, double **a); that prints the matrix a in a readable format (i.e., columns are aligned). 6. Write a program to test the above functions. In particular, choose A as a 4 x 3 matrix, and B as a 3 2 matrix. For this case, print A, B, C and turn in your results in a short report. Also, turn in evidence that you checked that C is correct, e.g., a Matlab script that shows the same computation and results. The first five functions should be placed in a single file, and the test program in a separate file. You should create a . h file defining the interface to the above functions, and use #include in the test program to import the definition into the file with the test program. To complete this assignment, we recommend you first get the functions malloc matrix, free matrix, fill matrix, and print matrix to work, then work on the matrix multiply

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

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

Students also viewed these Databases questions

Question

Brief the importance of span of control and its concepts.

Answered: 1 week ago

Question

What is meant by decentralisation?

Answered: 1 week ago

Question

Write down the Limitation of Beer - Lamberts law?

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago