Is there a faster version of the matlab function erfi?

1 view (last 30 days)
I need to call the erfi function for each element in a 3D array in order to compute some anti-derivative. This causes a very slow run of my code. I'm looking for a fast implementation of the erfi function in order to shorten the run time of my code.

Answers (2)

Alan Weiss
Alan Weiss on 10 Jun 2015
Edited: Alan Weiss on 10 Jun 2015
I don't know of any way to speed erfi. You can call erfi on a 3-D array all at once (you don't have to loop through the individual elements), but you probably already knew that.
The only other thing I can suggest is to use approximate asymptotic values in case the elements in your array are real and large in magnitude. I think that an asymptotic expansion for large positive x looks like
erfi(x) = 1/(x*pi^(1/2)) exp(x^2)(1 + O(1/x^2))
I got this by integration by parts. But the absolute error value is quite large. Perhaps you can come up with appropriate approximations in your region of interest.
Here, I just tried it on an example:
1/(20*sqrt(pi))*exp(400)
ans =
1.4729e+172
erfi(20)
ans =
1.4748e+172
Alan Weiss
MATLAB mathematical toolbox documentation

Juan F. Osoiro
Juan F. Osoiro on 5 Dec 2019
Edited: Juan F. Osoiro on 5 Dec 2019
Same issue here. erfi from the symbolic toolbox is too slow. The function in python is orders of magnitud faster. https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.erfi.html

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!