You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Star1Β (1)You must be signed in to star a repository
About
A collection of computational and numerical analysis problems I have personally solved using Python, NumPy, SymPy and scientific visualizations (plots) with Matplotlib. Each project includes: comprehensive documentation (PDF document), an interactive Jupyter Notebook, a clean .py script, and exported plots.
A collection of computational and numerical analysis problems I have personally solved using Python, NumPy, SymPy and scientific visualizations (plots) with Matplotlib. Each project includes: comprehensive documentation (PDF document), an interactive Jupyter Notebook, a clean .py script, and exported plots.
Table of Contents
#
Topic / Project
Preview
Full Documentation
Notebook
Script
01
Monte Carlo Integration Between the Graphs of two Parabolas
Description: Stochastic approximation of definite integrals and geometric areas using uniform random sampling within a defined bounding domain $[0, 1] \times [0, 1]$.
Exercise 1 (Parabolas): Evaluates the area between two intersecting parabolic curves, $P_1(x) = x^2 - x + 1/2$ and $P_2(x) = -x^2 + x + 1/2$, averaged across 10 independent trials of $n = 1000$ points each (Estimate $\approx 0.3266$, Exact $= 1/3$).
Exercise 2 (function mygraph()): Integrates $f(x) = \sqrt{x}$ over $[0, 1]$ across multiple sample sizes ($n = 1000, 4000, 16000$) using a modular plotting function mygraph() to demonstrate convergence and error behavior (Exact $= 2/3 \approx 0.6667$).
Description: Numerical solution of non-linear equations by rearranging $f(x) = 0$ into the equivalent fixed-point form $x = g(x)$ and generating the iterative sequence $x_{k+1} = g(x_k)$. Both implementations verify convergence conditions under the Fixed-Point Theorem and numerically estimate the asymptotic convergence rate ($p \approx 1.0$) and error constant ($C$).
Exercise 3 (Errors Plot): Solves the cubic equation $f(x) = x^3 + x - 1 = 0$ using the rearrangement $g(x) = \sqrt[3]{1 - x}$ with $x_0 = 0$, tolerance $\text{tol} = 10^{-6}$, and max iterations $= 100$. Tracks and plots consecutive errors $e_k = \vert{}x_{k+1} - x_k\vert{}$ across iterations, verifying an asymptotic error constant $C \approx 0.7160$.
Exercise 4 (Functions Plot): Solves $f(x) = \cos(x) - x = 0$ via the rearrangement $g(x) = \cos(x)$ starting from $x_0 = 0$. Provides a comparative geometric visualization of $y = \cos(x)$ against the identity line $y = x$ on $[-5, 5]$ highlighting the unique real root $x^* \approx 0.739085$ ($C \approx 0.6736$).
Description: Iterative root-finding algorithm using tangent line linearization to compute real roots of the non-linear polynomial $f(x) = x^4 + 2x^3 - 7x^2 + 3 = 0$ with derivative $f'(x) = 4x^3 + 6x^2 - 14x$.
Automated Root Search: Iterates through starting points $x_0 = i \cdot 0.1$ (avoiding division-by-zero when $f'(x_0) = 0$) with tolerance $\text{tol} = 10^{-4}$ and $\text{maxit} = 15$ to isolate both distinct positive real roots: $x_1^* \approx 1.6180$ and $x_2^* \approx 0.7913$.
Convergence Analysis ($x_0 = 1.4$): Evaluates error progression towards $x^* \approx 1.6180$ in 5 iterations. The asymptotic error ratio $e_5 / e_4^2 \approx 1.8504$ closely matches the theoretical constant C = |f''(x*)| / (2|f'(x*)|) β 1.8416, verifying quadratic convergence ($p = 2$).
π Output Visualizations (Error Convergence for $x_0 = 1.4$)
π 06: Secant Method implementation
Description: Numerical root-finding algorithm that approximates the tangent slope using a secant line between the two most recent iterates, avoiding the need for an analytical derivative:
$$x_{n+1} = x_n - \frac{f(x_n)(x_n - x_{n-1})}{f(x_n) - f(x_{n-1})}$$
Automated Search for Positive Roots: Iterates through consecutive intervals $(x_0, x_1) = (i \cdot 0.1, (i + 1) \cdot 0.1)$ while bypassing division-by-zero intervals ($\text{tol} = 10^{-4}$, $\text{maxit} = 15$). Successfully locates both positive real roots: $x_1^* \approx 1.6180$ and $x_2^* \approx 0.7913$.
Convergence Analysis ($x_0 = 1.4, x_1 = 1.5$): Converges to $x^* \approx 1.6180$ in 6 iterations. The sequence of consecutive errors confirms the characteristic superlinear convergence order of the golden ratio ($p \approx 1.618$):
$$p = \frac{1 + \sqrt{5}}{2} \approx 1.618$$
π 07: Bonus Experiment : Computational Cost Comparison Between the Newton-Raphson method and the Secant method
Description: In-depth computational efficiency and cost benchmark between the Newton-Raphson method ($p = 2$, cost of $2k\text{ FLOPs/step}$) and the Secant method ($p \approx 1.618$, cost of $1k\text{ FLOPs/step}$) for finding the common positive root $x^* \approx 1.6180$ of $f(x) = x^4 + 2x^3 - 7x^2 + 3 = 0$ ($\text{tol} = 10^{-4}$, $\text{maxit} = 15$).
Theoretical Background: Because $2^2 = 4 \approx 4.23 = 1.618^3$, 3 iterations of the Secant method reduce the error as much as 2 iterations of Newton-Raphson. Evaluating the derivative cost equality yields $4k > 3k$, theoretically establishing that the Secant method requires less computational effort overall despite needing more steps.
Empirical Validation: Even though Newton-Raphson converges in fewer iterations (5 vs. 6), the Secant method achieves convergence with significantly fewer total function evaluations (7 vs. 10), resulting in lower measured CPU execution time ($18.84\ \mu\text{s} < 20.83\ \mu\text{s}$ over 20,000 runs) and confirming $7k < 10k$ and $3k < 4k$.
Error vs. Total Function Evaluations / FLOPs Cost (Linear & Log Scale)
π 08: Cholesky Matrix Decomposition Example
Description: Implementation of the direct, column-oriented Cholesky factorization method in numerical linear algebra. Any real, symmetric, and positive-definite (SPD) matrix $S$ is uniquely decomposed into the product of a lower triangular matrix $L$ (with strictly positive diagonal elements) and its transpose:
$$S = L \cdot L^T$$
Computational Advantages: Highly stable numerically for SPD matrices without requiring row or column pivoting (unlike Gaussian elimination or general LU decomposition). It requires approximately half the arithmetic operations ($\approx n^3/3\text{ FLOPs}$) of LU factorization ($2n^3/3\text{ FLOPs}$), running more than twice as fast in practice.
Algorithm Implementation: Implemented from scratch via a custom cholesky(a) function using NumPy arrays and native math functions (math.sqrt) without relying on black-box solvers like scipy.linalg.cholesky or np.linalg.cholesky. It updates column by column, eliminates previous column contributions, computes square-root pivots on the diagonal, scales subdiagonal elements, and isolates $L$ using np.tril().
Test Matrix Construction & Verification: Built an auxiliary $5 \times 5$ lower triangular matrix $A$ with full column rank to construct the guaranteed symmetric positive-definite matrix $S = A^T \cdot A$. The decomposition is verified by computing $L \cdot L^T$ (np.dot(L, L.T)), exactly reconstructing the original matrix $S$ within numerical precision.
A collection of computational and numerical analysis problems I have personally solved using Python, NumPy, SymPy and scientific visualizations (plots) with Matplotlib. Each project includes: comprehensive documentation (PDF document), an interactive Jupyter Notebook, a clean .py script, and exported plots.