ShivamMathtech/Numerical-Analysis-Lab

A Python numerical-analysis textbook and computational laboratory, spanning floating-point foundations, scalar roots, matrix methods, approximation, calculus, ODEs, PDEs, eigenvalues, optimization and scientific applications. Manual implementations are paired with independent analytical or scientific-library checks.

★ 0Forks 0Jupyter NotebookGitHub ↗Compare

README

Numerical Analysis Lab

Learn the mathematics. Implement the method. Visualize the result. Measure the error.

Prepared for Shivam Singh · MathTech

A Python numerical-analysis textbook and computational laboratory, spanning floating-point foundations, scalar roots, matrix methods, approximation, calculus, ODEs, PDEs, eigenvalues, optimization and scientific applications. Manual implementations are paired with independent analytical or scientific-library checks. The examples are small, reproducible and suitable for learning, research preparation and classroom use.

What is included

  • 70 executed notebooks: the exact 63-notebook core syllabus plus seven advanced lessons.
  • Manual algorithms with input checks, iteration histories and explicit failure results.
  • Seven runnable projects: projectile motion, heat diffusion, circuits, population growth, orbits, Rosenbrock optimization and image processing.
  • A dedicated ML notebook covering least squares, gradient checking and PCA; an advanced sensitivity-ODE parameter-estimation lesson.
  • Saved plots, generated CSV datasets, five lightweight GIF animations and optional interactive controls.
  • Analytical, convergence, failure-case, physical-model and notebook validation tests.
  • All eight implementation phases completed; see phase evidence and the validation report.

This is an educational scientific-computing library, not a substitute for specialized production solvers. The implementation scope and limitations are stated in each notebook and in the API reference.

Quick start

Extract the ZIP and open a terminal in numerical-analysis-lab.

python -m venv .venv
# macOS/Linux:
source .venv/bin/activate
# Windows PowerShell instead:
# .venv\Scripts\Activate.ps1
python -m pip install -e ".[lab]"
python -m notebook

Open notebooks/01_foundations/01_number_systems.ipynb. Saved outputs can be read immediately; restart and run all cells to recompute them. The installation may download dependencies, but lessons and projects do not download data or call external APIs.

For a minimal algorithm-only environment, use python -m pip install -e .. requirements.txt provides the full lab dependency list. environment.yml provides a Conda alternative. Validated versions record the actual build environment; requirements-tested.txt pins direct dependencies to those versions without pretending to be a cross-platform transitive lock.

Run an algorithm

from numerical_analysis.root_finding import bisection

result = bisection(lambda x: x*x - 2, 0, 2, tol=1e-10)
print(result.value, result.residual, result.converged, result.reason)
from numerical_analysis.ode import solve_fixed

solution = solve_fixed(lambda t, y: -2*y, (0, 3), [1.0],
                       n_steps=120, method="rk4")
print(solution.t[-1], solution.y[-1])

Learning path

Module Notebooks Main methods
Foundations 6 Binary arithmetic, floating point, errors, sensitivity
Root finding 6 Bisection, regula falsi, fixed point, Newton, secant
Linear systems 7 Pivoted elimination, Gauss–Jordan, LU, Cholesky, Jacobi, Gauss–Seidel, SOR
Interpolation 6 Piecewise linear, Lagrange, Newton forward/backward/divided differences
Curve fitting 4 Householder QR, least squares, linear/polynomial models
Differentiation 4 Forward, backward and central stencils; step-size error study
Integration 6 Rectangles, trapezoid, Simpson 1/3 and 3/8, Gauss–Legendre
ODE 6 Euler, Heun, midpoint RK2, RK4, adaptive step doubling
PDE 4 Poisson stencils, FTCS heat, centered wave, SOR Laplace
Eigenvalues 4 Power, shifted inverse and symmetric shifted QR
Optimization 4 Golden section, damped Newton, Armijo gradient descent
Applications 6 Physical simulations and ML mathematics
Advanced 7 Conditioning, sparse PCG, stiffness, Fourier spectral derivative, linear FEM, Monte Carlo, scientific ML

See the complete clickable inventory and roadmap.

Visual gallery

Newton geometry

Heat space-time surface

Gradient descent

All images come from the included code. python tools/render_assets.py regenerates the gallery, six experiment CSVs and five animations. Static views work without widgets. Interactive controls become active when their cells are rerun in Jupyter; Plotly and HTML animations are opt-in.

Projects

python examples/projectile_motion.py
python examples/heat_diffusion.py
python examples/electrical_circuit.py
python examples/population_dynamics.py
python examples/orbit_simulation.py
python examples/numerical_optimization.py
python examples/image_processing.py

Each script accepts --output PATH, generates labeled figures and exports diagnostics or numerical data. Default outputs go under output/. See project descriptions.

Tests and reproducibility

python -m pytest -q
python tools/execute_notebooks.py --jobs 2
# Full Jupyter-kernel execution on a machine allowing local kernel sockets:
python tools/execute_notebooks.py --engine jupyter --jobs 2

The supplied execution report uses fresh IPython subprocesses, executing every code cell in order and capturing real output. The build sandbox did not permit Jupyter kernel sockets. Standard Jupyter notebook files are included, but browser interaction and live widget controls were not tested here. Notebook structure, calculations, saved PNGs, and widget-cell construction were checked. See the validation report for exact results.

Architecture

numerical-analysis-lab/
  src/numerical_analysis/    Numerical methods, experiments and plotting utilities
  notebooks/                63 core + 7 advanced executed notebooks
  tests/                    Numerical, application and artifact checks
  examples/                 Seven runnable project entry points
  docs/                     Theory notes, API reference, roadmap and validation
  datasets/                 Reproducible experiment CSVs
  assets/                   PNG gallery and optional GIF animations
  tools/                    Notebook authoring, execution and asset generation

Numerical modules are independent of plotting. laboratory.py and advanced_labs.py supply shared experiments; notebooks display both the manual algorithm source and the experiment source to keep the instructional code consistent with the tested implementation.

Contributing and references

Read CONTRIBUTING.md, coding standards, test strategy and references. Contributions and source are covered by the MIT license.

Contributors

ShivamMathtech

Issues