00001 // This is core/vnl/vnl_erf.h 00002 #ifndef vnl_erf_h_ 00003 #define vnl_erf_h_ 00004 //: 00005 // \file 00006 // \brief Error Function (erf) approximations 00007 // \author Tim Cootes, Ian Scott 00008 00009 #include <vnl/vnl_gamma.h> 00010 #include <vnl/vnl_math.h> 00011 00012 //: The Error function. 00013 // erf(x) = (2/sqrt(pi)) Integral from 0 to x (exp(-t^2) dt) 00014 // \note the output ranges from -1 to 1, and vnl_erf(0) = 0. 00015 inline double vnl_erf(double x) 00016 { return (x<0)?-vnl_gamma_p(0.5,x*x):vnl_gamma_p(0.5,x*x); } 00017 00018 //: The Complementary Error function. 00019 // erfc(x) = 1 - erf(x) = 1 - (2/sqrt(pi)) Integral from 0 to x (exp(-t^2) dt) 00020 // This value is useful for large x, when erf(x) ~= 1 and erfc(x) < eps. 00021 // \note the output ranges from 0 to 2, and vnl_erfc(0) = 1. 00022 double vnl_erfc(double x); 00023 00024 //: The Scaled Complementary Error function. 00025 // erfc_scaled(x) = exp(x^2) * erfc(x) 00026 // This value is useful for very large x, where erf and erfc returns 00027 // respectively ~1 and ~0. 00028 // It can be approximated by (1/sqrt(pi)) * (1/x) 00029 inline double vnl_scaled_erfc(double x) 00030 { return (vnl_math::two_over_sqrtpi/2.)*(1./x); } 00031 00032 #endif // vnl_erf_h_