The numerical libraries numxlib.py and numxlib.h

The partial numerical libraries developed along the chapters compose the general libraries numxlib.py and numxlib.h. The corresponding Python and C/C++ routines have identical names and functionalities. The only naming exception concerns the modules random1.py and random.h, and this is due to the existence of a standard Python module named random.py.

numxlib.h also includes memalloc.h, containing dynamic memory allocation routines for vectors and matrices in C/C+.

numxlib.py Library of numerical methods for Python.
numxlib.h Library of numerical methods for C/C++.

Component modules

sort.py
sort.h
Contains routines for sorting, indexing, and ranking numeric sequences.
BubbleSort Sorts a numeric sequence using bubble sort.
InsertSort Sorts a numeric sequence by direct insertion.
QuickSort Sorts a numeric sequence using Quicksort.
Index Indexes a numeric sequence by direct insertion.
Rank Ranks a numeric sequence based on the array of indexes.
Index2 Performs the indexing of two correlated arrays by direct insertion.

specfunc.py
specfunc.h
Contains routines for evaluating special functions.
Chebyshev Evaluates Chebyshev polynomials of the first kind and their derivatives using the recurrence relation.
Legendre Evaluates Legendre polynomials and their derivatives using the recurrence relation.
aLegendre Evaluates associated Legendre functions.
Laguerre Evaluates Laguerre polynomials and their derivatives using the recurrence relation.
aLaguerre Evaluates associated Laguerre polynomials.
Hermite Evaluates Hermite polynomials and their derivatives using the recurrence relation.
SpherY Evaluates the real and imaginary parts of spherical harmonics.
SBessy Evaluates spherical Neumann functions.
SBessj Evaluates spherical Bessel functions.

roots.py
roots.h
Contains routines for determining real roots of real functions.
Bisect Determines a real root of a function by the bisection method.
FalsPos Determines a real root of a function by the false position method.
Iter Determines a real root of a function by the method of successive approximations.
Newton Determines a real root of a function by the Newton-Raphson method using the analytical derivative.
NewtonNumDrv Determines a real root of a function by the Newton-Raphson method using the numerical derivative.
Secant Determines a real root of a function by the secant method.
BirgeVieta Determines real roots of polynomials by the Birge-Vieta method.
Jacobian Calculates the Jacobian of a system of multidimensional functions using central finite differences.
NewtonSys Solves a system of nonlinear equations by Newton's method.

linsys.py
linsys.py
Contains routines for solving systems of linear equations.
Gauss Solves a matrix equation by Gaussian elimination with partial pivoting.
GaussJordan0 Solves a matrix equation by Gauss-Jordan elimination with partial pivoting.
GaussJordan1 Solves a matrix equation by Gauss-Jordan elimination with partial pivoting and matrix inversion.
GaussJordan Solves a matrix equation by Gauss-Jordan elimination with complete pivoting and matrix inversion.
LUFactor Performs LU factorization of a matrix by Doolittle's method.
LUSystem Solves a linear system using the LU decomposition of its matrix.
MatInv Performs matrix inversion using LU factorization.
MatTriInv Inverts a triangular matrix.
Cholesky Performs the Cholesky factorization of a symmetric positive-definite matrix.
CholeskySys Solves a positive-definite linear system using the Cholesky decomposition of its matrix.
MatSymInv Inverts a positive-definite matrix using the Cholesky factorization.
TriDiagSys Solves a linear system with tridiagonal matrix.
GaussSeidel Solves a system of linear equations by the Gauss-Seidel method.

eigsys.py
eigsys.h
Contains routines for solving eigenvalue problems.
Jacobi Solves an eigenvalue problem for a real symmetric matrix using the Jacobi method.
EigSym Solves a generalized eigenvalue problem for real symmetric (positive-definite) matrices.
EigSort Sorts a set of eigenvalues and eigenvectors according to the eigenvalues.

modfunc.py
modfunc.h
Contains routines for modeling tabular dependences by interpolation or regression.
Lagrange Evaluates the Lagrange interpolating polynomial for a set of data points.
Neville Evaluates the Lagrange interpolating polynomial by Neville's method.
Spline Performs cubic spline interpolation.
LinFit Performs linear regression on a set of data points.
MultiFit Performs multilinear regression on a set of data points.
PolFit Performs polynomial regression on a set of data points.
MarqFit Performs nonlinear regression based on the Levenberg-Marquardt method.

integral.py
integral.h
Contains 1D and 3D integrators for real functions with real variables.
qTrapz Function integrator based on the trapezoidal rule.
qSimpson Function integrator based on Simpson's rule.
qTrapzCtrl Adaptive integrator based on the trapezoidal rule.
qSimpsonCtrl Adaptive integrator based on Simpson's rule.
qRomberg Adaptive integrator based on Romberg's method.
qImprop1 Adaptive integrator for improper integrals of the first kind (with infinite limits).
qImprop2 Adaptive integrator for improper integrals of the second kind (with singular integrable limits).
qMidPoint Adaptive integrator based on the midpoint rule.
xGaussLeg Generates abscissas and weights for Gauss-Legendre quadratures.
qGaussLeg Gauss-Legendre integrator.
xGaussLag Generates abscissas and weights for Gauss-Laguerre quadratures.
qGaussLag Gauss-Laguerre integrator.
qTrapz3D 3D integrator based on the trapezoidal rule.
xSimpson Generates integration points and weights for Simpson's rule.
qSimpson3D 3D integrator based on Simpson's rule.
qGaussLeg3D 3D integrator based on Gaussian quadratures.
qSimpsonAng Integrator in spherical angular coordinates based on Simpson's rule.
qSimpsonSph Integrator in spherical coordinates based on Simpson's rule.
qGaussSph Integrator in spherical coordinates based on Gaussian quadratures.
qSimpsonCyl Integrator in cylindrical coordinates based on Simpson's rule.

random1.py
random.h
Contains routines for generating pseudorandom numbers.
randLCG1 Linear congruential random number generator based on specifications from Press et al. 2002.
randLCG2 Linear congruential random number generator based on specifications from Rapaport 2004.
randMCG Multiply-with-Carry random number generator based on specifications of George Marsaglia.
randNrm Generates random numbers with normal distribution based on the central limit theorem.
randNrm2 Returns two random numbers with normal distribution.
randMet Random number generator based on the Metropolis method.

ode.py
ode.h
Contains routines for solving systems of ordinary differential equations.
Euler Euler propagator for systems of first-order ODEs.
EulerPC Euler predictor-corrector propagator for systems of first-order ODEs.
RungeKutta Fourth-order Runge-Kutta solver for Cauchy problems for systems of first-order ODEs.
RKadapt Adaptive ODE solver using step-halving and the Runge-Kutta method.
RKFehlberg Adaptive ODE solver based on the Runge-Kutta-Fehlberg method.
Euler1 Euler propagator for a second-order ODE.
EulerCromer1 Euler-Cromer propagator for a second-order ODE.
Verlet1 Verlet propagator for a second-order ODE.
Euler2 Euler propagator for a system of second-order ODEs.
EulerCromer Euler-Cromer propagator for a system of second-order ODEs.
Verlet2 2D velocity Verlet propagator for a single particle.
Verlet Velocity Verlet propagator for a system of particles in interaction.
EulerCromerQM Euler-Cromer integrator for the 1D Schrödinger equation.
Numerov Numerov integrator for the 1D Schrödinger equation.
Propag Propagates the solution of a second-order ODE on a regular mesh using the Euler-Cromer method.
Shoot Solves a two-point boundary-value problem for a second-order ODE using the shooting method.
ShootQM Solves the 1D Schrödinger equation using the shooting method.
Bilocal Linear bilocal problem solver based on the finite-difference method.

pde.py
pde.h
Contains routines for solving partial differential equations.
Poisson0 Solver for the 2D Poisson equation in Cartesian coordinates with Dirichlet boundary conditions.
PoissonXY Solver for the 2D Poisson equation in Cartesian coordinates with arbitrary boundary conditions.
Poisson2D Solver for the 2D Poisson equation in Cartesian coordinates on an irregular domain.
PropagFTCS Explicit forward-time central-space propagator for the diffusion equation.
PropagBTCS Implicit backward-time central-space propagator for the diffusion equation.
PropagCN Crank-Nicolson propagator for the diffusion equation.
PropagDiff Crank-Nicolson propagator for the diffusion equation with variable diffusion coefficient.
PropagQTD Crank-Nicolson propagator for the Schrödinger equation based on tridiagonal solver.
PropagQGS Crank-Nicolson propagator for the Schrödinger equation using the Gauss-Seidel method.
PropagWave Explicit forward-time central-space propagator for the classical wave equation.

utils.py
utils.h
Contains utility routines.
Nint Returns the nearest integer to its real-type argument.
Sign Transfers the sign of its second argument onto the absolute value of the first argument.
Magn Returns the order of magnitude of its argument as a power of 10.
Index Indexes a numeric sequence by direct insertion

Auxiliary libraries

memalloc.h Contains functions for dynamic memory allocation of vectors and matrices in C/C++.
Vector
FreeVector
Allocate/deallocate a double vector with indices in the range [imin,imax].
Matrix
FreeMatrix
Allocate/deallocate a double matrix, with row and column indices in the range [imin,imax] x  [jmin,jmax].
IVector
FreeIVector
Allocate/deallocate an int vector with indices in the range [imin,imax].
IMatrix
FreeIMatrix
Allocate/deallocate an int matrix, with row and column indices in the range [imin,imax] x  [jmin,jmax].
CVector
FreeCVector
Allocate/deallocate a complex vector with indices in the range [imin,imax].
CMatrix
FreeCMatrix
Allocate/deallocate a complex matrix, with row and column indices in the range [imin,imax] x  [jmin,jmax].

coords.py
coords.h
Contains routines for transforming the coordinates of systems of particles.
MovetoCM Moves a system of n particles to the CM system.
PrincipalAxes Rotates a set of n particles to the system of principal axes.

elemfunc.py
elemfunc.h
Contains routines for evaluating elementary functions.
Poly Evaluates a real polynomial using Horner's scheme.
PolyDerive Returns the coefficients of the derivative of a real polynomial.
PolyDivide Returns the coefficients of the division of a real polynomial by a binomial (x-x0).

matutil.py
matutil.h
Contains utility routines for basic operations with vectors and matrices.
MatRead Reads from the keyboard the elements of matrix.
MatPrint Prints the elements of a matrix on the display.
MatPrintTrans Prints the elements of a transposed matrix on the display.
MatZero Zeros the elements of a matrix.
MatCopy Copies a matrix into another matrix.
MatTrans Replaces a square matrix by its transpose.
MatDiff Returns the difference of two matrices.
MatProd Returns the product of two matrices.
MatPow Returns a power of a square matrix.
MatNorm Returns the max norm of a matrix.
VecPrint Prints the elements of a vector on the display.
VecZero Zeros the elements of a vector.
VecCopy Copies a vector into another vector.
VecDiff Returns the difference of two vectors.
VecNorm Returns the 2-norm of a vector.
MatVecProd Returns the product of matrix and a vector.