A comprehensive command-line matrix operations calculator written in C, featuring password protection, multiple matrix operations, and an intuitive menu-driven interface.
Author: Anant Rajput
Version: 4.2.1
Last Updated: December 27, 2025
- Features
- Operations Supported
- Prerequisites
- Installation
- Usage
- Examples
- System Settings
- Error Handling
- Limitations
- Security
- Future Enhancements
- Contributing
- License
- Contact
- ๐ Password Protected: Secure login system with 5-attempt limit and persistent password storage
- ๐พ Password Persistence: Password saved to
password.txtfile (default:12345) - ๐ Password Recovery: Security question-based password recovery system
- ๐ Seven Matrix Operations: Complete suite of linear algebra operations
- โ Input Validation: Comprehensive dimension and compatibility checks
- ๐ฏ User-Friendly Interface: Clear, menu-driven navigation
- โ๏ธ System Settings: Password management and program information
- ๐งน Screen Management: Clear screen functionality for better organization
- ๐พ Memory Efficient: Dynamic memory allocation using VLAs
- ๐ Session Persistence: Continue operations without restarting
- ๐ Security Features: Forceful eviction after failed authentication attempts
- Multiplies two matrices A[rโรcโ] and B[rโรcโ]
- Validates compatibility (cโ must equal rโ)
- Supports any valid matrix dimensions
- Input Type: Integer
- Output: Result matrix of size rโรcโ
- Computes determinants using cofactor expansion
- Supported sizes: 1ร1, 2ร2, 3ร3
- Validates square matrix requirement
- Input Type: Integer
- Output: Integer determinant value
- Calculates inverse using adjugate method
- Supported sizes: 1ร1, 2ร2, 3ร3
- Checks for singular matrices (det = 0)
- Input Type: Float
- Output: Floating-point inverse (2 decimal places)
- Derives characteristic polynomial using trace and determinant
- Supported sizes: 2ร2, 3ร3
- Input Type: Integer
- Output format:
- 2ร2:
ฮปยฒ - (trace)ฮป + det - 3ร3:
ฮปยณ - (trace)ฮปยฒ + (sum of minors)ฮป - det
- 2ร2:
- Calculates eigenvalues using quadratic formula
- Supported sizes: 2ร2 only
- Handles real eigenvalues (complex eigenvalues display as NaN)
- Input Type: Integer
- Output: Both eigenvalues (floating-point)
- Computes eigenvectors corresponding to eigenvalues
- Supported sizes: 2ร2 only
- Uses simplified formula:
[aโโ, ฮป - aโโ]แต - Input Type: Integer
- Output: Two eigenvectors in column form
- Swaps rows and columns
- Supported sizes: Any dimensions
- Input Type: Integer
- Output: Transposed matrix
- C Compiler: GCC 4.8+ or any C99-compatible compiler
- Operating System: Linux/Unix (uses
system("clear")) - Math Library: Standard C math library (
-lmflag required) - Knowledge: Basic understanding of linear algebra
- File Permissions: Write access for
password.txtfile
# If using git
git clone https://github.com/yourusername/matops.git
cd matops
# Or download the source file directlygcc matops.c -o matops -lmOr with explicit C99 standard:
gcc -std=c99 matops.c -o matops -lm -WallNote: The -lm flag is required to link the math library for sqrt() function.
Replace system("clear") with system("cls") in the source code before compiling, or add conditional compilation:
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif./matopsOn first run, the program will:
- Create
password.txtif it doesn't exist - Set default password to
12345 - Display the login screen
- Default Password:
12345 - Attempts Allowed: 5
- Password Recovery: Enter
101to access password recovery - Recovery Question: "What is the name of author?"
- Answer:
anant rajputorANANT RAJPUT(case-insensitive)
------------------
WELCOME TO MATOPS
------------------
CHOOSE OPERATIONS:
1. MATRIX MULTIPLICATION
2. DETERMINANT (upto 3 * 3 matrix)
3. INVERSE
4. CHARACTERSTIC EQUATION
5. EIGEN VALUE
6. EIGEN VECTOR
7. TRANSPOSE OF A MATRIX
8. SYSTEM SETTINGS
9. CLEAR SCREEN
0. EXIT
ENTER YOUR CHOICE: 1
ENTER THE NUMBER OF ROWS OF MATRIX A:-
2
ENTER THE NUMBER OF COLUMN OF MATRIX A:-
3
ENTER THE NUMBER OF ROWS IN MATRIX B:-
3
ENTER THE NUMBER OF COLUMN IN MATRIX B:-
2
ENTER THE ELEMENTS OF MATRIX A:-
1 2 3
4 5 6
ENTER THE ELEMENTS OF MATRIX B:-
7 8
9 10
11 12
------------------------------------------------------------
THE RESULT OF MULTIPLICATION OF MATRIX A AND MATRIX B IS:-
58 64
139 154
------------------------------------------------------------
Calculation:
A ร B = [1ร7 + 2ร9 + 3ร11 1ร8 + 2ร10 + 3ร12]
[4ร7 + 5ร9 + 6ร11 4ร8 + 5ร10 + 6ร12]
= [58 64]
[139 154]
ENTER YOUR CHOICE: 2
ENTER THE NUMBER OF ROWS OF MATRIX A:-
3
ENTER THE NUMBER OF COLUMN OF MATRIX A:-
3
ENTER THE ELEMENTS OF MAT A:
1 2 3
0 1 4
5 6 0
------------------------------
DETERMINANT OF MATRIX A IS :1
------------------------------
Calculation:
det(A) = 1(1ร0 - 4ร6) - 2(0ร0 - 4ร5) + 3(0ร6 - 1ร5)
= 1(-24) - 2(-20) + 3(-5)
= -24 + 40 - 15
= 1
ENTER YOUR CHOICE: 3
ENTER THE NUMBER OF ROWS OF MATRIX A:-
2
ENTER THE NUMBER OF COLUMN OF MATRIX A:-
2
ENTER ELEMENTS OF MATRIX A:
4 7
2 6
---------------------------
INVERSE OF MATRIX A IS :
0.60 -0.70
-0.20 0.40
---------------------------
Calculation:
det(A) = 4ร6 - 7ร2 = 24 - 14 = 10
Aโปยน = (1/10) ร [ 6 -7] = [0.60 -0.70]
[-2 4] [-0.20 0.40]
ENTER YOUR CHOICE: 4
ENTER THE NUMBER OF ROWS OF MATRIX A:-
2
ENTER THE NUMBER OF COLUMN OF MATRIX A:-
2
ENTER ELEMENTS OF MATRIX A:
3 1
1 3
--------------------------------------
CHARATERSTIC EQUATION OF MATRIX A IS:
ฮปยฒ - 6ฮป + 8
---------------------------------------
Explanation:
Trace = 3 + 3 = 6
det(A) = 3ร3 - 1ร1 = 8
Characteristic equation: ฮปยฒ - (trace)ฮป + det = ฮปยฒ - 6ฮป + 8
ENTER YOUR CHOICE: 5
ENTER THE NUMBER OF ROWS OF MATRIX A:-
2
ENTER THE NUMBER OF COLUMN OF MATRIX A:-
2
ENTER ELEMENTS OF MATRIX A:
3 1
1 3
-------------------------------------
EIGEN VALUE OF MATRIX A IS : 4.000000 and 2.000000
-------------------------------------
Calculation:
Characteristic equation: ฮปยฒ - 6ฮป + 8 = 0
Using quadratic formula:
ฮป = (6 ยฑ โ(36 - 32))/2 = (6 ยฑ 2)/2
ฮปโ = 4, ฮปโ = 2
ENTER YOUR CHOICE: 7
ENTER THE NUMBER OF ROWS OF MATRIX A:-
2
ENTER THE NUMBER OF COLUMN OF MATRIX A:-
3
ENTER ELEMENTS OF MATRIX A:
1 2 3
4 5 6
------------------------------------
THE TRANSPOSE OF THE MATRIX A IS:
1 4
2 5
3 6
------------------------------------
Access via main menu option 8:
---------------
SYSTEM SETTINGS
---------------
1. VERSION NUMBER
2. AUTHOR
3. MAINTAINER
4. RECENT UPDATE DATE
5. SUPPORTED MATRIX LIMITS
6. CHANGE PASSWORD
7. CLEAR SCREEN
8. RETURN TO PREVIOUS MENU
9. LOG OUT
Displays current version: 4.2.1
Shows author information: ANANT RAJPUT
Displays maintainer: ANANT RAJPUT
Last updated: 27 . DECEMBER . 2025
------------------------------------------------
SUPPORTED MATRIX LIMITS
------------------------------------------------
โข Multiplication : Any size (A[rรc], B[cรk])
โข Determinant : Up to 3 ร 3
โข Inverse : 1 ร 1, 2 ร 2, 3 ร 3
โข Eigen Values : 2 ร 2 , 3 ร 3
โข Eigen Vectors : 2 ร 2 only
โข Transpose : Any size
------------------------------------------------
Security-Enhanced Password Change Process:
- Requires current password verification (3 attempts)
- New password must be entered twice for confirmation
- Password
101is reserved for system commands and cannot be used - Password saved to
password.txtautomatically - Automatic FORCEFUL EVICTION after 3 failed verification attempts
Password Change Flow:
- Enter current password for verification
- If correct, enter new password
- Confirm new password (must match)
- Success message displayed
- Password saved to file
- New password takes effect immediately
Failed Attempt Handling:
- Attempts 1-2: Warning with remaining attempts displayed
Password is INCORRECT, TRY AGAIN (Attempts left = X) - Attempt 3: System logs you out for security
Password is INCORRECT, NO MORE TRIES LEFT Commencing FORCEFUL EVICTION due to security reasons.....LOADING.....
Password Mismatch:
- If new password and confirmation don't match:
Both input password are different. TRY AGAIN - 3 attempts allowed for password confirmation
Clears the terminal for better visibility using system("clear")
Returns to main operations menu without logging out
Logged Out of the System Successfully.
Exits to login screen while keeping program running
The program validates and handles various error conditions:
| Error Type | Validation | User Feedback |
|---|---|---|
| Zero Dimensions | Rejects matrices with 0 rows/columns | "ROWS AND COLUMNS MUST BE GREATER THAN ZERO." |
| Non-Square Matrix | Validates square requirement for det/inverse/eigen/char.eq. | Operation-specific error messages |
| Incompatible Multiplication | Checks cโ = rโ for AรB | "SORRY! THE MULTIPLICATION OF THE MATRIX IS NOT POSSIBLE." |
| Singular Matrix | Detects det = 0 for inverse calculation | "INVERSE DOES NOT EXIST" |
| Unsupported Size | Clear messages for operations beyond limits | "ONLY 2X2 AND 3X3 MATRIX SUPPORTED", etc. |
| Error Type | Attempts Allowed | User Feedback |
|---|---|---|
| Login Failure | 5 attempts | "INCORRECT PASSWORD. NUMBER OF ATTEMPST LEFT = X" |
| Final Login Attempt | After 5th failure | "INCORRECT PASSWORD. NO MORE ATTEMPTS LEFT" โ Program exits |
| Password Recovery Failure | 1 attempt | "Failed to retrive password.commencing FORCE EVICTION." |
| Password Change Verification | 3 attempts | "Password is INCORRECT, TRY AGAIN (Attempts left = X)" |
| Password Change Final Failure | After 3rd failure | "FORCEFUL EVICTION" โ Logged out |
| Error Type | Valid Range | User Feedback |
|---|---|---|
| Invalid Main Menu Choice | 0-9 | "INVALID RESPOSE (X). VALID RESPONSE = 0 - 9" |
| Invalid Settings Choice | 1-9 | "Invalid Response Detected (X). Valid response = (1 - 6)" |
| Operation | Supported Sizes | Algorithm | Note |
|---|---|---|---|
| Multiplication | Any (memory limited) | Standard algorithm | Limited by stack size |
| Determinant | 1ร1, 2ร2, 3ร3 | Cofactor expansion | Analytical formulas |
| Inverse | 1ร1, 2ร2, 3ร3 | Adjugate method | Uses determinant |
| Characteristic Equation | 2ร2, 3ร3 | Analytical formulas | Trace & determinant based |
| Eigenvalues | 2ร2 only | Quadratic formula | Real eigenvalues only |
| Eigenvectors | 2ร2 only | Simplified formula | Based on eigenvalues |
| Transpose | Any | Direct computation | No limitation |
-
Complex Numbers: No support for complex eigenvalues/eigenvectors
- Complex eigenvalues display as
nan(Not a Number) - No user-friendly warning provided
- Complex eigenvalues display as
-
Data Types:
- Matrix multiplication, determinant, characteristic equation: Integer input/output
- Inverse: Float input/output (2 decimal precision)
- Eigenvalues/eigenvectors: Integer input, float output
-
Precision: Standard floating-point limitations
- Uses
floatfor inverse calculation - Uses
doubleinternally forsqrt()calculations - Output limited to 2 decimal places
- Uses
-
Memory:
- VLA (Variable Length Array) size limited by available stack memory
- Large matrices may cause stack overflow
- No dynamic heap allocation used
-
Platform:
system("clear")command is Unix/Linux specific- Windows requires modification to
system("cls")
-
Password Security:
- Password stored in plain text in
password.txt - File permissions not explicitly set
- No encryption applied
- Password stored in plain text in
-
File Handling:
- If
password.txtis corrupted, defaults to 12345 - No backup password mechanism
- File must be writable in current directory
- If
-
Complex Eigenvalues: When a 2ร2 matrix has complex eigenvalues (discriminant < 0),
sqrt()of negative number producesnanwithout explanation -
Input Validation: No validation for non-numeric input
- Entering letters causes undefined behavior
- Program may crash or produce garbage values
-
Typos in Output:
- "ATTEMPST" instead of "ATTEMPTS"
- "characteric" instead of "characteristic"
- "MARRIX" instead of "MATRIX"
- "retrive" instead of "retrieve"
-
Password File Security: Plain text password storage is a security risk
-
No Confirmation: Exit (option 0) doesn't ask for confirmation
-
Password Storage:
- Passwords stored in plain text in
password.txt - Not suitable for sensitive environments
- For educational/personal use only
- Passwords stored in plain text in
-
File Permissions:
password.txtcreated with default permissions- Recommend setting
chmod 600 password.txton Unix systems
-
Input Validation:
- Limited validation of user input
- Malicious input may cause crashes
- Do not expose to untrusted users
-
Buffer Security:
- VLA usage may cause stack overflow
- No bounds checking on very large matrices
- Recovery Code: Enter
101at the login prompt - Security Question: "What is the name of author?"
- Correct Answers:
anant rajputorANANT RAJPUT(case-insensitive) - Failed Recovery: One attempt only, followed by immediate "FORCE EVICTION"
If using in any production or shared environment:
-
Change Default Password Immediately
Default: 12345 โ Change via System Settings (8 โ 6) -
Secure the Password File
chmod 600 password.txt # Unix/Linux -
Run with Limited Privileges
- Don't run as root/administrator
- Use dedicated user account
-
Monitor for Unusual Behavior
- Check for unexpected file access
- Monitor program crashes
-
Complex Number Support
- Handle complex eigenvalues and eigenvectors
- Display in a+bi format
- Proper mathematical representation
-
Larger Matrix Support
- Extend determinant calculation to nรn matrices
- Implement LU decomposition for inverse
- QR algorithm for eigenvalues of larger matrices
-
Input Validation
- Handle non-numeric input gracefully
- Validate input ranges
- Add input sanitization
-
Cross-Platform Compatibility
- Automatic detection of OS
- Use appropriate clear screen command
- Portable file paths
-
Enhanced Security
- Encrypt password in file
- Use secure password hashing
- Add password strength requirements
- Implement session timeouts
-
Additional Operations
- Matrix addition and subtraction
- Scalar multiplication and division
- Matrix exponentiation
- Rank calculation
- RREF (Reduced Row Echelon Form)
- Trace as separate operation
- Norm calculations (L1, L2, infinity)
-
Gaussian Elimination
- Solve systems of linear equations
- General solution finding
- Pivoting strategies
-
Advanced Decompositions
- LU decomposition
- QR decomposition
- Cholesky decomposition
- SVD (Singular Value Decomposition)
-
File I/O
- Import matrices from CSV/text files
- Export results to files
- Save calculation history
-
GUI Version
- GTK+ interface for Linux
- Qt for cross-platform
- Web-based interface
-
Code Quality
- Refactor into separate functions
- Improve error handling
- Add comprehensive comments
- Unit testing framework
Contributions are welcome! Here's how you can help improve MATOPS:
-
Fork the repository
git clone https://github.com/yourusername/matops.git
-
Create a feature branch
git checkout -b feature/amazing-feature
-
Make your changes
- Write clean, readable code
- Follow existing code style
- Add comments for complex logic
-
Test thoroughly
- Test with various inputs
- Check edge cases
- Verify no memory leaks
-
Commit your changes
git commit -m 'Add amazing feature: detailed description' -
Push to the branch
git push origin feature/amazing-feature
-
Open a Pull Request
- Provide clear description
- Reference any related issues
- Include screenshots if applicable
- Indentation: 4 spaces (no tabs)
- Braces: K&R style
if (condition) { // code }
- Naming:
- Variables:
snake_case - Functions:
snake_case - Constants:
UPPER_CASE
- Variables:
- Comments: Clear and concise
Bug Fixes:
- Fix typos in output messages
- Correct calculation errors
- Fix memory issues
- Improve error handling
New Features:
- Add new matrix operations
- Implement larger matrix support
- Add complex number handling
- Create file I/O functionality
Documentation:
- Improve README
- Add code comments
- Create tutorials
- Write examples
Testing:
- Write test cases
- Report bugs
- Suggest improvements
- Validate calculations
Before submitting a pull request, ensure:
- Code compiles without warnings
gcc -std=c99 -Wall -Wextra matops.c -o matops -lm
- All operations work correctly
- Edge cases handled (zero matrices, singular matrices, etc.)
- No memory leaks (test with valgrind if possible)
- Error messages are clear
- Documentation updated
- Code follows style guidelines
This project is licensed under the MIT License.
MIT License
Copyright (c) 2025 Anant Rajput
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
โ You CAN:
- Use the software for commercial purposes
- Modify the software
- Distribute the software
- Use the software privately
- Sublicense the software
โ You CANNOT:
- Hold the author liable
- Expect warranty or guarantee
๐ You MUST:
- Include the license and copyright notice
- State changes made to the code
Author & Maintainer: Anant Rajput
- GitHub Issues: Report bugs or request features
- Pull Requests: Contribute code
- Version: 4.2.1
- Last Updated: December 27, 2025
If you find this project helpful:
- โญ Star the repository
- ๐ Report bugs
- ๐ก Suggest features
- ๐ค Contribute code
- ๐ข Share with others
- Mathematical Foundation: Standard linear algebra algorithms and formulations
- Educational Purpose: Built to help students understand matrix operations
- Open Source Community: Thanks to all contributors and users for feedback
- C Programming: Inspired by the simplicity and power of C language
- Learning Resource: Designed as both a tool and a learning reference
| Metric | Value |
|---|---|
| Current Version | 4.2.1 |
| Development Status | Active |
| Last Updated | December 27, 2025 |
| Lines of Code | ~750 |
| Language | C (C99 standard) |
| License | MIT |
| Stability | Stable (Production Ready) |
| Platforms | Linux/Unix (Windows compatible with modifications) |
The default password is 12345. For any shared or production environment, change the password immediately via System Settings (Option 8 โ 6). The password is stored in plain text in password.txt and is not encrypted.
This program uses system("clear") which is Unix/Linux specific.
Windows users must:
- Replace
system("clear")withsystem("cls") - Recompile the program
OR use:
#ifdef _WIN32
system("cls");
#else
system("clear");
#endifLarge matrices may cause stack overflow due to VLA usage.
Recommendations:
- Keep matrix dimensions reasonable (<100ร100)
- For very large matrices, consider implementing heap allocation
- Monitor system memory during operations
The program needs write access to create and modify password.txt in the current directory.
Ensure:
- Current directory is writable
- Sufficient disk space available
Made with โค๏ธ for Linear Algebra Students
MATOPS - Making Matrix Operations Simple and Accessible