Problem Statement:
Write a python program to compute following computation on matrix:
a) Addition of two matrices
b) Subtraction of two matrices
c) Multiplication of two matrices
d) Transpose of a matrix
-------------------------------------------------------------------------------
Analysis of a Problem Statement:
1. Given :
Matrices are given in a problem statement.
2. Entity:
Matrix is an entity or object with no of rows and no of columns attribute.
3. Input:
You have to accept n x n matrix values from the user to perform operations on it.
4. Data Structure:
To store/organize the matrix element in memory we required LIST as a data structure.
5. Output:
5.1 Addition of two Matrices
5.2 Subtraction of two Matrices
5.3 Multiplication of two Matrices
5.4 Transpose of a Matrix SOURCE CODE:
OUTPUT:
Basic Matrix Operation using Python
Welcome all in assignment no:03 from Group A
For Matrix operation we require some input from you Please.
Enter no of rows in first matrix: 3
Enter no of cols in first matrix: 3
Enter no of rows in second matrix: 3
Enter no of cols in second matrix: 3
1. Accept two matrices from user:
2. Show the matrices values:
3. Addition of Two Matrices:
4. Subtraction of Two Matrices:
5. Multiplication of Two Matrices:
6. Transpose of Matrix
7. Exit
Enter your choice:1
please enter the values for First Matrix:
Enter the value of matrix[0][0]:: 1
Enter the value of matrix[0][1]:: 2
Enter the value of matrix[0][2]:: 3
----------------------------
Enter the value of matrix[1][0]:: 4
Enter the value of matrix[1][1]:: 5
Enter the value of matrix[1][2]:: 6
----------------------------
Enter the value of matrix[2][0]:: 7
Enter the value of matrix[2][1]:: 8
Enter the value of matrix[2][2]:: 9
----------------------------
please enter the values for Second Matrix:
Enter the value of matrix[0][0]:: 1
Enter the value of matrix[0][1]:: 2
Enter the value of matrix[0][2]:: 3
----------------------------
Enter the value of matrix[1][0]:: 4
Enter the value of matrix[1][1]:: 5
Enter the value of matrix[1][2]:: 6
----------------------------
Enter the value of matrix[2][0]:: 7
Enter the value of matrix[2][1]:: 8
Enter the value of matrix[2][2]:: 9
----------------------------
1. Accept two matrices from user:
2. Show the matrices values:
3. Addition of Two Matrices:
4. Subtraction of Two Matrices:
5. Multiplication of Two Matrices:
6. Transpose of Matrix
7. Exit
Enter your choice:2
The Value of First matrix is as follows:
1 2 3
4 5 6
7 8 9
The Value of Second matrix is as follows:
1 2 3
4 5 6
7 8 9
1. Accept two matrices from user:
2. Show the matrices values:
3. Addition of Two Matrices:
4. Subtraction of Two Matrices:
5. Multiplication of Two Matrices:
6. Transpose of Matrix
7. Exit
Enter your choice:3
The addition of two matrices are as follows..
2 4 6
8 10 12
14 16 18
1. Accept two matrices from user:
2. Show the matrices values:
3. Addition of Two Matrices:
4. Subtraction of Two Matrices:
5. Multiplication of Two Matrices:
6. Transpose of Matrix
7. Exit
Enter your choice:4
The subtraction of two matrices are as follows..
0 0 0
0 0 0
0 0 0
1. Accept two matrices from user:
2. Show the matrices values:
3. Addition of Two Matrices:
4. Subtraction of Two Matrices:
5. Multiplication of Two Matrices:
6. Transpose of Matrix
7. Exit
Enter your choice:5
The Multiplication of two matrices are as follows..
30 36 42
66 81 96
102 126 150
1. Accept two matrices from user:
2. Show the matrices values:
3. Addition of Two Matrices:
4. Subtraction of Two Matrices:
5. Multiplication of Two Matrices:
6. Transpose of Matrix
7. Exit
Enter your choice:6
Before Transpose of Matrix the elements in matrix are as follows:
1 2 3
4 5 6
7 8 9
After applying Transpose on matrix elements are as follows:
1 4 7
2 5 8
3 6 9
1. Accept two matrices from user:
2. Show the matrices values:
3. Addition of Two Matrices:
4. Subtraction of Two Matrices:
5. Multiplication of Two Matrices:
6. Transpose of Matrix
7. Exit
Enter your choice:7
Welcome all in assignment no:03 from Group A
For Matrix operation we require some input from you Please.
Enter no of rows in first matrix: 3
Enter no of cols in first matrix: 3
Enter no of rows in second matrix: 3
Enter no of cols in second matrix: 3
1. Accept two matrices from user:
2. Show the matrices values:
3. Addition of Two Matrices:
4. Subtraction of Two Matrices:
5. Multiplication of Two Matrices:
6. Transpose of Matrix
7. Exit
Enter your choice:1
please enter the values for First Matrix:
Enter the value of matrix[0][0]:: 1
Enter the value of matrix[0][1]:: 2
Enter the value of matrix[0][2]:: 3
----------------------------
Enter the value of matrix[1][0]:: 4
Enter the value of matrix[1][1]:: 5
Enter the value of matrix[1][2]:: 6
----------------------------
Enter the value of matrix[2][0]:: 7
Enter the value of matrix[2][1]:: 8
Enter the value of matrix[2][2]:: 9
----------------------------
please enter the values for Second Matrix:
Enter the value of matrix[0][0]:: 1
Enter the value of matrix[0][1]:: 2
Enter the value of matrix[0][2]:: 3
----------------------------
Enter the value of matrix[1][0]:: 4
Enter the value of matrix[1][1]:: 5
Enter the value of matrix[1][2]:: 6
----------------------------
Enter the value of matrix[2][0]:: 7
Enter the value of matrix[2][1]:: 8
Enter the value of matrix[2][2]:: 9
----------------------------
1. Accept two matrices from user:
2. Show the matrices values:
3. Addition of Two Matrices:
4. Subtraction of Two Matrices:
5. Multiplication of Two Matrices:
6. Transpose of Matrix
7. Exit
Enter your choice:2
The Value of First matrix is as follows:
1 2 3
4 5 6
7 8 9
The Value of Second matrix is as follows:
1 2 3
4 5 6
7 8 9
1. Accept two matrices from user:
2. Show the matrices values:
3. Addition of Two Matrices:
4. Subtraction of Two Matrices:
5. Multiplication of Two Matrices:
6. Transpose of Matrix
7. Exit
Enter your choice:3
The addition of two matrices are as follows..
2 4 6
8 10 12
14 16 18
1. Accept two matrices from user:
2. Show the matrices values:
3. Addition of Two Matrices:
4. Subtraction of Two Matrices:
5. Multiplication of Two Matrices:
6. Transpose of Matrix
7. Exit
Enter your choice:4
The subtraction of two matrices are as follows..
0 0 0
0 0 0
0 0 0
1. Accept two matrices from user:
2. Show the matrices values:
3. Addition of Two Matrices:
4. Subtraction of Two Matrices:
5. Multiplication of Two Matrices:
6. Transpose of Matrix
7. Exit
Enter your choice:5
The Multiplication of two matrices are as follows..
30 36 42
66 81 96
102 126 150
1. Accept two matrices from user:
2. Show the matrices values:
3. Addition of Two Matrices:
4. Subtraction of Two Matrices:
5. Multiplication of Two Matrices:
6. Transpose of Matrix
7. Exit
Enter your choice:6
Before Transpose of Matrix the elements in matrix are as follows:
1 2 3
4 5 6
7 8 9
After applying Transpose on matrix elements are as follows:
1 4 7
2 5 8
3 6 9
1. Accept two matrices from user:
2. Show the matrices values:
3. Addition of Two Matrices:
4. Subtraction of Two Matrices:
5. Multiplication of Two Matrices:
6. Transpose of Matrix
7. Exit
Enter your choice:7