Skip to content

aryanGupta-09/MatrixCalculator

Repository files navigation

Matrix Calculator

A powerful Android application for performing matrix operations with a clean, intuitive Material 3 UI built with Jetpack Compose and enhanced with native C++ computation.

Screenshots

input-screenshot output-screenshot

Features

  • Matrix Operations: Add, subtract, multiply, and divide matrices
  • Independent Matrix Dimensions: Configure different dimensions for each matrix
  • Advanced Matrix Division: Implements division as multiplication by inverse (B⁻¹)
  • Dynamic Sizing: Easily adjust matrix dimensions on-the-fly
  • High Performance: Matrix operations performed in native C++ code using Eigen library
  • Clean UI: Material 3 design with intuitive interface
  • Error Handling: Comprehensive validation and error messages
  • Responsive Layout: Works well on different screen sizes

Matrix Operations and Dimension Requirements

  • Addition & Subtraction: Both matrices must have the same dimensions
  • Multiplication: Columns of Matrix A must equal rows of Matrix B
  • Division: Second matrix must be square (for computing inverse) and columns of first matrix must equal rows of second matrix

Technologies Used

  • UI Framework: Jetpack Compose
  • Design System: Material 3
  • Architecture: Modern Android architecture
  • Language: Kotlin + C++ (via JNI)
  • Native Binding: Java Native Interface (JNI)
  • Matrix Library: Eigen (C++ library for linear algebra)

Setup and Installation

Prerequisites

  • Android Studio (latest version recommended)
  • Android SDK 24 or higher
  • NDK (Native Development Kit)
  • CMake

Installation Steps

  1. Clone the repository:

    git clone https://github.com/aryanGupta-09/MC_A3.git
    
  2. Open the project in Android Studio

  3. Sync Gradle files and ensure NDK is properly set up

  4. Build and run the application on an emulator or physical device

How to Use

  1. Set Matrix Dimensions: Use the separate dimension controls for each matrix to set their individual rows and columns

  2. Input Values: Enter numerical values in both Matrix A and Matrix B

  3. Select Operation: Choose from Add, Subtract, Multiply, or Divide operations

  4. Calculate: Press the Calculate button to perform the selected operation

  5. View Result: The resulting matrix will be displayed in the Result section

  6. Error Handling: If an operation cannot be performed (e.g., incompatible dimensions for multiplication), an error message will be displayed

Implementation Details

UI Layer

The application uses Jetpack Compose to create a modern, reactive UI with Material 3 design components. The interface is organized into cards for different sections:

  • Matrix A input with its own dimensions
  • Matrix B input with its own dimensions
  • Operation selection
  • Results display

Native Computation Layer

Matrix operations are implemented in C++ for performance:

  • Uses the Eigen library for efficient matrix operations
  • The native code is accessed through JNI (Java Native Interface)
  • Four core operations are provided: add, subtract, multiply, and divide
  • Matrix division is implemented as multiplication by the inverse of the second matrix
  • The implementation handles proper validation of matrix dimensions for each operation

Error Handling

The application provides robust error handling for:

  • Invalid numeric inputs
  • Incompatible matrix dimensions for different operations
  • Singular matrices in division operations (when the determinant is close to zero)
  • Other edge cases