mathC is a set of subroutines, either in ANSI C or C++, for various mathematical problems. It is used by almost all our software, hence we found it convenient to create a separate download package for it instead of bundling it with all our software packages.

The subroutines in mathC are based on many mathematical textbooks and publications, on personal communications and hard experience. Some subroutines were taken from the literature as they are, some were signifcantly improved by us. Unless indicated otherwise in the top portions of the source files, we do not claim authorship.

Installation requirements

  • C version: an ANSI C compiler capable of handling dynamic libraries (GNU gcc and HP-UX cc are known to work)
  • C++ version: a C++ compiler capable of handling dynamic libraries and template function (GNU g++ is known to work)
  • the make command (a standard feature of UNIX and Linux)
  • the mathC source files


  1. Unpack the mathC archive:
      gzip -cd mathc.tar.gz | tar -xvf -
    This creates the directories math/C and math/C++.
  2. Make platform-specific changes for the C version:
      cd math/C
  3. Build the library:
  4. Repeat the last two steps for the C++ version.

Note: The recent configure script recognizes Linux and MacOS only. If you have a different operating system, you may have to modify the configure script. Please send us your configure script, and we will build your changes into the official distribution.

Contents (C++ version)

  • minimization, curve fitting
    • min_brent: local minimum of a 1-dimensional function, parabola minimum
    • fit_marquardt: modified Marquardt—Levenberg method
    • fit_powell: Powell's sequential minimization method
    • fit_simplex: simplex method of Nelder and Mead
    • min_scan1: absolute minimum of a 1-dimensional function
  • differentiation
    • diff_gradient: gradient of an n-dimensional function, Romberg's method
    • diff_hessian: Hessian of an n-dimensional function, Romberg's method
    • diff_ridders: derivative of an 1-dimensional function, Ridder's method
    • diff_romberg: derivative of an 1-dimensional function (also bounded!), Romberg's method
    • diff_x: derivative of an 1-dimensional function confined to [0; 1]
    • diff_2all: 2-dimensional function, all derivatives up to given order
  • precise differentiation using (multi-)complex arithmetics
    • diff_cauchy: n-th order differentiation using complex integration, Cauchy's formula
    • diff_lm: n-th order differentiation using complex integration, Lyness–Moler method
    • diff_st: 1st-order differentiation, step method of Squire and Trapp
    • diff_mcx: n-th order differentiation using multicomplex arithmetics
  • differential equations
    • ode_ck: 1st degree ordinary ODE, Cash–Karp method
    • ode_runge_kutta: 1st degree ordinary ODE, Runge–Kutta method
  • functions
    • f_bessel_sph: spherical Bessel function (= J_{l+1/2}(x))
    • f_dfac: factorial (as double precision)
    • f_ibinom_c: binomial coefficients (as integers)
    • f_legendre: Legendre polynomials (function values or coefficients)
  • integration
    • int_gauss: Gauss' method
    • int_romberg: Romberg's iterative method
    • int_simpson: Simpson's and Newton's rules
    • int_spline: integral over a cubic spline function
    • int_trapez: trapezoidal method
  • interpolation
    • ipl_akima: Akima polynomials
    • ipl_spline: natural cubic spline polynomials
    • ipl_eval: evaluation of Akima or spline polynomials
    • ipl_pspline: periodic cubic spline polynomials
    • ipl_peval: evaluation of periodic cubic spline polynomials
    • ipl_lagrange: calculation of Lagrange polynomials
    • ipl_reinsch: smoothing natural cubic spline polynomials
    • ipl_track: polynomial intra/extrapolation of tables
  • linear algebra
    • lin_gauss: systems of linear equations, Gauss elimination
    • lin_jacobi: eigenvalues and eigenvectors of symmetric matrices, Jacobi algorithm
    • lin_matinv: matrix inversion, Gauss—Jordan algorithm
    • lin_rayleigh: nearest eigenvalue and associated eigenvector of symmetric matrices, Rayleigh quotient algorithm
  • multicomplex arithmetics
  • nonlinear equations
    • eqn_quadratic: linear or quadratic equation
    • eqn_cubic: cubic equation (faster than Cardano's algorithm!)
      description [U. K. Deiters and R. Macías-Salinas, Ind. Eng. Chem. Res. 53 (2014) 2529–2536]
    • eqn_quartic: quartic polynomial equation
    • eqn_quintic: 5th order polynomial equation
    • eqn_polynomial: polynomial equation of arbitrary order
    • eqn_regulafalsi: nonlinear equation by regula falsi, Illinois method
    • eqn_steffensen: nonlinear equation, Steffensen's substitution method
  • random numbers
    • ran_cgr48: improved random number generator doing 48-bit randomization (portable version, requires 64-bit integers)
    • ran_seed: initialization of a random number generator
    • ran_shuffle: similar to ran_cgr48, invokes drand48(3C)
    • ran_stauffer: random number generator of D. Stauffer (famous theoretical physicist from Cologne)
    • ran_ecuyer: random number generator of P. l'Ecuyer (with shuffling)
    • ran_vector: unit vector with random orientation
  • vector/matrix algebra
    • numerous operations implemented as member functions of our own Vector and Matrix template classes
  • other
    • sort_index: sort elements of a vector, merge sort method

Some of these subroutines are not available in the C version, and some are there under a different name.