No License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
erfi function

3.4 | 5 ratings Rate this file 6 Downloads (last 30 days) File Size: 840 Bytes File ID: #18238 Version: 1.0
image thumbnail

erfi function


Per Sundqvist (view profile)


06 Jan 2008 (Updated )

Imaginary error function (could be complex) using matlab's incomplete gamma function gammainc

| Watch this File

File Information

Imaginary error function, as it is defined in Mathematica erfi(z)==erf(iz)/i (z could be complex) using the incomplete gamma function in matlab: gammainc

MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (11)
16 May 2016 Janos

Janos (view profile)

Comment on Steven G. Johnson's code:

Comment only
16 May 2016 Janos

Janos (view profile)

This is a fantastic implementation. This code works about 2000x faster for me (when tested with large multidimensional arrays) than the built-in Matlab erfi function.

25 Jun 2013 Javier Del Águila

Thank you so much

Comment only
13 Mar 2013 Chris

Chris (view profile)

Thanx man.
You saved my life!

29 Oct 2012 Steven G. Johnson

Note that an alternate way of computing erfi, which works for complex z, is to use the Faddeeva function (, via erfi = @(z) -i * (exp(z.^2) .* Faddeeva_w(z) - 1) ... this seems to avoid the below-mentioned problems for large arguments, and is faster.

Comment only
21 Jun 2011 Mohamed Yassin OUKILA

what is erfz2?

Comment only
19 May 2011 Marcelo Pisani

Function gives wrong results for high moduli input. For instance, using Maple ERF converted to DOUBLE (erfz2 function below):

>> z=3+2i; erfz2(z*i)/i, erfi(z)
ans =
8.6873 -20.8295i
ans =
8.6873 -20.8295i

>> z=7+7i; erfz2(z*i)/i, erfi(z)
ans =
-0.0561 + 1.0102i
ans =
7.3774e+024 +1.6269e+025i

01 Nov 2010 PLH

PLH (view profile)

The program does not work as stated. When using complex z (i.e., not pure real, or pure imaginary), I get the following error:

Error using ==> gammainc
Inputs must be real, full, and double or single.

Error in ==> erfi at 19

This also occurs for Example 2 provided with the code. I'm assuming it's a trivial problem since the figure above seems to correspond to what I would expect (look at the erfi article on Mathworld ). In case it's relevant, I'm using Matlab (R2010a) (64-bit).

Comment only
01 Nov 2010 PLH

PLH (view profile)

06 Jul 2010 kinor

kinor (view profile)

Hi Ian,

thank your for the hint

and you of course for sharing the function Per!



Comment only
02 Jun 2010 Ian

Ian (view profile)

-Good work with this function Per!!
-While preforming an optimisation using this function. A bug in MATLAB 7.10 (R2010a) was reported. The function enters an infinite loop when calling gamminc(x,a) with x<0 and abs(x)>>a. They are working to fix this in future releases.
kind regards,
Ian Gregory, Sydney.

Contact us