(Difference between revisions)
 Revision as of 00:42, 5 October 2012 (edit)Stevenj (Talk | contribs) (initial page)← Previous diff Revision as of 00:44, 5 October 2012 (edit)Stevenj (Talk | contribs) (→Usage)Next diff → Line 15: Line 15: Passing relerr=0 (or any relerr less than machine precision ε≈10−16) corresponds to requesting [[w:Machine epsilon|machine precision]], and in practice a relative error < 10−12 is usually achieved. Specifying a larger value of relerr generally improves performance (at the expense of accuracy). Passing relerr=0 (or any relerr less than machine precision ε≈10−16) corresponds to requesting [[w:Machine epsilon|machine precision]], and in practice a relative error < 10−12 is usually achieved. Specifying a larger value of relerr generally improves performance (at the expense of accuracy). + + You should also compile Faddeeva_w.cc and link it with your program, of course. == Algorithm == == Algorithm ==

Contents

Steven G. Johnson has written a free/open-source C++ function to compute the scaled complex error function w(z) = ez2erfc(−iz), also called the Faddeeva function, for arbitary complex arguments z to a desired accuracy:

Usage

```#include <complex>
extern std::complex<double> Faddeeva_w(std::complex<double> z, double relerr);
```

The function `Faddeeva_w(z, relerr)` computes w(z) to a desired relative error `relerr`.

Passing `relerr=0` (or any `relerr` less than machine precision ε≈10−16) corresponds to requesting machine precision, and in practice a relative error < 10−12 is usually achieved. Specifying a larger value of `relerr` generally improves performance (at the expense of accuracy).

You should also compile `Faddeeva_w.cc` and link it with your program, of course.

Algorithm

We use the algorithm described in the paper:

Note that this is SGJ's independent re-implementation of this algorithm, based on the description in the paper only. In particular, I did not refer to (or even download) the author's Matlab implementation (which is under restrictive "semifree" ACM copyright terms and therefore unusable in free/open-source software).

This algorithm requires an external [[w:Error function|complementary error function] erfc(x) function for real arguments x to be supplied as a subroutine. More precisely, it requires the scaled function erfcx(x) = ex2erfc(x). Here, we include an erfcx function derived from the DERFC routine in SLATEC (modified by SGJ to compute erfcx instead of erfc), originally written by W. Fullerton at Los Alamos National Laboratory.