Skip to content

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.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Python Jupyter NumPy Matplotlib SymPy

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 Monte Carlo 1.0 πŸ“„assignment.pdf Jupyter Notebook Python Code
02 Monte Carlo Numerical Integration of 𝒇(𝒙)=βˆšπ’™ Monte Carlo 2.0 πŸ“„assignment.pdf Jupyter Notebook Python Code
03 Fixed-Point Iteration Method implementation (General Iterative Method) with Consecutive Errors Plotting Fixed Point 1.0 πŸ“„assignment.pdf Jupyter Notebook Python Code
04 Fixed-Point Iteration Method implementation (General Iterative Method) with Functions Graph Plotting (Curves Intersection) Fixed Point 2.0 πŸ“„assignment.pdf Jupyter Notebook Python Code
05 Newton-Raphson (N-R) Method implementation for Solving Non-Linear Equations, with Consecutive Errors Plotting (both Linear and Logarithmic scale) Newton-Raphson πŸ“„assignment.pdf Jupyter Notebook Python Code
06 Secant Method implementation for Solving Non-Linear Equations, with Consecutive Errors Plotting (both Linear and Logarithmic scale) Secant Method πŸ“„assignment.pdf Jupyter Notebook Python Code
07 Bonus: Computational Cost Comparison experiment: Newton-Raphson Method vs. Secant Method for Solving Non-Linear Equations Cost Comparison πŸ“„assignment.pdf Jupyter Notebook Python Code
08 Cholesky Decomposition Example Cholesky πŸ“„assignment.pdf Jupyter Notebook Python Code

In-Depth Section Breakdown

πŸ“Œ 01 & 02: Monte Carlo Numerical Integration

  • 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$).
  • Tools & Libraries: numpy, matplotlib.pyplot, sympy
  • Files & Documentation:

πŸ“Š Output Visualizations

Exercise 1: Enclosed Area Between Parabolas ($n = 1000$, 10 Trials)

Monte Carlo Integration - Parabolas

Exercise 2: Area Under $f(x) = \sqrt{x}$ for Varying Sample Sizes ($n = 1000, 4000, 16000$)

Monte Carlo n=1000

Monte Carlo n=4000

Monte Carlo n=16000


πŸ“Œ 03 & 04: Fixed-Point Iteration (General Iterative Method) implementation

  • 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$).
  • Tools & Libraries: numpy, matplotlib.pyplot
  • Files & Documentation:

πŸ“Š Output Visualizations

Exercise 3: Error Convergence vs. Iterations

Fixed-Point Iteration Error Convergence

Exercise 4: Geometric Intersection $y = \cos(x)$ & $y = x$

Fixed-Point Iteration Curves Intersection


πŸ“Œ 05: Newton-Raphson (N-R) Method implementation

  • 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$).
  • Tools & Libraries: numpy, matplotlib.pyplot
  • Files & Documentation: Notebook, Script (.py), Documentation (PDF)

πŸ“Š Output Visualizations (Error Convergence for $x_0 = 1.4$)

Newton-Raphson Error - Linear Scale

Newton-Raphson Error - Log Scale


πŸ“Œ 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})}$$
    • Target Non-linear Equation: Solves $f(x) = x^4 + 2x^3 - 7x^2 + 3 = 0$.
    • 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$$
  • Tools & Libraries: numpy, matplotlib.pyplot
  • Files & Documentation: Notebook, Script (.py), Documentation (PDF)

πŸ“Š Output Visualizations (Error Convergence for $x_0 = 1.4, x_1 = 1.5$)

Secant Method Error - Linear Scale

Secant Method Error - Log Scale


πŸ“Œ 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$.
  • Tools & Libraries: numpy, matplotlib.pyplot, timeit
  • Files & Documentation: Notebook, Documentation (PDF)

Summary Table of Results

Metric Newton-Raphson (N-R) Secant Method
Initial Estimate(s) $x_0 = 1.4$ $x_0 = 1.4, x_1 = 1.5$
Computed Root ($x^*$) 1.6180 1.6180
Iterations to Converge 5 6
Function Evaluations ($f + f'$) 10 7
Theoretical FLOPs Cost $10k$ $7k$
Final Error ($e_{\text{last}}$) $5.1418 \times 10^{-5}$ (0.00005) $6.2415 \times 10^{-7}$ (0.0000006)
Execution Time (timeit) 20.83 $\mu\text{s}$ 18.84 $\mu\text{s}$

πŸ“Š Output Visualizations

Error vs. Iteration Count (Linear & Log Scale)

Error vs. Iterations - Linear Scale

Error vs. Iterations - Log Scale

Error vs. Total Function Evaluations / FLOPs Cost (Linear & Log Scale)

Error vs. Evaluations - Linear Scale

Error vs. Evaluations - 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.
  • Tools & Libraries: numpy, math.sqrt
  • Files & Documentation: Notebook, Script (.py), Documentation (PDF)

Numerical Results & Matrix Reconstruction

Matrix A (5x5 Lower Triangular, Full Rank):
[[1. 0. 0. 0. 0.]
 [1. 2. 0. 0. 0.]
 [1. 2. 3. 0. 0.]
 [1. 2. 3. 4. 0.]
 [1. 2. 3. 4. 5.]]

Symmetric Positive-Definite Matrix S = A^T * A:
[[ 5.  8.  9.  8.  5.]
 [ 8. 16. 18. 16. 10.]
 [ 9. 18. 27. 24. 15.]
 [ 8. 16. 24. 32. 20.]
 [ 5. 10. 15. 20. 25.]]

Computed Lower Triangular Factor L:
[[2.23606798 0.         0.         0.         0.        ]
 [3.57770876 1.78885438 0.         0.         0.        ]
 [4.02492236 2.01246118 2.59807621 0.         0.        ]
 [3.57770876 1.78885438 2.30940108 3.26598632 0.        ]
 [2.23606798 1.11803399 1.44337567 2.04124145 3.53553391]]

Verification Check: L * L^T (Matches S):
[[ 5.  8.  9.  8.  5.]
 [ 8. 16. 18. 16. 10.]
 [ 9. 18. 27. 24. 15.]
 [ 8. 16. 24. 32. 20.]
 [ 5. 10. 15. 20. 25.]]

Repository Structure

.
β”œβ”€β”€ 1. Monte Carlo integration method 1.0 (parabolas)/
β”‚   β”œβ”€β”€ assignment.pdf
β”‚   β”œβ”€β”€ graph.png
β”‚   β”œβ”€β”€ monte-carlo-integration-method.ipynb
β”‚   └── monte-carlo-integration-method.py
β”‚
β”œβ”€β”€ 2. Monte Carlo integration method 2.0 (mygraph)/
β”‚   β”œβ”€β”€ assignment.pdf
β”‚   β”œβ”€β”€ graph_1.png
β”‚   β”œβ”€β”€ graph_2.png
β”‚   β”œβ”€β”€ graph_3.png
β”‚   β”œβ”€β”€ monte-carlo-integration-2.0-mygraph.ipynb
β”‚   └── monte-carlo-integration-2.0-mygraph.py
β”‚
β”œβ”€β”€ 3. fixed point iteration method 1.0 (errors plot)/
β”‚   β”œβ”€β”€ assignment.pdf
β”‚   β”œβ”€β”€ graph.png
β”‚   β”œβ”€β”€ fixed-point-iteration-method.ipynb
β”‚   └── fixed-point-iteration-method.py
β”‚
β”œβ”€β”€ 4. fixed point iteration method 2.0 (functions plot)/
β”‚   β”œβ”€β”€ assignment.pdf
β”‚   β”œβ”€β”€ graph.png
β”‚   β”œβ”€β”€ fixed-point-iteration-method-2.0.ipynb
β”‚   └── fixed-point-iteration-method-2.0.py
β”‚
β”œβ”€β”€ 5. Newton-Raphson (N-R) method/
β”‚   β”œβ”€β”€ assignment.pdf
β”‚   β”œβ”€β”€ graph_1.png
β”‚   β”œβ”€β”€ graph_2.png
β”‚   β”œβ”€β”€ newton-raphson-method.ipynb
β”‚   └── newton-raphson-method.py
β”‚
β”œβ”€β”€ 6. Secant method/
β”‚   β”œβ”€β”€ assignment.pdf
β”‚   β”œβ”€β”€ graph_1.png
β”‚   β”œβ”€β”€ graph_2.png
β”‚   β”œβ”€β”€ secant-method.ipynb
β”‚   └── secant-method.py
β”‚
β”œβ”€β”€ 7. BONUS computational cost comparison (N-R vs secant)/
β”‚   β”œβ”€β”€ assignment.pdf
β”‚   β”œβ”€β”€ graph_1.png
β”‚   β”œβ”€β”€ graph_2.png
β”‚   β”œβ”€β”€ graph_3.png
β”‚   β”œβ”€β”€ graph_4.png
β”‚   └── computational-cost-comparison-NR-secant.ipynb
β”‚
β”œβ”€β”€ 8. Cholesky decomposition/
β”‚   β”œβ”€β”€ assignment.pdf
β”‚   β”œβ”€β”€ cholesky-decomp.ipynb
β”‚   └── cholesky-decomp.py
β”‚
└── README.md

πŸ‘€ Author

Athanasios Gourdomichalis - GitHub Profile


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.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages