{"id":24917032,"url":"https://github.com/codernayeem/numericalproject","last_synced_at":"2025-03-28T07:44:56.059Z","repository":{"id":259588657,"uuid":"878051363","full_name":"codernayeem/NumericalProject","owner":"codernayeem","description":"A console application to solve problems using various numerical methods","archived":false,"fork":false,"pushed_at":"2024-11-27T19:50:18.000Z","size":57,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T08:31:40.098Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","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/codernayeem.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-24T17:34:36.000Z","updated_at":"2024-11-27T19:57:22.000Z","dependencies_parsed_at":"2024-10-26T19:09:11.203Z","dependency_job_id":"4ab91c92-c0f6-4203-8f57-c537990efa68","html_url":"https://github.com/codernayeem/NumericalProject","commit_stats":null,"previous_names":["codernayeem/numericalproject"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codernayeem%2FNumericalProject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codernayeem%2FNumericalProject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codernayeem%2FNumericalProject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codernayeem%2FNumericalProject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codernayeem","download_url":"https://codeload.github.com/codernayeem/NumericalProject/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245991559,"owners_count":20706126,"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":[],"created_at":"2025-02-02T08:30:44.396Z","updated_at":"2025-03-28T07:44:56.040Z","avatar_url":"https://github.com/codernayeem.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Numerical Methods Console Application\n\nThis console application implements various numerical methods for solving linear equations, non-linear equations, and differential equations, along with matrix inversion. Each algorithm is designed to perform specific calculations and is encapsulated in separate files for modularity and clarity.\n\n## Table of Contents\n- [Usage](#usage)\n- __Algorithms Explanation__\n  - Linear Equations\n    - Jacobi Method\n    - Gauss-Seidel Method\n    - Gauss Elimination\n    - Gauss-Jordan Elimination\n    - LU Factorization\n  - Non-linear Equations\n    - Bisection Method\n    - False Position Method\n    - Secant Method\n    - Newton-Raphson Method\n  - Differential Equations\n    - Runge-Kutta Method\n  - Matrix Inversion\n- [Contributors](#contributors)\n\n## Usage\n1. Clone the repository:\n   - `git clone https://github.com/codernayeem/NumericalProject.git`\n2. Navigate to the project directory:\n   - `cd NumericalProject`\n3. Compile \u0026 Run the application:\n   - `./run.bat`\n4. (Optional) Run the application _(After building once)_:\n   - `./numerical_methods`\n\n# Working Principle of Algorithms and Features\n## Linear\n### 1. Jacobi Iterative Method\nThe Jacobi method iteratively solves the system `Ax = b` by separating `A` into its diagonal and non-diagonal parts.\n\n**Steps**:\n1. Initialize `x^(0)`.\n2. For each iteration `k`:\n   - Update each element `x_i^(k+1)` using:\n     ```\n     x_i^(k+1) = (b_i - sum(a_ij * x_j^(k)) for j != i) / a_ii\n     ```\n3. Check for convergence by evaluating if the average error falls below a tolerance level.\n\n**Features**:\n- Convergence check based on tolerance.\n- Diagonal dominance check for matrix stability.\n\n---\n\n### 2. Gauss-Seidel Iterative Method\nThe Gauss-Seidel method is similar to Jacobi but uses the most recent values of `x` during each update.\n\n**Steps**:\n1. Initialize `x^(0)`.\n2. For each iteration `k`:\n   - Update `x_i^(k+1)` using previously updated values:\n     ```\n     x_i^(k+1) = (b_i - sum(a_ij * x_j^(k+1)) for j \u003c i - sum(a_ij * x_j^(k)) for j \u003e i) / a_ii\n     ```\n3. Convergence is achieved if the average error is less than the tolerance level.\n\n**Features**:\n- Faster convergence by using updated values immediately.\n- Similar tolerance and diagonal dominance check as Jacobi.\n\n---\n\n### 3. Gauss Elimination\nGauss Elimination transforms the matrix `A` into an upper triangular form to solve the system.\n\n**Steps**:\n1. Perform partial pivoting to select the largest element as the pivot.\n2. For each row `i`:\n   - Eliminate variables below the pivot:\n     ```\n     A[j] = A[j] - (A[j][i] / A[i][i]) * A[i]\n     ```\n3. Use back substitution to solve for `x`.\n\n**Features**:\n- Allows handling of singular matrices with a result indicating infinite or no solutions.\n\n---\n\n### 4. Gauss-Jordan Elimination\nAn extension of Gauss Elimination, Gauss-Jordan transforms `A` into a reduced row-echelon form.\n\n**Steps**:\n1. For each column:\n   - Select a pivot, divide the row by the pivot to make it 1.\n2. Eliminate other rows:\n   - For each row `i`, subtract multiples of the pivot row to zero out the column.\n3. Solution vector `x` is obtained directly.\n\n**Features**:\n- Provides a unique solution if it exists.\n- Checks for singular matrices.\n\n---\n\n### 5. LU Factorization\nLU Factorization decomposes `A` as `A = LU`, where `L` is a lower triangular matrix and `U` is an upper triangular matrix.\n\n**Steps**:\n1. Decompose `A` such that: `A = LU`\n2. Solve `Ly = b` for `y` using forward substitution.\n3. Solve `Ux = y` for `x` using back substitution.\n\n**Features**:\n- Efficient for systems with multiple right-hand side vectors.\n- Limited to `n \u003c= 4` in this implementation.\n\n## Non-Linear \n\n### 1. Bisection Method\nThe Bisection Method is a bracketing method used to find the root of a function `f(x)` within an interval `[a, b]` where `f(a) * f(b) \u003c 0`.\n\n**Steps**:\n1. Check that `f(a) * f(b) \u003c 0`, ensuring a root exists within `[a, b]`.\n2. Calculate midpoint `x = (a + b) / 2`.\n3. If `f(x) == 0` or `(x - old_x) \u003c= tolerance`, `x` is the root.\n4. If `f(a) * f(x) \u003c 0`, set `b = x`; otherwise, set `a = x`.\n5. Repeat until convergence.\n\n**Features**:\n- Ensures convergence for continuous functions with opposite signs at `a` and `b`.\n- Includes tolerance-based convergence.\n\n---\n\n### 2. False Position (Regula Falsi) Method\nThe False Position method also finds roots in a bracketing interval but uses a linear approximation for faster convergence.\n\n**Steps**:\n1. Ensure `f(a) * f(b) \u003c 0` for the initial interval.\n2. Calculate `x` as: `x = (a * f(b) - b * f(a)) / (f(b) - f(a))`\n3. If `f(x) == 0` or `(x - old_x) \u003c= tolerance`, `x` is the root.\n4. Update interval: if `f(a) * f(x) \u003c 0`, set `b = x`; otherwise, set `a = x`.\n5. Repeat until convergence.\n\n**Features**:\n- Faster than Bisection for some functions, but convergence depends on the function’s shape.\n\n---\n\n### 3. Newton-Raphson Method\nNewton-Raphson is an open method that approximates roots using derivatives. It requires an initial guess and differentiable function.\n\n**Steps**:\n1. Initialize with an initial guess `x`.\n2. For each iteration, update `x` as: `x_new = x - f(x) / f'(x)`\n3. If `f(x_new) \u003c tolerance`, `x_new` is the root.\n4. If derivative `f'(x) == 0`, it indicates a division by zero, stopping the process.\n5. Repeat until convergence or maximum iterations are reached.\n\n**Features**:\n- Rapid convergence if the initial guess is close to the root.\n- Includes a synthetic division to deflate the polynomial after each root is found.\n\n---\n\n### 4. Secant Method\nThe Secant Method approximates the derivative with finite differences, needing two initial points `x0` and `x1`.\n\n**Steps**:\n1. Given initial guesses `x0` and `x1`, calculate `x` as: `x = x1 - f(x1) * (x1 - x0) / (f(x1) - f(x0))`\n2. If `f(x) \u003c= tolerance`, `x` is the root.\n3. Update `x0 = x1` and `x1 = x` for the next iteration.\n4. Repeat until convergence or maximum iterations.\n\n**Features**:\n- Faster than Newton-Raphson for some functions since it avoids computing the derivative explicitly.\n- Synthetic division is used to deflate polynomial equations after finding each root.\n\n---\n\n\n# Working Principle of Differential Equation Solver (Runge-Kutta Method)\n\nThe application solves differential equations using the Runge-Kutta method, a widely used technique for its balance between accuracy and computational efficiency.\n\n## Step-by-Step Process\n\n### 1. **Function Selection**\n   - The user is presented with a menu to choose a mathematical function type to define the differential equation, such as:\n     - Polynomial\n     - Trigonometric functions (sine, cosine, tangent)\n     - Logarithmic function\n     - Custom functions of `x` and `y`, including terms like `x^2`, `xy`, and `y^2`\n   - Based on the user’s choice, the program prompts for coefficients or parameters required to define the chosen function.\n   - Once the parameters are input, the application formulates the equation and displays it to the user.\n\n### 2. **Initial Conditions and Step Size Setup**\n   - The user provides:\n     - The initial values of `x` and `y` (denoted as `x0` and `y0`).\n     - A non-zero step size `h` that controls the increments for the `x` values.\n     - The `range` for which the solution is computed, marking the endpoint of the calculation.\n\n### 3. **Runge-Kutta Calculation**\n   - The application uses the Runge-Kutta method (fourth-order) to solve the differential equation iteratively from `x0` to the specified range.\n   - **Intermediate Calculations**:\n     - At each step, the method computes four intermediate slopes:\n       - `k1 = h * f(x, y)`\n       - `k2 = h * f(x + h/2, y + k1/2)`\n       - `k3 = h * f(x + h/2, y + k2/2)`\n       - `k4 = h * f(x + h, y + k3)`\n     - These slopes represent estimates of the derivative at different points within the current interval.\n   - **Updating the Solution**:\n     - The next value of `y` is calculated by averaging these slopes:\n       - `y_next = y + (k1 + 2 * k2 + 2 * k3 + k4) / 6`\n     - The `x` value is incremented by `h` to proceed to the next step.\n\n### 4. **Result Display**\n   - At each iteration, the new values of `x` and `y` are printed in a table format for easy tracking of the solution progression.\n\n### 5. **Completion**\n   - The process repeats until the solution reaches the specified range, providing a step-by-step solution for the differential equation using the selected function and initial values.\n\nThis structured approach ensures that the solution is computed accurately over the desired interval.\n# Working Principle of Matrix Inversion (Gauss-Jordan Method)\n\nThis application calculates the inverse of a square matrix using the Gauss-Jordan method. The process includes checking if the matrix is invertible before attempting inversion.\n\n## Step-by-Step Process\n\n### 1. **Invertibility Check**\n   - Before inverting, the function checks if the matrix is invertible by attempting to calculate its determinant.\n   - Steps:\n     - For each pivot position, the function ensures a non-zero value by swapping rows if needed. If no non-zero pivot is found in a column, the matrix is deemed singular (non-invertible), and the function returns `false`.\n     - If a pivot exists, the function reduces the matrix to an upper triangular form, calculating the determinant in the process.\n     - If the determinant is non-zero, the matrix is invertible.\n\n### 2. **Initial Setup for Inversion**\n   - If the matrix is confirmed to be invertible, an identity matrix of the same size is created. This identity matrix will be transformed into the inverse of `A` as the matrix is reduced.\n   - The matrix `A` is augmented with this identity matrix, forming an augmented matrix `[A | I]`.\n\n### 3. **Row Operations to Create Pivots**\n   - For each row `i`, the algorithm identifies the pivot element and normalizes it:\n     - **Pivot Normalization**:\n       - Divide the entire row by the pivot element so that the pivot becomes 1. This operation is applied to both `A` and `inv` (initially the identity matrix).\n     - **Zeroing Elements Above and Below the Pivot**:\n       - For all rows except the pivot row `i`, adjust each element in the column to zero by subtracting a multiple of the pivot row.\n       - This step ensures that all elements above and below each pivot are zero, moving the matrix closer to reduced row echelon form.\n\n### 4. **Iterate Over Each Row**\n   - Repeat the row operations for each row in `A`, moving down the diagonal until the entire left side of the augmented matrix becomes the identity matrix.\n   - As `A` transforms into the identity matrix, `inv` transforms into the inverse of `A`.\n\n### 5. **Return the Inverse Matrix**\n   - Once the left half of the augmented matrix is reduced to the identity matrix, the right half contains the inverse of the original matrix `A`.\n   - The `invert` function returns this inverse matrix.\n\n### 6. **Failure Case Handling**\n   - If the matrix is not invertible (as detected by `isInvertible`), the application can return an error message indicating the matrix is singular.\n\nThis structured approach ensures that only invertible matrices are processed, and the result is computed accurately using Gauss-Jordan elimination.\n\n## Contributors (Team No 18)\n- Ayesha Mehereen - 2107039  [@Mehereen-1](https://github.com/Mehereen-1)\n- Shormi Ghosh - 21070109 [@ShormiGhosh](https://github.com/ShormiGhosh)\n- Md. Nayeem - 2107050 [@codernayeem](https://github.com/codernayeem)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodernayeem%2Fnumericalproject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodernayeem%2Fnumericalproject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodernayeem%2Fnumericalproject/lists"}