A collection of fundamental numerical analysis algorithms implemented in C and C++, organized by topic. Each module is self-contained and built around a shared arithmetic utility layer.
numeric_methods/
├── ArchivosComunes/ # Shared utilities (arithmetic, linear algebra, matrix I/O)
├── AritmeticaFinita/ # Finite arithmetic and precision experiments
├── CalculoDeCeros/ # Root-finding methods
├── CondicionamientoMatriz/ # Matrix conditioning
├── FactorizacionCholesky/ # Cholesky factorization
├── Integrales/ # Numerical integration
├── Interpolacion/ # Polynomial interpolation and splines
└── Mascaras/ # 2D convolution masks
Core building blocks used across all modules.
mn_aritmeticas— Machine epsilon detection, smallest/largest representable positive numbers, and a relative distance function for floating-point comparison.mn_lapack— Dense linear algebra: Gaussian elimination with partial pivoting (mn_gauss), matrix inversion (mn_inversa), system error calculation, and matrix/vector file I/O. Also includes a set of macros for common matrix-vector operations (products, transposes, norms, copies).mn_jacobi— Jacobi eigenvalue algorithm for symmetric matrices. Returns eigenvalues and eigenvectors, with error metrics for validation.mn_raices_polinomios— Polynomial evaluation (direct and Horner's method) and Newton-Raphson root-finding for polynomials.
All modules use double via the real typedef and rely on the TNT (Template Numerical Toolkit)Array1D/Array2D types.
Experiments illustrating the limits of floating-point representation.
| File | Description |
|---|---|
calculo_del_numero_e.cpp | Computes e by summing the Taylor series until convergence stalls |
calculo_del_numero_pi.cpp | Computes π via the Leibniz formula |
calculo_del_numero_pi_metodo_montecarlo.cpp | Estimates π using Monte Carlo sampling (1,000,000 trials) |
Several methods for computing zeros of scalar functions and polynomials.
| Method | Files | Notes |
|---|---|---|
| Bisection | biseccion/biseccion.cpp | Bracketing method; guaranteed convergence when sign change exists |
| Newton-Raphson | newton_raphson/main.cpp | Quadratic convergence; uses Horner's method for polynomial derivatives |
| Regula Falsi | regula_falsi/regula_falsi.cpp | False-position bracketing method |
| SOR Relaxation | Relajacion/mn_relajacion.c | SOR (Successive Over-Relaxation) for linear systems Au = b |
| Halley / 2nd-order NR | calculo_raiz.cpp | Uses the quadratic Taylor approximation at each step |
Test functions used throughout: f(x) = x - tan(x) + 1 and f(x) = x - sin(x) - 1.
Computes the condition number κ₂(A) of a matrix using its largest and smallest singular values (via Jacobi eigendecomposition). Demonstrates sensitivity of linear systems to perturbations.
Cholesky Factorization (FactorizacionCholesky/)
Factorizes a symmetric positive-definite matrix A into LLᵀ. Provides:
mn_cholesky_factorization— returns the lower-triangular factor Lmn_descenso/mn_remonte— forward and back substitutionmn_cholesky— full solver: factorize then solvemn_determinante_factorizacion_cholesky— determinant from the diagonal of L
Adaptive Simpson's rule (mn_simpson):
- Fixed-N version: integrates with a user-specified number of subintervals.
- Adaptive version: doubles N until the relative change between successive estimates falls below a given tolerance.
| Method | Files | Description |
|---|---|---|
| Newton's divided differences | metodoNewton/metodoNewton.c | Builds and evaluates the Newton interpolating polynomial; supports optimal Chebyshev node placement |
| Quadratic splines | splines2grado/splines2grado.c | Constructs piecewise quadratic splines given nodes, values, and an initial derivative condition |
mn_mascara3x3 applies an arbitrary 3×3 convolution kernel to a 2D array, with explicit boundary handling for edges and corners (replicating border pixels). Useful for image filtering operations such as smoothing or edge detection.
Projects use Code::Blocks (.cbp files) with GCC. Each subdirectory contains its own project file. To build a module, open the corresponding .cbp file and build the default target.
Dependencies:
- GCC with C99/C++11 support
- TNT array library (headers included under
tnt_array/) - Standard C math library (
-lm)
- The
realtype is defined asdoublethroughout. Changing it tofloatinmn_aritmeticas.hwill affect precision across all modules. - File I/O for matrices and vectors uses a simple plain-text format: first line is dimensions, followed by values row by row. See
datos/generacion_datos.cfor examples of how test data is generated.