{"id":27193684,"url":"https://github.com/abanoub-refaat/m352-numerical-analysis","last_synced_at":"2026-01-22T00:34:00.514Z","repository":{"id":281509774,"uuid":"945492843","full_name":"abanoub-refaat/M352-Numerical-Analysis","owner":"abanoub-refaat","description":"This repository contains Numerical Analysis implementations and solutions using Octave. It includes various numerical methods such as interpolation, differentiation, integration, and solving linear and nonlinear equations.","archived":false,"fork":false,"pushed_at":"2025-04-28T11:13:22.000Z","size":146,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-28T11:32:12.135Z","etag":null,"topics":["ml","numerical-analysis","octave","octave-scripts"],"latest_commit_sha":null,"homepage":"","language":"MATLAB","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/abanoub-refaat.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,"zenodo":null}},"created_at":"2025-03-09T14:57:37.000Z","updated_at":"2025-04-28T11:13:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"a83b2c8d-bcb8-461c-8950-f36b3d0ea340","html_url":"https://github.com/abanoub-refaat/M352-Numerical-Analysis","commit_stats":null,"previous_names":["abanoub-refaat/m352-numerical-analysis"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/abanoub-refaat/M352-Numerical-Analysis","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abanoub-refaat%2FM352-Numerical-Analysis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abanoub-refaat%2FM352-Numerical-Analysis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abanoub-refaat%2FM352-Numerical-Analysis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abanoub-refaat%2FM352-Numerical-Analysis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abanoub-refaat","download_url":"https://codeload.github.com/abanoub-refaat/M352-Numerical-Analysis/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abanoub-refaat%2FM352-Numerical-Analysis/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28648460,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T21:29:11.980Z","status":"ssl_error","status_checked_at":"2026-01-21T21:24:31.872Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["ml","numerical-analysis","octave","octave-scripts"],"created_at":"2025-04-09T18:57:47.509Z","updated_at":"2026-01-22T00:34:00.507Z","avatar_url":"https://github.com/abanoub-refaat.png","language":"MATLAB","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Math352: Numerical Analysis Course - LAB Content\n\nThis repository contains implementations of numerical methods using **Octave**. The goal is to apply and explore fundamental **Numerical Analysis** techniques to solve mathematical problems.\n\n\u003e [!IMPORTANT] \u003e[GNU Octave](https://www.gnu.org/software/octave/) (Recommended for running the scripts)\n\n## 🚀 Getting Started\n\n1. Clone the repository\n\n   ```bash\n   git clone https://github.com/abanoub-refaat/M352-Numerical-Analysis.git\n   cd M352-Numerical-Analysis\n   ```\n\n2. Open **Octave** and run any script:\n\n   ```octave\n   script_name.m\n   ```\n\n\u003e [!NOTE]\n\u003e replace script_name with the name of the actual script you want.\n\n## 📌 Forward Euler’s Method in Octave\n\nEuler’s method is a simple numerical approach for solving ODEs:\n\n\\[\ny\\_{i+1} = y_i + h f(x_i, y_i)\n\\]\n\nIt approximates the solution by using the slope at the current point.\n\n**Implementing Euler's Forward Method:**\n\n```octave\nfunction [x, y] = eulers_method(f, xinit, xend, yinit, h)\n    N = (xend - xinit) / h;\n    x = [xinit zeros(1, N)];\n    y = [yinit zeros(1, N)];\n\n    for i = 1 : N\n        x(i+1) = x(i) + h;\n        y(i+1) = y(i) + h * feval(f, x(i), y(i));\n    end\n\n    % Plot the solution\n    plot(x, y, 'b-s', 'LineWidth', 2);\n    xlabel('x');\n    ylabel('y');\n    title(\"Euler's Method Numerical Solution\");\n    grid on;\n    legend('Heun's Method', 'Euler's Method');\n    hold off;\n\n    % Save the plot\n    print -dpng eulers_method_plot.png;\nendfunction\n```\n\n---\n\n## 📌 Heun's Method in Octave\n\nHeun’s method is an improved **Euler's method**, using a **predictor-corrector** approach:\n\n\\[\ny*{i+1} = y_i + \\frac{h}{2} \\left[ f(x_i, y_i) + f(x*{i+1}, y\\_{\\text{new}}) \\right]\n\\]\n\nWhere:\n\n- \\( y\\_{\\text{new}} = y_i + h \\cdot f(x_i, y_i) \\) (Predictor step)\n- \\( y\\_{i+1} \\) is updated using the average slope (Corrector step).\n\n**Implementing Heun's Method:**\n\n```octave\nfunction [x, y] = heuns_method(f, xinit, xend, yinit, h)\n    N = (xend - xinit) / h;\n    x = [xinit zeros(1, N)];\n    y = [yinit zeros(1, N)];\n\n    for i = 1 : N\n        x(i+1) = x(i) + h;\n        % Predictor step\n        ynew = y(i) + h * feval(f, x(i), y(i));\n        % Corrector step\n        y(i+1) = y(i) + (h/2) * (feval(f, x(i), y(i)) + feval(f, x(i+1), ynew));\n    end\n\n    % Plot the solution\n    figure;\n    plot(x, y, 'r-o', 'LineWidth', 2);\n    xlabel('x');\n    ylabel('y');\n    title(\"Heun's Method Numerical Solution\");\n    grid on;\n    hold on;\n\n    % Save the plot\n    print -dpng heuns_method_plot.png;\nendfunction\n```\n\n---\n\n## 🛠️ How to Use\n\n1. **Define the function** you want to solve:\n\n   ```octave\n   f = @(x, y) x + y;  % Example: dy/dx = x + y\n   ```\n\n2. **Run Heun's Method:**\n\n   ```octave\n   [x_h, y_h] = heuns_method(f, 0, 2, 1, 0.2);\n   ```\n\n3. **Run Euler's Method:**\n\n   ```octave\n   [x_e, y_e] = eulers_method(f, 0, 2, 1, 0.2);\n   ```\n\n4. **Check the generated plots in `heuns_method_plot.png` and `eulers_method_plot.png`.** 📈\n\n---\n\n## 📊 Comparison of Heun’s and Euler’s Methods\n\n| Method             | Order of Accuracy | Stability   | Error Reduction   |\n| ------------------ | ----------------- | ----------- | ----------------- |\n| **Euler’s Method** | First-order       | Less stable | More error-prone  |\n| **Heun’s Method**  | Second-order      | More stable | Improved accuracy |\n\n- **Euler’s Method** is simpler but less accurate.\n- **Heun’s Method** reduces error by using an additional correction step.\n\n---\n\n### 📊 Graph Output\n\nThe numerical solutions will be plotted and saved as:\n\n![Heun's Method Plot](ODEs/imgs/heuns_method_plot.png)\n![Euler's Forward Method Plot](ODEs/imgs/forward-euler_method_plot.png)\n![Euler's Backward Method Plot](ODEs/imgs/backward_euler_method_plot.png)\n\n## Task2\n\n### 1.Runge-Kutta (RK4) Method\n\nThe classical fourth-order Runge-Kutta method is given by:\n\n\\[\ny\\_{n+1} = y_n + \\frac{h}{6} (k_1 + 2k_2 + 2k_3 + k_4)\n\\]\nwhere:\n\n- \\( k_1 = f(t_n, y_n) \\)\n- \\( k_2 = f(t_n + \\frac{h}{2}, y_n + \\frac{h}{2} k_1) \\)\n- \\( k_3 = f(t_n + \\frac{h}{2}, y_n + \\frac{h}{2} k_2) \\)\n- \\( k_4 = f(t_n + h, y_n + h k_3) \\)\n\n**Example Usage:**\n\n```octave\nf = @(t, y) -2*t*y; % Example: dy/dt = -2*t*y\n[t, y] = runge_kutta_4(f, 0, 1, 0.1, 10);\nplot(t, y, 'o-');\nxlabel('t'); ylabel('y');\ntitle('Runge-Kutta 4th Order');\n```\n\n![Rungge-Kutta 4th Order plot](ODEs/imgs/runge-kutta-4-method.png)\n\n---\n\n## 2. Multistep Methods (Adams-Bashforth)\n\nMultistep methods use multiple past points to compute the next point. The **Adams-Bashforth (two-step) method** is:\n\n\\[\ny*{n+1} = y_n + \\frac{h}{2} \\left(3f(t_n, y_n) - f(t*{n-1}, y\\_{n-1})\\right)\n\\]\n\nThis method requires an initial value, which we can compute using RK4.\n\n### **Implementation in Octave**\n\n```octave\n% Example Usage:\nf = @(t, y) -2*t*y; % Example: dy/dt = -2*t*y\n[t, y] = adams_bashforth_2(f, 0, 1, 0.1, 10);\nplot(t, y, 'o-');\nxlabel('t'); ylabel('y');\ntitle('Adams-Bashforth 2-Step');\n```\n\n![Adams-Bashforth Method Plot](ODEs/imgs/runge-kutta-4-method.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabanoub-refaat%2Fm352-numerical-analysis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabanoub-refaat%2Fm352-numerical-analysis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabanoub-refaat%2Fm352-numerical-analysis/lists"}