Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A dynamic integer matrix is a two dimensional array of integers. It can also be descried as a pointer to a pointer or an array

A dynamic integer matrix is a two dimensional array of integers. It can also be descried as a pointer to a pointer or an array of pointers. In this program you will write several small utility functions to test mastery of this concept. The function signatures and descriptions follow below. You may assume that the matrix will be a square matrix meaning that the number of rows equals the number of columns in the matrix. Implement these functions: int** makeMatrix(int n); void printMatrix(int **A, int n); bool sumEqual(int **A, int **B, int n); bool isEqual(int **A, int **B, int n); int diagonal(int **A, int n); int** sumMatrix(int **A, int **B, int n); int** product(int **A, int **B, int n); int** subtractMatrix(int **A, int **B, int n);

Expected Output

Test Case Test Case 1

Expected Output

 Please enter a value for the size of matrix: 2 Enter values for matrix A: 1 2 3 4 Matrix A: 1 2 3 4 Enter values for matrix B: 5 5 0 0 Matrix B: 5 5 0 0 Enter a number between 1 and 11 to select your choice from the following menu. 1. Check Sum of Elements of Matrices A and B 2. Check If Matrices A and B are Identical 3. Product of Diagonal Elements of Matrix A 4. Product of Diagonal Elements of Matrix B 5. Sum of Matrices A and B 6. Product of Matrices A and B 7. Matrix B Subtracted from Matrix A 8. Inverse of Matrix A 9. Inverse of Matrix B 10. Matrix A Divided By Matrix B 11. EXIT Your entered number is: 13 Invalid Input Enter a number between 1 and 11 to select your choice from the following menu. 1. Check Sum of Elements of Matrices A and B 2. Check If Matrices A and B are Identical 3. Product of Diagonal Elements of Matrix A 4. Product of Diagonal Elements of Matrix B 5. Sum of Matrices A and B 6. Product of Matrices A and B 7. Matrix B Subtracted from Matrix A 8. Inverse of Matrix A 9. Inverse of Matrix B 10. Matrix A Divided By Matrix B 11. EXIT Your entered number is: 1 Sum of elements in each matrix is equal Enter a number between 1 and 11 to select your choice from the following menu. 1. Check Sum of Elements of Matrices A and B 2. Check If Matrices A and B are Identical 3. Product of Diagonal Elements of Matrix A 4. Product of Diagonal Elements of Matrix B 5. Sum of Matrices A and B 6. Product of Matrices A and B 7. Matrix B Subtracted from Matrix A 8. Inverse of Matrix A 9. Inverse of Matrix B 10. Matrix A Divided By Matrix B 11. EXIT Your entered number is: 2 Matrix A and B are NOT identical Enter a number between 1 and 11 to select your choice from the following menu. 1. Check Sum of Elements of Matrices A and B 2. Check If Matrices A and B are Identical 3. Product of Diagonal Elements of Matrix A 4. Product of Diagonal Elements of Matrix B 5. Sum of Matrices A and B 6. Product of Matrices A and B 7. Matrix B Subtracted from Matrix A 8. Inverse of Matrix A 9. Inverse of Matrix B 10. Matrix A Divided By Matrix B 11. EXIT Your entered number is: 3 The product of the diagonal elements of A is: 4 Enter a number between 1 and 11 to select your choice from the following menu. 1. Check Sum of Elements of Matrices A and B 2. Check If Matrices A and B are Identical 3. Product of Diagonal Elements of Matrix A 4. Product of Diagonal Elements of Matrix B 5. Sum of Matrices A and B 6. Product of Matrices A and B 7. Matrix B Subtracted from Matrix A 8. Inverse of Matrix A 9. Inverse of Matrix B 10. Matrix A Divided By Matrix B 11. EXIT Your entered number is: 4 The product of the diagonal elements of B is: 0 Enter a number between 1 and 11 to select your choice from the following menu. 1. Check Sum of Elements of Matrices A and B 2. Check If Matrices A and B are Identical 3. Product of Diagonal Elements of Matrix A 4. Product of Diagonal Elements of Matrix B 5. Sum of Matrices A and B 6. Product of Matrices A and B 7. Matrix B Subtracted from Matrix A 8. Inverse of Matrix A 9. Inverse of Matrix B 10. Matrix A Divided By Matrix B 11. EXIT Your entered number is: 5 The sum of matrix A and B is: 6 7 3 4 Enter a number between 1 and 11 to select your choice from the following menu. 1. Check Sum of Elements of Matrices A and B 2. Check If Matrices A and B are Identical 3. Product of Diagonal Elements of Matrix A 4. Product of Diagonal Elements of Matrix B 5. Sum of Matrices A and B 6. Product of Matrices A and B 7. Matrix B Subtracted from Matrix A 8. Inverse of Matrix A 9. Inverse of Matrix B 10. Matrix A Divided By Matrix B 11. EXIT Your entered number is: 6 The product of matrix A and B is: 5 5 15 15 Enter a number between 1 and 11 to select your choice from the following menu. 1. Check Sum of Elements of Matrices A and B 2. Check If Matrices A and B are Identical 3. Product of Diagonal Elements of Matrix A 4. Product of Diagonal Elements of Matrix B 5. Sum of Matrices A and B 6. Product of Matrices A and B 7. Matrix B Subtracted from Matrix A 8. Inverse of Matrix A 9. Inverse of Matrix B 10. Matrix A Divided By Matrix B 11. EXIT Your entered number is: 7 Matrix A - B is: -4 -3 3 4 Enter a number between 1 and 11 to select your choice from the following menu. 1. Check Sum of Elements of Matrices A and B 2. Check If Matrices A and B are Identical 3. Product of Diagonal Elements of Matrix A 4. Product of Diagonal Elements of Matrix B 5. Sum of Matrices A and B 6. Product of Matrices A and B 7. Matrix B Subtracted from Matrix A 8. Inverse of Matrix A 9. Inverse of Matrix B 10. Matrix A Divided By Matrix B 11. EXIT Your entered number is: 8 Inverse of matrix A is: -2.000000 1.000000 1.500000 -0.500000 Enter a number between 1 and 11 to select your choice from the following menu. 1. Check Sum of Elements of Matrices A and B 2. Check If Matrices A and B are Identical 3. Product of Diagonal Elements of Matrix A 4. Product of Diagonal Elements of Matrix B 5. Sum of Matrices A and B 6. Product of Matrices A and B 7. Matrix B Subtracted from Matrix A 8. Inverse of Matrix A 9. Inverse of Matrix B 10. Matrix A Divided By Matrix B 11. EXIT Your entered number is: 9 Inverse of matrix B is: Det = 0 so matrix is singular. Enter a number between 1 and 11 to select your choice from the following menu. 1. Check Sum of Elements of Matrices A and B 2. Check If Matrices A and B are Identical 3. Product of Diagonal Elements of Matrix A 4. Product of Diagonal Elements of Matrix B 5. Sum of Matrices A and B 6. Product of Matrices A and B 7. Matrix B Subtracted from Matrix A 8. Inverse of Matrix A 9. Inverse of Matrix B 10. Matrix A Divided By Matrix B 11. EXIT Your entered number is: 10 Det = 0 so matrix is singular. Matrix was not invertable so division is impossible, returning to menu. Enter a number between 1 and 11 to select your choice from the following menu. 1. Check Sum of Elements of Matrices A and B 2. Check If Matrices A and B are Identical 3. Product of Diagonal Elements of Matrix A 4. Product of Diagonal Elements of Matrix B 5. Sum of Matrices A and B 6. Product of Matrices A and B 7. Matrix B Subtracted from Matrix A 8. Inverse of Matrix A 9. Inverse of Matrix B 10. Matrix A Divided By Matrix B 11. EXIT Your entered number is: 11 

Test Case Test Case 2

Expected Output

Please enter a value for the size of matrix: 2 Enter values for matrix A: 1 6 7 5 Matrix A: 1 6 7 5 Enter values for matrix B: 5 9 3 1 Matrix B: 5 9 3 1 Enter a number between 1 and 11 to select your choice from the following menu. 1. Check Sum of Elements of Matrices A and B 2. Check If Matrices A and B are Identical 3. Product of Diagonal Elements of Matrix A 4. Product of Diagonal Elements of Matrix B 5. Sum of Matrices A and B 6. Product of Matrices A and B 7. Matrix B Subtracted from Matrix A 8. Inverse of Matrix A 9. Inverse of Matrix B 10. Matrix A Divided By Matrix B 11. EXIT Your entered number is: 9 Inverse of matrix B is: -0.045455 0.409091 0.136364 -0.227273 1 element summation check 2 Are A and B identical 3 Diagonal of matrix A 4 Diagonal of matrix B 5 Sum of matrix A and B 6 Product of matrix A and B 7 Matrix B subtracted from matrix A 8 Invert matrix A 9 Invert matrix B 10 Matrix division 11 EXIT Your entered number is: 10 Division result is: 0.772727 -0.954545 0.363636 1.727273 Enter a number between 1 and 11 to select your choice from the following menu. 1. Check Sum of Elements of Matrices A and B 2. Check If Matrices A and B are Identical 3. Product of Diagonal Elements of Matrix A 4. Product of Diagonal Elements of Matrix B 5. Sum of Matrices A and B 6. Product of Matrices A and B 7. Matrix B Subtracted from Matrix A 8. Inverse of Matrix A 9. Inverse of Matrix B 10. Matrix A Divided By Matrix B 11. EXIT Your entered number is: 11 

Any explanation or help will be great. Thanks! The rest is optional extra work

Extension to matrix problem

In the description for problem 2, the last two functions were described that where a cut above the rest in terms of difficulty. For bonus points on assignment 5 you should implement these functions:

double** inverseMatrix(int **A, int n);

double** matrixDivision(int **A, int **B, int n);

These two functions are only required for bonus points, you can receive full credit on the matrix problem without implementing them, should you find them too difficult you may simply output NOT IMPLEMENTED when their menu choice is selected.

The inverseMatrix function finds the inverse of a matrix should it exist. This requires finding the determinate of a matrix. For example, for the following matrix A, its determinate is ad - bc. The inverse of a matrix (A1 ) is found as follows.

A = [ a b

c d ]

Inverse of A:

A 1 = 1 Determinate d b c a A 1 = 1 ad bc d b c a

For this problem, we will consider only 2 x 2 matrices for which it is trivial to compute the determinate.

Note: you should only concern yourself with the 2 x 2 matrix case for this function, all other sizes should print an error message and return to the menu.

Example (inverse matrix): 7 4 2 3

Determinate = (7 x 3) - (4 x 2) = 21 - 8 = 13

Inverted matrix is: 3/13 4/13 2/13 7/13 same as 0.2307692 0.3076923 0.1538462 0.5384615 11

The matrixDivision function divides one matrix by another matrix. The reason divides is in quotes is because technically matrix division does not exist. The division of some matrix A by matrix B is instead represented by multiplying A by the inverse of B. Note: you should only concern yourself with the 2 x 2 matrix case for this function, all other sizes should print an error message and return to the menu.

For two 2x2 matrices A and B, the matrix division is defined as follows. A = p q r s B = a b c d

A B is the same as A B1 where B 1 = 1 ad bc d b c a

Therefore, A B = A B1 = A 1 ad bc d b c a !

Example (matrix division): A = 13 26 39 13 B = 7 4 2 3

A B = A B1 = 1 10 7 5 12

Sample output:

Please enter a value for the size of matrix: 2

Enter values for matrix A: 13 26 39 13

Matrix A: 13 26 39 13

Enter values for matrix B: 7 4 2 3

Matrix B: 7 4 2 3 13

Enter a number between 1 and 11 to select your choice from the following menu.

...menu...

Your entered number is: 8

Inverse of matrix A is: -0.015385 0.030769 0.046154 -0.015385

Enter a number between 1 and 11 to select your choice from the following menu.

...menu...

Your entered number is: 9

Inverse of matrix B is: -0.015385 0.030769 0.046154 -0.015385

Enter a number between 1 and 11 to select your choice from the following menu.

...menu...

Your entered number is: 10

-1 10 7 -5

Enter a number between 1 and 11 to select your choice from the following menu.

...menu...

Your entered number is: 11

Exiting

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

Students also viewed these Databases questions