C++ source code for compiled plugins (MEX files) to compute various error functions for complex arguments:
** Faddeeva_erf(z)  the error function
** Faddeeva_erfc(z) = 1  erf(z)  complementary error function
** Faddeeva_erfi(z) = i erf(iz)  imaginary error function
** Faddeeva_erfcx(z) = exp(z^2) erfc(z)  scaled complementary error function
** Faddeeva_w(z) = exp(z^2) erfc(iz)  Faddeeva function
** Faddeeva_Dawson(z) = 0.5 sqrt(pi) exp(z^2) erfi(z)  Dawson function
From e.g. the Faddeeva function, one can also obtain the Voigt functions and other related functions.
Assuming you have a C++ compiler (and have configured it in MATLAB with mex setup), compile by running the included Faddeeva_build.m script in MATLAB:
Faddeeva_build
All of the functions have usage of the form:
w = Faddeeva_w(z)
or optionally Faddeeva_w(z, relerr), where relerr is a desired relative error (default: machine precision). z may be an array or matrix of complex or real numbers.
This code may also be downloaded from
http://abinitio.mit.edu/Faddeeva
along with documentation and other versions. As described in the source code, this implementation uses a combination of algorithms for the Faddeeva function: a continuedfraction expansion for large z [similar to G. P. M. Poppe and C. M. J. Wijers, "More efficient computation of the complex error function," ACM Trans. Math. Soft. 16 (1), pp. 38–46 (1990)], and a completely different algorithm for smaller z [Mofreh R. Zaghloul and Ahmed N. Ali, "Algorithm 916: Computing the Faddeyeva and Voigt Functions," ACM Trans. Math. Soft. 38 (2), 15 (2011).]. Given the Faddeeva function, we can then compute the other error functions, although we must switch to Taylor expansions and use other tricks in certain regions of the complex plane to avoid cancellation errors or other floatingpoint problems.
