Skip to content

Solve systems of linear equations with photo OCR support. Upload handwritten equations or enter manually. Features Gaussian elimination, Cramer's rule, and step-by-step solutions.

Notifications You must be signed in to change notification settings

gerra/LinearEquationSolver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Linear Equation Solver

A modern React web application for solving systems of linear algebraic equations with advanced features including manual matrix entry, OCR-based photo recognition, and multiple solving methods.

React Vite Material-UI Tesseract.js

Features

🔢 Dynamic Matrix Input

  • Adjustable matrix dimensions (rows × columns)
  • Intuitive grid interface for entering coefficients and constants
  • Real-time validation
  • Support for matrices up to 20×20

📸 Photo Recognition

  • OCR Support: Upload images of handwritten or printed equations
  • AI-Powered (Optional): Integration with OpenAI GPT-4 Vision API for superior accuracy
  • Manual Input Fallback: Type equations directly if OCR fails
  • Automatic processing on upload
  • Review and edit extracted values before solving

🧮 Multiple Solving Methods

  • Gaussian Elimination: Works for any system size with partial pivoting

    • Handles inconsistent systems (no solution)
    • Detects underdetermined systems (infinite solutions)
    • Shows complete step-by-step solution
  • Cramer's Rule: For square matrices where det(A) ≠ 0

    • Automatic validation (requires n×n matrix)
    • Shows determinant calculations
    • Step-by-step solution for each variable

📊 Detailed Results

  • Solution Vector: Clear display of x₁, x₂, ..., xₙ values
  • System Status: Identifies unique, infinite, or no solution cases
  • Step-by-Step Solution: Expandable accordion showing every step
    • Initial augmented matrix
    • Row swaps (pivoting)
    • Elimination steps
    • Back substitution (Gaussian)
    • Determinant calculations (Cramer's)
    • Final solution values

🎨 Modern UI

  • Material Design interface
  • Responsive layout
  • Intuitive controls
  • Clean, professional appearance

Technologies Used

  • React 18: Modern React with hooks and functional components
  • Vite: Fast build tool and development server
  • Material-UI (MUI): Component library for Material Design
  • Tesseract.js: Client-side OCR for text recognition from images
  • OpenAI Vision API (Optional): GPT-4 Vision for advanced image analysis

Installation

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn

Setup

  1. Clone the repository

    git clone https://github.com/yourusername/LizaProject.git
    cd LizaProject
  2. Install dependencies

    npm install
  3. Start development server

    npm run dev
  4. Open in browser Navigate to http://localhost:5173 (or the port shown in terminal)

Building for Production

npm run build

The built files will be in the dist directory.

Usage

Manual Entry

  1. Set Dimensions: Enter the number of rows (equations) and columns (variables)
  2. Enter Matrix: Fill in the coefficient matrix (A) and constants vector (b)
    • Format: Ax = b
    • Each row represents one equation
  3. Select Method: Choose between Gaussian Elimination or Cramer's Rule
  4. Solve: Click "Solve System" to get results

Photo Upload

  1. Switch Tab: Go to "Photo Upload" tab
  2. Upload Image: Click or drag-and-drop an image of your equations
  3. Automatic Processing: OCR automatically extracts the matrix
  4. Review: Edit extracted values if needed in the review dialog
  5. Confirm: Click "Use This Matrix" to populate the manual entry form
  6. Solve: Return to manual entry tab and click "Solve System"

OCR Options

  • Tesseract.js (Default): Free, client-side OCR
  • OpenAI Vision (Optional): Better accuracy, requires API key

Example Equations

The application supports standard equation format:

1x₁ - 1x₂ + 3x₃ - 3x₄ = -12
3x₁ - 2x₂ + 7x₃ - 10x₄ = -36
3x₁ - 5x₂ + 10x₃ - 10x₄ = -36
-3x₁ + 2x₂ - 1x₃ + 15x₄ = 33

Or simplified:

1x1 - 1x2 + 3x3 - 3x4 = -12
3x1 - 2x2 + 7x3 - 10x4 = -36

Project Structure

LizaProject/
├── src/
│   ├── components/
│   │   ├── MatrixSizeSelector.jsx    # Matrix dimension inputs
│   │   ├── MatrixInput.jsx            # Manual matrix entry grid
│   │   ├── PhotoUpload.jsx           # Image upload and OCR
│   │   ├── MethodSelector.jsx        # Solving method selection
│   │   └── ResultsDisplay.jsx        # Solution and steps display
│   ├── utils/
│   │   ├── matrixSolver.js           # Gaussian & Cramer algorithms
│   │   ├── matrixParser.js           # OCR text to matrix parser
│   │   ├── ocrProcessor.js          # Tesseract.js integration
│   │   ├── openaiVision.js          # OpenAI Vision API integration
│   │   └── numberFormatter.js       # Number formatting utilities
│   ├── App.jsx                       # Main application component
│   ├── index.jsx                     # Application entry point
│   └── styles.css                    # Global styles
├── public/
├── package.json
├── vite.config.js
└── README.md

Implementation Details

Matrix Solvers

Gaussian Elimination

  • Implements partial pivoting for numerical stability
  • Detects and handles inconsistent systems
  • Identifies underdetermined systems (infinite solutions)
  • Performs back substitution to find solutions
  • Tracks and displays all intermediate steps

Cramer's Rule

  • Validates square matrix requirement (n×n)
  • Calculates determinant using recursive algorithm
  • Creates modified matrices (Aᵢ) by replacing columns
  • Computes each variable using det(Aᵢ)/det(A)
  • Shows determinant calculations for each step

OCR Processing

Tesseract.js Integration

  • Client-side OCR processing (no backend required)
  • Automatic image preprocessing (contrast enhancement)
  • Character whitelist for better math recognition
  • Progress tracking during processing

OpenAI Vision API

  • Optional integration for superior accuracy
  • Sends image to GPT-4 Vision for analysis
  • Structured prompt for equation extraction
  • Handles complex mathematical notation

Text Parsing

The parser handles multiple formats:

  • Standard equations: 1x1 - 1x2 + 3x3 = -12
  • Subscripts: x₁, x₂ → converted to x1, x2
  • Spaced formats: 1 x 1 - 1 x 2
  • Compact formats: 1x1-1x2+3x3
  • OCR errors: Merged digits, character substitutions

Browser Support

Optimized for Google Chrome. May work in other modern browsers.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is open source and available under the MIT License.

Author

Created with React, Vite, and modern web technologies.

Acknowledgments


Note: For OpenAI Vision API, you need your own API key. This feature is optional and the app works perfectly with free Tesseract OCR.

About

Solve systems of linear equations with photo OCR support. Upload handwritten equations or enter manually. Features Gaussian elimination, Cramer's rule, and step-by-step solutions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages