This program performs a custom matrix operation ( A = B \unicode{x2218} C ) where:
- ( B ) is a randomly generated square input matrix.
- ( C ) is a randomly generated square core matrix.
- ( A ) is the resulting output matrix after performing the operation.
-
Initial Setup:
- The core matrix ( C ) is aligned with the top-left corner of the input matrix ( B ).
- Elements of ( C ) are multiplied by corresponding elements in ( B ).
- The sum of these products is written to the corresponding cell in the result matrix ( A ).
-
Shifting and Calculating:
- Shift ( C ) one cell to the right and repeat the multiplication and summing process.
- Continue until ( C ) reaches the end of the current row.
- Move ( C ) to the beginning of the next row and repeat until the entire input matrix ( B ) is processed.
-
Output Matrix Size:
-
The size of the output matrix ( A ) is calculated as:
[ \text{output_row_size} = (\text{input_row_size} - \text{core_row_size}) + 1 ]
-
- Dynamic Allocation: Matrices must be declared dynamically.
- Random Generation:
- Input matrix ( B ): Size between 5x5 and 20x20, values between 10-20.
- Core matrix ( C ): Size between 2x2 and 5x5, values between 1-10.
- Menu Options:
- Generate new matrices and store in "data.txt".
- Read matrices from "data.txt".
- Compile the Program:
g++ -o matrix_operation matrix_operation.cpp
input matrix
10 12 15 14 20
11 19 16 18 17
14 15 10 13 16
12 13 18 20 15
11 17 16 15 19
core matrix
5 7
8 4
Press 1-To generate new matrix or press 2-To read the matrices
1
The Output Matrix:
8 7 6 5
9 8 7 6
10 9 8 7
11 10 9 8