{"id":19418488,"url":"https://github.com/sudipto3331/lagrange-interpolation-numerical-method-implementation-in-python","last_synced_at":"2025-02-25T03:42:23.331Z","repository":{"id":254982360,"uuid":"848166701","full_name":"sudipto3331/Lagrange-Interpolation-Numerical-Method-Implementation-in-Python","owner":"sudipto3331","description":"This repository contains a Python implementation of the Lagrange Interpolation method for estimating the value of a function at a given interpolating point based on a set of data points. The code reads the data points from an Excel file (`datai.xls`), performs the Lagrange interpolation, and plots the results.","archived":false,"fork":false,"pushed_at":"2024-08-27T09:02:02.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-07T17:30:04.366Z","etag":null,"topics":["excel","lagrange-interpolation","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-27T09:00:29.000Z","updated_at":"2024-08-27T09:02:36.000Z","dependencies_parsed_at":"2024-08-27T10:23:16.267Z","dependency_job_id":"6fb7b399-29d9-4957-95d0-d309155191a2","html_url":"https://github.com/sudipto3331/Lagrange-Interpolation-Numerical-Method-Implementation-in-Python","commit_stats":null,"previous_names":["sudipto3331/lagrange-interpolation-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%2FLagrange-Interpolation-Numerical-Method-Implementation-in-Python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudipto3331%2FLagrange-Interpolation-Numerical-Method-Implementation-in-Python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudipto3331%2FLagrange-Interpolation-Numerical-Method-Implementation-in-Python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudipto3331%2FLagrange-Interpolation-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/Lagrange-Interpolation-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","lagrange-interpolation","numerical-analysis","numerical-methods","python3"],"created_at":"2024-11-10T13:14:07.112Z","updated_at":"2025-02-25T03:42:23.315Z","avatar_url":"https://github.com/sudipto3331.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lagrange Interpolation Numerical Method Implementation in Python\n\nThis repository contains a Python implementation of the Lagrange Interpolation method for estimating the value of a function at a given interpolating point based on a set of data points. The code reads the data points from an Excel file (`datai.xls`), performs the Lagrange interpolation, and plots the results.\n\n## Table of Contents\n- [Lagrange Interpolation Theory](#lagrange-interpolation-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## Lagrange Interpolation Theory\nLagrange Interpolation is a polynomial interpolation method that expresses the interpolating polynomial as a linear combination of Lagrange basis polynomials. It is particularly useful when the data points are distinct and not evenly spaced.\n\n**Formula:**\nGiven \\( n \\) data points \\((x_0, y_0)\\), \\((x_1, y_1)\\), ..., \\((x_{n-1}, y_{n-1})\\), the interpolating polynomial \\( P(x) \\) is given by:\n   \\[\n   P(x) = \\sum_{i=0}^{n-1} y_i \\prod_{\\substack{0 \\le j \u003c n \\\\ j \\ne i}} \\frac{x - x_j}{x_i - x_j}\n   \\]\n\n## Dependencies\nTo run this code, you need the following libraries:\n- `numpy`\n- `xlrd`\n- `matplotlib`\n\n## Installation\nTo install the required libraries, you can use `pip`:\n```sh\npip install numpy xlrd matplotlib\n```\n\n## Usage\n1. Clone the repository.\n2. Ensure the script and the Excel file (`datai.xls`) are in the same directory.\n3. Run the script using Python:\n    ```sh\n    python lagrange_interpolation.py\n    ```\n4. Provide the required input when prompted:\n    - Enter the interpolating point.\n\n## Code Explanation\nThe code starts by importing the necessary libraries and taking the interpolating point as input. It reads the data points from the Excel file and performs the Lagrange interpolation to compute the value at the specified interpolating point. The results are then plotted.\n\nBelow is a snippet from the code illustrating the main logic:\n\n```python\nimport numpy as np\nimport xlrd\nfrom matplotlib import pyplot as plt\n\n# Taking necessary input values from keyboard\nX = float(input('Enter the interpolating point: '))\n\n# Reading data from excel file\nloc = ('datai.xls')\nwb = xlrd.open_workbook(loc)\nsheet = wb.sheet_by_index(0)\n\nn = sheet.ncols - 1\nx = np.zeros([n])\ny = np.zeros([n])\nY = 0\n\nfor i in range(1, sheet.ncols):\n    x[i-1] = sheet.cell_value(0, i)\n    y[i-1] = sheet.cell_value(1, i)\n\n# Performing Lagrange interpolation    \nfor i in range(n):\n    a = 1\n    b = 1\n    for j in range(n):\n        if j != i:\n            a *= (X - x[j])\n            b *= (x[i] - x[j])\n    Y += (a / b) * y[i]\n    \nprint('The interpolating result at x = ' + str(Y))\n\nplt.figure(1)\nplt.plot(x, y) \nplt.plot(X, Y, 'o')\nplt.xlabel('Values of x')\nplt.ylabel('Values of y')\nplt.title('Graphical verification of the interpolation result')\nplt.legend(['Measured', 'Estimated / Interpolated'], loc='best')\nplt.show()\n```\n\nThe code completes by plotting the original data points and the interpolated point using `matplotlib`.\n\n## Example\nBelow is an example of how to use the script:\n\n1. Prepare the `datai.xls` file with the data points. The first row should contain the \\( x \\)-values and the second row should contain the corresponding \\( y \\)-values.\n2. **Run the script**:\n    ```sh\n    python lagrange_interpolation.py\n    ```\n\n3. **Enter the input value**:\n    ```\n    Enter the interpolating point: 2.5\n    ```\n\n4. **Output**:\n    - The script will compute the interpolated value at the specified point and plot the original data points along with the interpolated point.\n\n## Files in the Repository\n- `lagrange_interpolation.py`: The main script for performing Lagrange Interpolation.\n- `datai.xls`: Excel file from which the data points are read.\n\n## Input Parameters\nThe initial input data is expected to be in the form of two rows within the `datai.xls` file:\n- First row: \\( x \\)-values\n- Second row: \\( y \\)-values\n\n## Troubleshooting\n1. **Excel File**: Ensure that the input data is correctly formatted and placed in the `datai.xls` file.\n2. **Interpolating Point**: Ensure the interpolating point falls within the range of the input \\( x \\)-values.\n3. **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 Lagrange Interpolation 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%2Flagrange-interpolation-numerical-method-implementation-in-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsudipto3331%2Flagrange-interpolation-numerical-method-implementation-in-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudipto3331%2Flagrange-interpolation-numerical-method-implementation-in-python/lists"}