The pracma Package


This package provides R implementations of more advanced functions in numerical analysis, with a special view on on optimization and time series routines. Uses Matlab/Octave function names where appropriate to simplify porting.

Some of these implementations are the result of courses on Scientific Computing (“Wissenschaftliches Rechnen”) and are mostly intended to demonstrate how to implement certain algorithms in R/S. Others are implementations of algorithms found in textbooks.


The package encompasses functions from all areas of numerical analysis, for example:

Root finding and minimization of univariate functions,
e.g. Newton-Raphson, Brent-Dekker, Fibonacci or `golden ratio’ search.

Handling polynomials,
including roots and polynomial fitting, e.g. Laguerre’s and Muller’s methods.

Interpolation and function approximation,
barycentric Lagrange interpolation, Pade and rational interpolation, Chebyshev or trigonometric approximation.

Some special functions,
e.g. Fresnel integrals, Riemann’s Zeta or the complex Gamma function, and Lambert’s W computed iteratively through Newton’s method.

Special matrices, e.g. Hankel, Rosser, Wilkinson

Numerical differentiation and integration,
Richardson approach and “complex step” derivatives, adaptive Simpson and Lobatto integration and adaptive Gauss-Kronrod quadrature.

Solvers for ordinary differential equations and systems,
classical Runge-Kutta, ODE23, or Adams-Bashford-Moulton method.

Some functions from number theory,
such as primes and prime factorization, continuous fractions, the extended Euclidean algorithm, primitive roots, etc.

Sorting routines, e.g. recursive quickstep.

Several functions for string manipulation and regular search,
all wrapped and named similar to their Matlab analogues.


It serves two main goals:

Collecting R scripts that can be demonstrated in courses on Numerical Analysis or Scientific Computing, using R/S as the chosen programming language.

Wrapping functions with appropriate Matlab names to simplify porting programs from Matlab or Octave to R.

Besides that, many of these functions could be called in R applications as they do not have comparable counterparts in R packages (at least at this moment).


All referenced books have been utilized in one way or another. Web links have been provided where reasonable.

Abramowitz, M., and I. A. Stegun (1972). Handbook of Mathematical Functions (with Formulas, Graphs, and Mathematical Tables). Dover, New York. \url{}.

Arndt, J. (2010). Matters Computational: Ideas, Algorithms, Source Code. Springer-Verlag, Berlin Heidelberg Dordrecht. FXT: a library of algorithms: \url{}.

Cormen, Th. H., Ch. E. Leiserson, and R. L. Rivest (2009). Introduction to Algorithms. Third Edition, The MIT Press, Cambridge, MA.

Gautschi, W. (1997). Numerical Analysis: An Introduction. Birkhaeuser, Boston.

Gentle, J. E. (2009). Computational Statistics. Springer Science+Business Media LCC, New York.

Hazewinkel, M., Editor (2002). Encyclopaedia of Mathematics. Springer-Verlag, Berlin Heidelberg New York. \url{}. (2011). Matlab Central: \url{}. \url{}.

NIST: National Institute of Standards and Technology. Olver, F. W. J., et al. (2010). NIST Handbook of Mathematical Functions. Cambridge University Press. Internet: NIST Digital Library of Mathematical Functions, \url{}; Dictionary of Algorithms and Data Structures, \url{}; Guide to Available Mathematical Software, \url{}

Press, W. H., S. A. Teukolsky, W. T Vetterling, and B. P. Flannery (2007). Numerical Recipes: The Art of Numerical Computing. Third Edition, incl. Numerical Recipes Software, Cambridge University Press, New York. \url{} [chapters], or \url{} [pages].

Quarteroni, A., R. Sacco, and F. Saleri (2007). Numerical Mathematics. Second Edition, Springer-Verlag, Berlin Heidelberg.

Skiena, St. S. (2008). The Algorithm Design Manual. Second Edition, Springer-Verlag, London. The Stony Brook Algorithm Repository: \url{}.

Stoer, J., and R. Bulirsch (2002). Introduction to Numerical Analysis. Third Edition, Springer-Verlag, New York.

Strang, G. (2007). Computational Science and Engineering. Wellesley-Cambridge Press. Matlab Codes: \url{}

Weisstein, E. W. (2003). CRC Concise Encyclopedia of Mathematics. Second Edition, Chapman & Hall/CRC Press. Wolfram MathWorld: \url{}.

Zhang, S., and J. Jin (1996). Computation of Special Functions. John Wiley & Sons. \url{} }