{"id":19418493,"url":"https://github.com/sudipto3331/gauss-seidel-elimination-numerical-method-implementation-in-python","last_synced_at":"2025-07-16T13:10:54.852Z","repository":{"id":254975504,"uuid":"848144801","full_name":"sudipto3331/Gauss-Seidel-Elimination-Numerical-Method-Implementation-in-Python","owner":"sudipto3331","description":"This repository contains a Python implementation of the Gauss-Seidel Elimination method for solving systems of linear equations. The code reads coefficients from an Excel file (`data.xls`), performs Gauss-Seidel iteration with relaxation, and saves the results in a new Excel file. The method also includes error checking and verifies the results.","archived":false,"fork":false,"pushed_at":"2024-08-27T08:10:27.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-07T17:29:59.857Z","etag":null,"topics":["excel-export","gauss-seidel-iteration","gauss-seidel-method","numerical-analysis","numerical-methods","python3"],"latest_commit_sha":null,"homepage":"http://sudiptomondal.me/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sudipto3331.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-27T08:05:30.000Z","updated_at":"2024-08-27T08:11:19.000Z","dependencies_parsed_at":"2024-08-27T09:27:53.253Z","dependency_job_id":"6b9b0831-423a-4fba-bfef-6c48754d3d65","html_url":"https://github.com/sudipto3331/Gauss-Seidel-Elimination-Numerical-Method-Implementation-in-Python","commit_stats":null,"previous_names":["sudipto3331/gauss-seidel-elimination-numerical-method-implementation-in-python"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudipto3331%2FGauss-Seidel-Elimination-Numerical-Method-Implementation-in-Python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudipto3331%2FGauss-Seidel-Elimination-Numerical-Method-Implementation-in-Python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudipto3331%2FGauss-Seidel-Elimination-Numerical-Method-Implementation-in-Python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudipto3331%2FGauss-Seidel-Elimination-Numerical-Method-Implementation-in-Python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sudipto3331","download_url":"https://codeload.github.com/sudipto3331/Gauss-Seidel-Elimination-Numerical-Method-Implementation-in-Python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240599180,"owners_count":19826959,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["excel-export","gauss-seidel-iteration","gauss-seidel-method","numerical-analysis","numerical-methods","python3"],"created_at":"2024-11-10T13:14:08.180Z","updated_at":"2025-02-25T03:42:24.752Z","avatar_url":"https://github.com/sudipto3331.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gauss Seidel Elimination Numerical Method Implementation in Python\n\nThis repository contains a Python implementation of the Gauss-Seidel Elimination method for solving systems of linear equations. The code reads coefficients from an Excel file (`data.xls`), performs Gauss-Seidel iteration with relaxation, and saves the results in a new Excel file. The method also includes error checking and verifies the results.\n\n## Table of Contents\n- [Gauss-Seidel Elimination Theory](#gauss-seidel-elimination-theory)\n- [Dependencies](#dependencies)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Code Explanation](#code-explanation)\n- [Example](#example)\n- [Files in the Repository](#files-in-the-repository)\n- [Input Parameters](#input-parameters)\n- [Troubleshooting](#troubleshooting)\n- [Author](#author)\n\n## Gauss-Seidel Elimination Theory\nThe Gauss-Seidel method is an iterative technique for solving systems of linear equations. It improves upon the Jacobi method by using the latest updates to the values of the unknowns immediately within the iteration.\n\n**Steps:**\n1. Initialize initial guesses for all unknowns.\n2. Iterate over each equation and solve for the current unknown using the latest available values of other unknowns.\n3. Apply a relaxation factor to accelerate convergence.\n4. Check for convergence by comparing the relative errors to a desired threshold.\n\n## Dependencies\nTo run this code, you need the following libraries:\n- `numpy`\n- `xlrd`\n- `xlwt`\n\n## Installation\nTo install the required libraries, you can use `pip`:\n```sh\npip install numpy xlrd xlwt\n```\n\n## Usage\n1. Clone the repository.\n2. Ensure the script and the Excel file (`data.xls`) are in the same directory.\n3. Run the script using Python:\n    ```sh\n    python gauss_seidel_elimination.py\n    ```\n4. Provide the required inputs when prompted:\n    - Enter the desired percentage relative error.\n    - Enter the number of iterations.\n    - Enter the relaxation factor.\n5. The script will read the coefficients from the Excel file, perform Gauss-Seidel Elimination, and write the results into a new Excel file named `xlwt_example.xls`.\n\n## Code Explanation\nThe code begins by importing the necessary libraries and defining a helper function `brcond_Seidel` to check the convergence condition. It then reads the coefficients and constants from the Excel file into numpy arrays. The main iteration loop performs Gauss-Seidel updates and checks for convergence. The results are written into a new sheet in an Excel file.\n\nBelow is a snippet from the code illustrating the main logic:\n\n```python\nimport numpy as np\nimport xlrd\nfrom xlwt import Workbook\n\ndef brcond_Seidel(E, err, n):\n    a = 0\n    for i in range(n):\n        if E[i] \u003c err:\n            a += 1\n    return a / n\n\nerr = float(input('Enter desired percentage relative error: '))\nite = int(input('Enter number of iterations: '))\nrelaxation = float(input('Enter relaxation factor: '))\n\nloc = ('data.xls')\nwb = xlrd.open_workbook(loc)\nsheet = wb.sheet_by_index(3)\n\nn = sheet.nrows\na = np.zeros([n, n+1])\nE = np.zeros([n])\nrel_err = np.zeros([ite, n])\nX = np.zeros([n])\nx = np.zeros([ite, n])\nx_new = np.zeros([ite, n])\nitern = np.zeros([ite])\np = np.zeros([n])\n\nfor i in range(sheet.ncols):\n    for j in range(sheet.nrows):\n        a[j, i] = sheet.cell_value(j, i)\n\n# Iteration for Gauss-Seidel begins here\nfor j in range(ite):\n    itern[j] = j + 1\n    for i in range(n):\n        summation = 0\n        for k in range(n):\n            if k != i:\n                summation += a[i, k] * x[j, k]\n        x_new[j, i] = (a[i, n] - summation) / a[i, i]\n        if j \u003e 0:\n            x[j, i] = x_new[j, i] * relaxation + (1 - relaxation) * x[j-1, i]\n        else:\n            x[j, i] = x_new[j, i]\n        if j \u003e 0:\n            rel_err[j, i] = abs((x[j, i] - x[j-1, i]) / x[j, i]) * 100\n            E[i] = rel_err[j, i]\n\n    if j \u003e 0 and brcond_Seidel(E, err, n) == 1:\n        break\n    elif j == ite - 1:\n        break\n\n    x[j+1, :] = x[j, :]\n\nnum_of_iter = j\nX = x[j, :]\n\nprint('The values of the unknown variables are respectively:')\nprint(X)\n\nwb = Workbook()\nsheet1 = wb.add_sheet('Sheet 1')\n\nsheet1.write(0, n, 'Gauss')\nsheet1.write(0, n+1, 'Seidel')\nsheet1.write(1, 0, 'Number of iteration')\n\nfor i in range(1, n+1):\n    sheet1.write(1, i, 'x_' + str(i))\nfor i in range(n+1, 2*n+1):\n    sheet1.write(1, i, 'Relative error of x_' + str(i-n))\n\nfor i in range(num_of_iter+1):\n    sheet1.write(i+2, 0, itern[i])\n    for j in range(n):\n        sheet1.write(i+2, 1+j, x[i, j])\n        sheet1.write(i+2, n+1+j, rel_err[i, j])\n\nsheet1.write(i+4, 0, 'The')\nsheet1.write(i+4, 1, 'unknown')\nsheet1.write(i+4, 2, 'values')\nsheet1.write(i+4, 3, 'are:')\nfor k in range(n):\n    sheet1.write(i+4, k+4, X[k])\n\nwb.save('xlwt_example.xls')\n\n# Result Verification\nfor i in range(n):\n    summation = 0\n    for j in range(n):\n        summation += a[i, j] * X[j]\n    p[i] = summation - a[i, j+1]\n\nprint('The verification results are:')\nprint(p)\nprint('The implementation is correct if verification results are all zero')\n```\n\nThe code completes by saving the final results into the Excel file `xlwt_example.xls` and prints verification results.\n\n## Example\nBelow is an example of how to use the script:\n\n1. Prepare the `data.xls` file with the system of equations in matrix form.\n2. **Run the script**:\n    ```sh\n    python gauss_seidel_elimination.py\n    ```\n\n3. **Enter the input values**:\n    ```\n    Enter desired percentage relative error: 0.001\n    Enter number of iterations: 50\n    Enter relaxation factor: 1.0\n    ```\n\n4. **Output**:\n    - The script will compute the results using the Gauss-Seidel Elimination method and write the intermediate and final results into the Excel file (`xlwt_example.xls`).\n    - The console will display the values of the unknowns and the verification results.\n\n## Files in the Repository\n- `gauss_seidel_elimination.py`: The main script for performing the Gauss-Seidel Elimination method.\n- `data.xls`: Excel file from which the matrix data is read and into which the results are written.\n\n## Input Parameters\nThe initial input data is expected to be in the form of a matrix within the `data.xls` file. Each row represents coefficients of the variables in the equations along with the constants.\n\n## Troubleshooting\n1. **Excel File**: Ensure that the input matrix is correct and placed in the `data.xls` file.\n2. **Matrix Format**: Confirm that the matrix is complete and correctly formatted.\n3. **Excel File Creation**: Ensure you have write permissions in the directory where the script is run to save the Excel file.\n4. **Python Version**: This script is compatible with Python 3. Ensure you have Python 3 installed.\n\n## Author\nScript created by sudipto3331.\n\n---\n\nThis documentation should guide you through understanding, installing, and using the Gauss-Seidel Elimination method script. For further issues or feature requests, please open an issue in the repository on GitHub. Feel free to contribute by creating issues and submitting pull requests. Happy coding!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudipto3331%2Fgauss-seidel-elimination-numerical-method-implementation-in-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsudipto3331%2Fgauss-seidel-elimination-numerical-method-implementation-in-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudipto3331%2Fgauss-seidel-elimination-numerical-method-implementation-in-python/lists"}