My Math Forum Computing the error function

 Applied Math Applied Math Forum

 February 28th, 2014, 09:54 AM #1 Senior Member     Joined: Dec 2013 From: some subspace Posts: 212 Thanks: 72 Math Focus: real analysis, vector analysis, numerical analysis, discrete mathematics Computing the error function My first question here... I was coding an application that involves the computation of error function $\mathrm{erf}(x)= \frac{2}{\sqrt{\pi}}\int_0^x e^{-t^2}dt \quad x \in (-2,-6).$ I'd need an accuracy (absolute error) of $10^{-13}$ at least, preferably $10^{-15}$. At this point, I've tried Maclaurin serie, asymptotic serie and trapetzoid rule of integration but there were problems in accuracy and convergence in this interval. Currently the best absolute error I can get, is $\le 1.2\cdot 10^{-9}$. Any ideas what kind of method to use next?
 February 28th, 2014, 10:04 AM #2 Global Moderator     Joined: Nov 2006 From: UTC -5 Posts: 16,046 Thanks: 938 Math Focus: Number theory, computational mathematics, combinatorics, FOM, symbolic logic, TCS, algorithms Re: Computing the error function Well, I suggest PARI/GP (see my .sig below): Code: > 1-erfc(.5) %1 = 0.5204998778130465376827466538919645287364515757579637000588057256471935 which takes about 70 microseconds to find the answer to 77 significant digits on my (older) machine.
 February 28th, 2014, 12:02 PM #3 Senior Member     Joined: Dec 2013 From: some subspace Posts: 212 Thanks: 72 Math Focus: real analysis, vector analysis, numerical analysis, discrete mathematics Re: Computing the error function Thank you, but well, I'd believe, that's not allowed since we have to code our own program and prosedures to do things. But the algorithm they are using sounds pretty interesting.
 February 28th, 2014, 01:50 PM #4 Global Moderator     Joined: Nov 2006 From: UTC -5 Posts: 16,046 Thanks: 938 Math Focus: Number theory, computational mathematics, combinatorics, FOM, symbolic logic, TCS, algorithms Re: Computing the error function Sorry, that wasn't clear to me. If you'd like, though, you can peek at their source code here: http://pari.math.u-bordeaux.fr/cgi-bin/ ... s3.c#l1122 Note that the function finds erfc(x), which is related to erf(x) by erf(x) = 1 - erfc(x).
 March 1st, 2014, 03:55 AM #5 Senior Member     Joined: Dec 2013 From: some subspace Posts: 212 Thanks: 72 Math Focus: real analysis, vector analysis, numerical analysis, discrete mathematics Re: Computing the error function No problem! Thank you for your help. I looked at the PARI/GP code a little bit, but then I just decided to make some kind of composition of different methods (Maclaurin serie, trapetzoid rule and asymptotic serie). The solution is not quite elegant, but anyway I get the good enough accuracy. The speed then... I have to think about it.
March 1st, 2014, 06:52 AM   #6
Global Moderator

Joined: Nov 2006
From: UTC -5

Posts: 16,046
Thanks: 938

Math Focus: Number theory, computational mathematics, combinatorics, FOM, symbolic logic, TCS, algorithms
Re: Computing the error function

Quote:
 Originally Posted by fysmat No problem! Thank you for your help. I looked at the PARI/GP code a little bit, but then I just decided to make some kind of composition of different methods (Maclaurin serie, trapetzoid rule and asymptotic serie). The solution is not quite elegant, but anyway I get the good enough accuracy. The speed then... I have to think about it.
There's nothing wrong with that sort of approach -- sometimes it's referred to as a "polyalgorithm", where you have several algorithms and choose which one is best based on the arguments or the precision desired.

 March 1st, 2014, 07:18 AM #7 Senior Member     Joined: Dec 2013 From: some subspace Posts: 212 Thanks: 72 Math Focus: real analysis, vector analysis, numerical analysis, discrete mathematics Re: Computing the error function *nods nods* I was just a bit disappointed because of the trapetzoid rule. It took too much time to compute the results. So. I changed the integrator to sinh-tanh quadrature and now I'm getting accurate enough results quite fast. ^^
March 1st, 2014, 08:17 AM   #8
Global Moderator

Joined: Nov 2006
From: UTC -5

Posts: 16,046
Thanks: 938

Math Focus: Number theory, computational mathematics, combinatorics, FOM, symbolic logic, TCS, algorithms
Re: Computing the error function

Quote:
 Originally Posted by fysmat *nods nods* I was just a bit disappointed because of the trapetzoid rule. It took too much time to compute the results. So. I changed the integrator to sinh-tanh quadrature and now I'm getting accurate enough results quite fast. ^^
Yes, PARI/GP uses it internally as well -- I think they have one of the best implementations of double-exponential integration anywhere.

 Tags computing, error, function

 Thread Tools Display Modes Linear Mode

 Similar Threads Thread Thread Starter Forum Replies Last Post Sonntag111106 Math Books 1 April 20th, 2013 03:18 AM sugakusu Calculus 0 March 26th, 2012 04:19 AM Cookie1 Complex Analysis 1 March 11th, 2012 11:29 PM GoYu Calculus 1 November 2nd, 2011 05:47 AM Cookie1 Applied Math 0 December 31st, 1969 04:00 PM

 Contact - Home - Forums - Cryptocurrency Forum - Top