Inverse Error Function in C

Is it possible to calculate the inverse error function in C?

I can find erf(x) in <math.h> , which computes the error function, but I cannot find anything to do the opposite.

+7
c function inverse
source share
2 answers

Quick and dirty, tolerance under + -6e-3. Work based on the "Convenient approximation of the error function and its inverse" by Sergey Vinitsky.

C / C ++ CODE:

 float myErfInv2(float x){ float tt1, tt2, lnx, sgn; sgn = (x < 0) ? -1.0f : 1.0f; x = (1 - x)*(1 + x); // x = 1 - x*x; lnx = logf(x); tt1 = 2/(PI*0.147) + 0.5f * lnx; tt2 = 1/(0.147) * lnx; return(sgn*sqrtf(-tt1 + sqrtf(tt1*tt1 - tt2))); } 

Checking the performance of MATLAB:

 clear all, close all, clc x = linspace(-1, 1,10000); a = 0.147; u = log(1-x.^2); u1 = 2/(pi*a) + u/2; u2 = u/a; y = sign(x).*sqrt(-u1+sqrt(u1.^2 - u2)); f = erfinv(x); axis equal figure(1); plot(x, [y;f]); figure(2); e = fy; plot(x, e); 

MATLAB Charts:

Plot1 Plot2

+3
source share

I don't think this is the standard version in <math.h> , but there are other C erfinv(x) that implement the erfinv(x) backward error function that you can use.

+1
source share

All Articles