Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

CLI based application contains some important operations in 2D Matrix

License

Notifications You must be signed in to change notification settings

KristiantoJohan/2D-Matrix-Operation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

2D Matrix Operations in C++

This project provides a set of operations for 2D matrices implemented in C++. The operations include:

  • Matrix Addition
  • Matrix Subtraction
  • Matrix Multiplication
  • Determinant Calculation
  • Matrix Inversion

Table of Contents

Installation

  1. Clone the repository:

    git clone https://github.com/KristiantoJohan/2D-Matrix-Operations.git
  2. Navigate to the project directory:

    cd 2D-Matrix-Operations
  3. Compile the code:

    g++ -o matrix_operations main.cpp matrix.cpp

Usage

Run the compiled program:

./matrix_operations

Operations

Matrix Addition

Add two matrices of the same dimensions.

Matrix Subtraction

Subtract one matrix from another, both of the same dimensions.

Matrix Multiplication

Multiply two matrices if the number of columns in the first matrix is equal to the number of rows in the second matrix.

Determinant Calculation

Calculate the determinant of a square matrix.

Matrix Inversion

Calculate the inverse of a square matrix if it is invertible.

Examples

Below are examples of how each operation can be used within the program.

Matrix Addition

Matrix A = {{1, 2}, {3, 4}};
Matrix B = {{5, 6}, {7, 8}};
Matrix C = addMatrices(A, B);
// C is {{6, 8}, {10, 12}}

Matrix Subtraction

Matrix A = {{5, 6}, {7, 8}};
Matrix B = {{1, 2}, {3, 4}};
Matrix C = subtractMatrices(A, B);
// C is {{4, 4}, {4, 4}}

Matrix Multiplication

Matrix A = {{1, 2}, {3, 4}};
Matrix B = {{5, 6}, {7, 8}};
Matrix C = multiplyMatrices(A, B);
// C is {{19, 22}, {43, 50}}

Determinant Calculation

Matrix A = {{1, 2}, {3, 4}};
double det = determinant(A);
// det is -2.0

Matrix Inversion

Copy code
Matrix A = {{4, 7}, {2, 6}};
Matrix invA = inverse(A);
// invA is {{0.6, -0.7}, {-0.2, 0.4}}

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or additions.

Additional Notes

Ensure your matrices are valid (e.g., dimensions match for the required operations). Error handling is included for invalid operations, such as attempting to invert a non-invertible matrix.

About

CLI based application contains some important operations in 2D Matrix

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages