Skip to content

This repository provides a Python-based solution for solving systems of linear equations using two efficient numerical methods: 1. Gauss-Jordan Elimination 2. LU Decomposition

Notifications You must be signed in to change notification settings

Reza-Rezvan/linear-equation-solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Linear Equation Solver: Gauss-Jordan and LU Decomposition

This repository contains Python implementations for solving systems of linear equations using two numerical methods:

  1. Gauss-Jordan Elimination
  2. LU Decomposition

These methods can be applied to solve any square system of linear equations. The code is written in a modular way for clarity and easy integration.

Features

  • Solve a system of linear equations using the Gauss-Jordan Elimination method.
  • Solve the same system using LU Decomposition (with forward and backward substitution).
  • Handles errors for systems with no unique solutions.

Requirements

The following Python libraries are required:

  • numpy

Install the dependencies using pip:

pip install numpy

Usage

Clone the repository and run the solver.py script:

git clone <repository-url>
cd <repository-directory>
python solver.py

Example Input

The script solves a system of equations, such as:

2x + y - z = 8
-3x - y + 2z = -11
-2x + y + 2z = -3

Represented in matrix form:

A = [[2,  1, -1],
     [-3, -1,  2],
     [-2,  1,  2]]

b = [8, -11, -3]

Output

The script provides solutions using both methods:

Solution using Gauss-Jordan:
[ 2.  3. -1.]

Solution using LU Decomposition:
[ 2.  3. -1.]

Functions

Gauss-Jordan Method

  • Function: gauss_jordan(a, b)
  • Description: Solves a system of equations by transforming the coefficient matrix into reduced row echelon form.

LU Decomposition Method

  • Functions:
    • lu_decomposition(a)
    • forward_substitution(L, b)
    • backward_substitution(U, y)
    • solve_lu(a, b)
  • Description: Decomposes the matrix into lower (L) and upper (U) triangular matrices, solves using substitution.

Error Handling

  • Raises errors for singular matrices or systems with no unique solutions.

Feel free to modify and expand the code for your specific use cases!

About

This repository provides a Python-based solution for solving systems of linear equations using two efficient numerical methods: 1. Gauss-Jordan Elimination 2. LU Decomposition

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy