Introduction
The objective is to create a Python program capable of performing fundamental operations on matrices with a maximum size of 4x4, without utilizing Python's pre-existing libraries such as numpy or sympy.
The Challenge
Create a Python program that can perform basic operations on matrices of maximum size 4x4 without using Python's built-in libraries (such as numpy or sympy).
The program must be able to perform the following operations:
Matrix Addition: Adding two matrices of size n × m, with n, m ≤ 4.
Matrix Subtraction: Adds two matrices of size n × m, with n, m ≤ 4.
Matrix Multiplication: Adding two matrices of size n × m, with n, m ≤ 4
Matrix Determinant: Calculates the determinant of an n × n matrix, n ≤ 4.
Matrix Inverse: Calculates the inverse of an n × n square matrix n ≤ 4 (if any).
The Solution
I seperate the main scripts and the operations scripts
/root folder:
├── matrix_app.py├── .dist
├── 1_penjumlahan.py
├── 2_pengurangan.py
├── 3_perkalian.py
├── 4_determinan.py
└── 5_inverse.py
Key features :
matrix_app.py: The main script, appears to be a simple terminal output that allows the user to choose a matrix operation. The program repeatedly prompts the user to input a choice (1 to 5) until a valid input is provided.
Once a valid choice is made, the program uses the os.system function to run a corresponding Python script located in the .dist directory. The program seems to be designed to provide a simple interface for the user to interact with different matrix operations, with each operation implemented in a separate script.
.dist/1_penjumlahan.py: Matrix addition
.dist/2_pengurangan.py: Matrix subtraction
.dist/3_perkalian.py: Matrix multiplication
.dist/4_determinan.py: Matrix determinant calculation
.dist/5_inverse.py: Matrix inverse calculation
These scripts being executed by the matrix_app.py script, which appears to be a main program that prompts the user to choose an operation and then runs the corresponding script using the os.system() function.
The .dist folder might be used to organize and distribute these separate operation scripts, making it easier to manage and maintain the codebase. The name .dist could be short for "distribution" or "operations", but without more context, it's difficult to say for certain.
The Results
The matrix operation scripts in the .dist folder successfully perform various mathematical operations on matrices, including addition, subtraction, multiplication, determinant calculation, and inverse calculation. The matrix_app.py script serves as a user-friendly interface, allowing users to select an operation and execute the corresponding script. The results of each operation are likely displayed to the user, providing a clear and concise output.
Conclusion
The matrix operation scripts in the .dist folder provide a comprehensive set of tools for performing various mathematical operations on matrices. The scripts are well-organized and easy to understand, making it simple for users to select an operation and execute the corresponding script.
The matrix_app.py script serves as a user-friendly interface, allowing users to interact with the scripts and view the results of each operation.
Overall, this codebase demonstrates a solid implementation of matrix operations and provides a valuable resource for anyone working with matrices in Python.