{"id":25970639,"url":"https://github.com/michaelehab/numerical-methods","last_synced_at":"2025-03-04T23:18:40.437Z","repository":{"id":62089490,"uuid":"501787069","full_name":"michaelehab/Numerical-Methods","owner":"michaelehab","description":"A repository containing python codes for the numerical methods I studied in Numerical Analysis course during Spring 2022 semester","archived":false,"fork":false,"pushed_at":"2022-07-19T11:37:50.000Z","size":45,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-05-06T15:06:23.321Z","etag":null,"topics":["divided-differences","fixed-point","gauss-quadrature","gauss-seidel","interpolation","lagrange-interpolation","learn","linear-regression","non-linear","numerical-analysis","numerical-differentiation","numerical-integration","numerical-methods","ode","regression","simpson-rule","trapezoidal-rule"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michaelehab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-09T19:41:03.000Z","updated_at":"2022-12-31T04:56:23.000Z","dependencies_parsed_at":"2022-10-26T07:45:46.154Z","dependency_job_id":null,"html_url":"https://github.com/michaelehab/Numerical-Methods","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelehab%2FNumerical-Methods","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelehab%2FNumerical-Methods/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelehab%2FNumerical-Methods/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelehab%2FNumerical-Methods/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaelehab","download_url":"https://codeload.github.com/michaelehab/Numerical-Methods/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241935319,"owners_count":20044834,"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":["divided-differences","fixed-point","gauss-quadrature","gauss-seidel","interpolation","lagrange-interpolation","learn","linear-regression","non-linear","numerical-analysis","numerical-differentiation","numerical-integration","numerical-methods","ode","regression","simpson-rule","trapezoidal-rule"],"created_at":"2025-03-04T23:18:40.034Z","updated_at":"2025-03-04T23:18:40.420Z","avatar_url":"https://github.com/michaelehab.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Numerical Methods implemented in Python\n\u003cdiv align=\"center\"\u003e\n\n![GitHub stars](https://img.shields.io/github/stars/michaelehab/Numerical-Methods?style=plastic)\n![GitHub forks](https://img.shields.io/github/forks/michaelehab/Numerical-Methods?style=plastic)\n![GitHub repo size](https://img.shields.io/github/repo-size/michaelehab/Numerical-Methods?style=plastic)\n![GitHub top language](https://img.shields.io/github/languages/top/michaelehab/Numerical-Methods?style=plastic)\n\u003c/div\u003e\n\n# Definition 📃(\u003ca href=\"https://en.wikipedia.org/wiki/Numerical_analysis\"\u003eWIKI\u003c/a\u003e):\nNumerical analysis is the study of algorithms that use numerical approximation for the problems of mathematical analysis. Numerical analysis finds application in all fields of engineering and the physical sciences, and in the 21st century also the life and social sciences, medicine, business and even the arts.\n\n# Subjects 📘\n## \u003ca href=\"./interpolation.py\"\u003eInterpolation\u003c/a\u003e\n### 1. Lagrange Interpolating Polynomial:\n#### Example : \n\u003ctable align=\"center\"\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eX\u003c/td\u003e \n    \u003ctd\u003e1.0\u003c/td\u003e\n    \u003ctd\u003e1.3\u003c/td\u003e\n    \u003ctd\u003e1.5\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eY\u003c/td\u003e\n    \u003ctd\u003e0.841\u003c/td\u003e\n    \u003ctd\u003e0.964\u003c/td\u003e\n    \u003ctd\u003e0.997\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Using Lagrange Polynomial :\n$$l_k(x)= \\prod_{i=0,\\, i\\neq k}^{n} \\frac{x-x_i}{x_k-x_i}=\\frac{x-x_0}{x_k-x_0} \\cdots \\frac{x-x_{k-1}}{x_k-x_{k-1}} \\frac{x-x_{k+1}}{x_k-x_{k+1}} \\cdots \\frac{x-x_{n}}{x_k-x_{n}}$$\n\n$$l_2(1.4)=0.9854$$\n\n### 2. Newton Divided Difference:\n#### Example : \n\u003ctable align=\"center\"\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eX\u003c/td\u003e \n    \u003ctd\u003e0\u003c/td\u003e\n    \u003ctd\u003e2\u003c/td\u003e\n    \u003ctd\u003e4\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eY\u003c/td\u003e\n    \u003ctd\u003e1\u003c/td\u003e\n    \u003ctd\u003e5\u003c/td\u003e\n    \u003ctd\u003e17\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n#### Using Newton Divided Difference :\n$$\\left[\\begin{array}{ccccc}\nx_0=0 \u0026 f[x_0]=1  \u0026                  \u0026 \u0026 \\cr\nx_1=2 \u0026 f[x_1]=5   \u0026 f[x_0,x_1]=\\displaystyle\\frac{5-1}{2-0} = 2\u0026 \u0026 \\cr\nx_2=4 \u0026 f[x_2]=17 \u0026 f[x_1,x_2]=\\displaystyle\\frac{17-5}{4-2}=6  \u0026  f[x_0,x_1,x_2]=\n\\displaystyle\\frac{6-2}{4-0}=1\n  \u0026 \n\\end{array}\\right]$$\n\nThen\n\n$$\\begin{array}{rcl}\nP_2(x)\u0026=\u0026f[x_0]+f[x_0,x_1]x+f[x_0,x_1,x_2]x(x-2)\\\\\n\u0026=\u00261+2x+x(x-2)\\\\\n\u0026=\u00261+x^2\n\\end{array}$$\n\n## \u003ca href=\"./differentiation.py\"\u003eDifferentiation\u003c/a\u003e\n### 1. Forward Difference\n$$f^ \\prime(x) = \\frac{f(x + \\Delta x) - f(x)}{\\Delta x}$$\n\n$$f^{\\prime \\prime}(x) = \\frac{f(x + 2\\Delta x) - 2f(x + \\Delta x) + f(x)}{(\\Delta x)^2}$$\n\n### 2. Backward Difference\n$$f^ \\prime(x) = \\frac{f(x) - f(x - \\Delta x)}{\\Delta x}$$\n\n### 3. Centered Difference\n$$f^ \\prime(x) = \\frac{f(x + \\Delta x) - f(x - \\Delta x)}{2\\Delta x}$$\n\n$$f^{\\prime \\prime}(x) = \\frac{f(x + \\Delta x) + f(x - \\Delta x) - 2f(x)}{(\\Delta x)^2}$$\n## \u003ca href=\"./integration.py\"\u003eIntegration\u003c/a\u003e\n### 1. Trapezoidal Rule\n$$\\int_{a}^b f(x)dx=\\frac{h}{2}(f(a)+f(b)+2\\sum_{i=0}^{n-1}f(a + ih))$$\nWhere:\n\n$$h = \\frac{b - a}{numberOfSegments}$$\n\n### 2. Simpson $\\frac{1}{3}$ Rule\n$$\\int_{a}^b f(x)dx=\\frac{h}{3}(f(x)+f(x_n)+2\\sum_{i(even)=0}^{n-2}f(x_i)+4\\sum_{i(odd)=0}^{n-1}f(x_i))$$\nWhere:\n\n$$h = \\frac{b - a}{numberOfSegments}$$\n\n### 3. 2-Points Gauss Quadrature\n$$\\int_{a}^b f(x)dx=\\frac{b - a}{2}(f(\\frac{b - a}{2} * \\frac{1}{\\sqrt{3}} + \\frac{b + a}{2}) + f(\\frac{b - a}{2} * \\frac{-1}{\\sqrt{3}} + \\frac{b + a}{2}))$$\n\n### 4. MidPoint Rule (One Point Gauss Quadrature)\n$$\\int_{a}^b f(x)dx=(b - a)f(\\frac{b + a}{2})$$\n\n## \u003ca href=\"./regression.py\"\u003eRegression\u003c/a\u003e\n### Linear Regression ($y = a + bx$)\n\n$$\\begin{bmatrix}\n\\sum_{1}^{n} 1 \u0026 \\sum_{1}^{n} x_i \\\\\n\\sum_{1}^{n} x_i \u0026 \\sum_{1}^{n} (x_i)^2\n\\end{bmatrix}\n\\begin{bmatrix}\na \\\\\nb\n\\end{bmatrix} =\n\\begin{bmatrix}\n\\sum_{1}^{n} y_i \\\\\n\\sum_{1}^{n} x_i y_i\n\\end{bmatrix}$$\n## \u003ca href=\"./ode.py\"\u003eODE\u003c/a\u003e\n### 1. Euler Method ($y(t0) = y0$ \u0026 $f(x_i, y_i) = \\frac{dy}{dx}$)\n$$y_{i+1} = y_i + hf(x_i, y_i)$$\n\n### 2. Taylor Method ($y(t0) = y0$ \u0026 $f(x_i, y_i) = \\frac{dy}{dx}$)\n$$y_{i+1} = y_i + hf(x_i, y_i) + \\frac{h^2}{2}f^\\prime(x_i, y_i)$$\n\n### 3. Runge-Kutta 2nd Order ($y(t0) = y0$ \u0026 $f(x_i, y_i) = \\frac{dy}{dx}$)\n$$k_1 = f(x_i, y_i)$$\n\n$$k_2 = f(x_i + p_1h, y_i + q_1 k_1 h)$$\n\n$$y_{i+1} = y_i + h(a_1 k_1 + a_2 k_2)$$\n#### Heun: $(a_1 = \\frac{1}{2}, a_2 = \\frac{1}{2}, p_1 = q_1 = 1)$\n#### Midpoint: $(a_1 = 0, a_2 = 1, p_1 = q_1 = \\frac{1}{2})$\n#### Ralston: $(a_1 = \\frac{1}{3}, a_2 = \\frac{2}{3}, p_1 = q_1 = \\frac{3}{4})$\n\n### 4. Runge-Kutta 4th Order ($y(t0) = y0$ \u0026 $f(x_i, y_i) = \\frac{dy}{dx}$)\n$$k_1 = f(x_i, y_i)$$\n\n$$k_2 = f(x_i + \\frac{h}{2}, y_i + \\frac{k_1 h}{2})$$\n\n$$k_3 = f(x_i + \\frac{h}{2}, y_i + \\frac{k_2 h}{2})$$\n\n$$k_4 = f(x_i + h, y_i + k_3 h)$$\n\n$$y_{i+1} = y_i + \\frac{h}{6}(k_1 + 2k_2 + 2k_3 + k_4)$$\n## \u003ca href=\"./eigenvalues.py\"\u003eEigenvalues\u003c/a\u003e\n### 1. Normalized Power Method\n* Let $x_0$ be an initial approximation to the eigenvector.\n* For $k=1,2,3,\\ldots$ do\n  * Compute $x_k=Ax_{k-1}$,\n  * Normalize $x_k=x_k/\\|x_k\\|_\\infty$\n* Stop when tolerance is $t$\n  \n## \u003ca href=\"./nonlinear.py\"\u003eNon-Linear Equations\u003c/a\u003e\n### 1. Fixed Point\n$$F(x) = 0$$\n\n$$x = G(x)$$\n\n$$x^{(k)} = G(x^{(k -1)})$$\n\n### 2. Gauss Seidel\n$$x^{(k)} = G(x^{(k)})$$\n\n### 3. Newton's Method\n$$-F(x^{(k - 1)}) = J(x^{(k - 1)})y^{(k - 1)}$$\n\n$$x^{(k)} = x^{(k - 1)} + y^{(k - 1)}$$\n\nwhere\n\n$$\nJ =\n\\begin{bmatrix}\n  \\frac{\\partial F_1}{\\partial x_1} \u0026 \\frac{\\partial F_1}{\\partial x_2} \u0026 \\cdots \u0026 \\frac{\\partial F_1}{\\partial x_n} \\\\\n  \\frac{\\partial F_2}{\\partial x_1} \u0026 \\frac{\\partial F_2}{\\partial x_2} \u0026 \\cdots \u0026 \\frac{\\partial F_2}{\\partial x_n} \\\\\n  \\vdots \u0026 \\vdots \u0026 \\ddots \u0026 \\vdots \\\\\n  \\frac{\\partial F_m}{\\partial x_1} \u0026 \\frac{\\partial F_m}{\\partial x_2} \u0026 \\cdots \u0026 \\frac{\\partial F_m}{\\partial x_n} \\\\\n\\end{bmatrix}\n$$\n\nSetting the environment 🛠\n--------------------------\n#### 1. Make sure python v3.7 or higher is installed:\n\n```console\n* To get the version Excute:\n$ python --version\nPython 3.9.6\n```\n\u003e if not installed watch the following [video](https://www.youtube.com/watch?v=VWgs_iTojoA)\n\n#### 2. Make Sure Git is installed:\n```console\n* To get the version Excute:\n$ git --version\ngit version 2.28.0.windows.1\n```\n\u003e if not installed watch the following [video](https://www.youtube.com/watch?v=2j7fD92g-gE)\n\n#### 3. Execute the following commands in your terminal after changing your directory to the desired path\n\n```console\n$ mkdir Numerical-Methods\n$ python -m venv venv```\n```\nFor Windows Users:\n```\n$ venv\\Scripts\\activate.bat\n```\nFor Linux Users:\n```\n$ source venv/bin/activate\n```\nThen\n```\n$ git clone https://github.com/michaelehab/Numerical-Methods \u0026\u0026 cd Numerical-Methods\n$ pip install -r requirements.txt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelehab%2Fnumerical-methods","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaelehab%2Fnumerical-methods","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelehab%2Fnumerical-methods/lists"}