Files
numethods/README.md
2025-09-17 11:29:23 +03:00

130 lines
4.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# numethods
A lightweight, from-scratch, object-oriented Python package implementing classic numerical methods.
**No NumPy / SciPy solvers used**, algorithms are implemented transparently for learning and research.
## Why this might be useful
- Great for teaching/learning numerical methods step by step.
- Good reference for people writing their own solvers in C/Fortran/Julia.
- Lightweight, no dependencies.
- Consistent object-oriented API (.solve() etc).
---
## Tutorial Series
This package comes with a set of Jupyter notebooks designed as a structured tutorial series in **numerical methods**, both mathematically rigorous and hands-on with code.
### Core Tutorials
1. [Tutorial 1: Vectors and Matrices](tutorials/tutorial1_vectors.ipynb)
- Definitions of vectors and matrices.
- Vector operations: addition, scalar multiplication, dot product, norms.
- Matrix operations: addition, multiplication, transpose, inverse.
- Matrix and vector norms.
- Examples with `numethods.linalg`.
2. [Tutorial 2: Linear Systems of Equations](tutorials/tutorial2_linear_systems.ipynb)
- Gaussian elimination and GaussJordan.
- LU decomposition.
- Cholesky decomposition.
- Iterative methods: Jacobi and Gauss-Seidel.
- Examples with `numethods.solvers`.
3. [Tutorial 3: Orthogonalization and QR Factorization](tutorials/tutorial3_orthogonalization.ipynb)
- Inner products and orthogonality.
- GramSchmidt process (classical and modified).
- Householder reflections.
- QR decomposition and applications.
- Examples with `numethods.orthogonal`.
4. [Tutorial 4: Root-Finding Methods](tutorials/tutorial4_root_finding.ipynb)
- Bisection method.
- Fixed-point iteration.
- Newtons method.
- Secant method.
- Convergence analysis and error behavior.
- Trace outputs for iteration history.
- Examples with `numethods.roots`.
- [Polynomial Regression Demo](tutorials/polynomial_regression.ipynb)
- Step-by-step example of polynomial regression.
- Shows how to fit polynomials of different degrees to data.
- Visualizes fitted curves against the original data.
---
## Features
### Linear system solvers
- **LU decomposition** (with partial pivoting): `LUDecomposition`
- **Gauss-Jordan** elimination: `GaussJordan`
- **Jacobi** iterative method: `Jacobi`
- **Gauss-Seidel** iterative method: `GaussSeidel`
- **Cholesky** factorization (SPD): `Cholesky`
### Root-finding
- **Bisection**: `Bisection`
- **Fixed-Point Iteration**: `FixedPoint`
- **Secant**: `Secant`
- **Newton's method** (for roots): `NewtonRoot`
### Interpolation
- **Newton** (divided differences): `NewtonInterpolation`
- **Lagrange** polynomials: `LagrangeInterpolation`
### Orthogonalization, QR, and Least Squares
- **Classical Gram-Schmidt**: `QRGramSchmidt`
- **Modified Gram-Schmidt**: `QRModifiedGramSchmidt`
- **Householder QR** (numerically stable): `QRHouseholder`
- **QR-based linear solver** (square systems): `QRSolver`
- **Least Squares** for overdetermined systems (via QR): `LeastSquaresSolver`
### Numerical Differentiation
- **Forward difference**: `ForwardDiff`
- **Backward difference**: `BackwardDiff`
- **Central difference (2nd order)**: `CentralDiff`
- **Central difference (4th order)**: `CentralDiff4th`
- **Second derivative**: `SecondDerivative`
- **Richardson extrapolation**: `RichardsonExtrap`
### Matrix & Vector utilities
- Minimal `Matrix` / `Vector` classes
- `@` operator for **matrix multiplication**
- `*` for **scalar**-matrix multiplication
- `.T` for transpose
- Forward / backward substitution helpers
- Norms, dot products, row/column access
---
## Install (editable)
```bash
pip install -e /numethods
```
or just add `/numethods` to `PYTHONPATH`.
## Examples
```bash
python /numethods/examples/demo.py
```
## Notes
- All algorithms are implemented without relying on external linear algebra solvers.
- Uses plain Python floats and list-of-lists for matrices/vectors.
- Tolerances use a relative criterion `|Δ| ≤ tol (1 + |value|)`.