GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - hayk1minasyan2/programming-1-semester-project-gaussian-elimination-python: Solving systems of linear equations by Gaussian elimination (RREF, parametric solutions) in Python. Programming 1 semester project, Charles University.

BranchesTags
Open more actions menu

Latest commit

 

History

1 Commit
1 Commit

Folders and files

NameName
Last commit message
Last commit date
docs
docs
 
 
examples
examples
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
gaussian_elimination.py
gaussian_elimination.py
 
 

Repository files navigation

Programming 1 Semester Project - Gaussian Elimination

A command-line Python program that solves systems of linear equations by Gaussian elimination.

  • Two input modes: a coefficient matrix (augmented, last column is the right-hand side), or equations written with named variables (2x + 3y - z = 5).
  • Reduces the matrix to reduced row echelon form (RREF) and prints it.
  • Reads the solution off the RREF: a unique value per variable, or, for underdetermined systems, a parametric solution with free variables t_k.
  • Pure Python, standard library only.

Requirements

Python 3.12 or newer (the code uses nested same-quote f-strings, which earlier versions reject).

Run

python3 gaussian_elimination.py

The program first asks for the input mode, m (matrix) or e (equations); M, E and the quoted forms 'm', 'e' are also accepted. It then reads the system from standard input until end of file (Ctrl-D on Linux/macOS, Ctrl-Z Enter on Windows).

Input can also be redirected from a file whose first line is the mode:

python3 gaussian_elimination.py < examples/equations_input.txt

Input format

Matrix mode (m). One equation per line, coefficients separated by spaces, the last number being the right-hand side. A variable missing from an equation gets coefficient 0. Entries are parsed as integers. Variables are named x_1, x_2, ... in the output.

m
1 2 3 4
2 4 6 8

Equation mode (e). One equation per line, any variable names, constant on the right-hand side. Allowed operators are +, - and =; coefficients may be decimals with a dot as the decimal mark. Spaces are ignored. Every line, including the last, must end with a newline.

e
2x + 3y - z = 5
x - y + 2z = 3
3x + y + z = 10

Example

$ python3 gaussian_elimination.py < examples/equations_input.txt
 Input system of linear equations.
 Your input should be the coefficient matrix of the system.
 In each row write one linear equation.
 Type 0 for variables, which do not participate in your equations:

Please clerify your input method: for matrix enter 'm', for equations enter 'e' :Enter your system of linear equations:

 Here is the reduced row echelon form of your matrix:

1    0    0    4.6
0    1    0    -2
0    0    1    -1.8

x = 4.6
y = -2
z = -1.8

A system with infinitely many solutions:

$ python3 gaussian_elimination.py < examples/infinitely_many.txt
...
 Here is the reduced row echelon form of your matrix:

1    2    3    4
0    0    0    0

x_1 = 4 - 2t_2- 3t_3
x_2 = t_2
x_3 = t_3

Known limitations

  • Arithmetic is in floating point; displayed values are rounded to about four significant decimals (e.g. -0.8571).
  • The consistency check described in the developer documentation (check_consistence()) is defined but not called in the final version, so an inconsistent system is not reported as such; its RREF is printed and a (meaningless) solution is read off.
  • A variable whose column is entirely zero is printed as None instead of as a free parameter.
  • Matrix mode accepts integer entries only; decimals are accepted only in equation mode.

Project structure

gaussian_elimination.py              The program
examples/matrix_input.txt            Sample input, matrix mode
examples/equations_input.txt         Sample input, equation mode
examples/infinitely_many.txt         Sample input with free variables
docs/User_Documentation.md / .pdf
docs/Developer_Documentation.md / .pdf
docs/Project_Proposal.md / .pdf
docs/original/                       Original LaTeX sources and PDFs

Documentation

  • User documentation
  • Developer documentation
  • Project proposal

Author

Hayk Minasyan

Semester project for Programming 1, Charles University, Faculty of Mathematics and Physics (MFF UK), 2024/25

About

Solving systems of linear equations by Gaussian elimination (RREF, parametric solutions) in Python. Programming 1 semester project, Charles University.

Topics

gaussian-eliminationlinear-algebralinear-equationsmatrixpythonrrefstudent-project

Resources

Readme
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.