lib/rubystats/modules.rb
# Complementary error function.
# Based on C-code for the error function developed at Sun Microsystems.
# author Jaco van Kooten
Complementary error function.
Based on C-code for the error function developed at Sun Microsystems.
author Jaco van Kooten
Complementary error function . Based on C - code for the error function developed at Sun Microsystems . author Jaco van Kooten
def complementary_error(x)
    eRa = [-9.86494403484714822705e-03,
      -6.93858572707181764372e-01,
      -1.05586262253232909814e01,
      -6.23753324503260060396e01,
      -1.62396669462573470355e02,
      -1.84605092906711035994e02,
      -8.12874355063065934246e01,
      -9.81432934416914548592e00 ]
    eSa = [ 1.96512716674392571292e01,
      1.37657754143519042600e02,
      4.34565877475229228821e02,
      6.45387271733267880336e02,
      4.29008140027567833386e02,
      1.08635005541779435134e02,
      6.57024977031928170135e00,
      -6.04244152148580987438e-02 ]
    eRb = [-9.86494292470009928597e-03,
      -7.99283237680523006574e-01,
      -1.77579549177547519889e01,
      -1.60636384855821916062e02,
      -6.37566443368389627722e02,
      -1.02509513161107724954e03,
      -4.83519191608651397019e02 ]
    eSb = [ 3.03380607434824582924e01,
      3.25792512996573918826e02,
      1.53672958608443695994e03,
      3.19985821950859553908e03,
      2.55305040643316442583e03,
      4.74528541206955367215e02,
      -2.24409524465858183362e01 ]
    abs_x = (if x >= 0.0 then x else -x end)
    if abs_x < 1.25
      retval = 1.0 - error(abs_x)
    elsif abs_x > 28.0
      retval = 0.0
    else
      s = 1.0/(abs_x * abs_x)
      if abs_x < 2.8571428
        r = eRa[0] + s * (eRa[1] + s * 
                          (eRa[2] + s * (eRa[3] + s * (eRa[4] + s * 
                                                       (eRa[5] + s *(eRa[6] + s * eRa[7])
                                                       )))))
                                                       s = 1.0 + s * (eSa[0] + s * (eSa[1] + s * 
                                          (eSa[2] + s * (eSa[3] + s * (eSa[4] + s * 
                           (eSa[5] + s * (eSa[6] + s * eSa[7])))))))
      else
        r = eRb[0] + s * (eRb[1] + s * 
                          (eRb[2] + s * (eRb[3] + s * (eRb[4] + s * 
             (eRb[5] + s * eRb[6])))))
        s = 1.0 + s * (eSb[0] + s * 
                       (eSb[1] + s * (eSb[2] + s * (eSb[3] + s * 
             (eSb[4] + s * (eSb[5] + s * eSb[6]))))))
      end
      retval =  Math.exp(-x * x - 0.5625 + r/s) / abs_x
    end
    return ( if x >= 0.0 then retval else 2.0 - retval end )
    end
def complementary_error ( x ) eRa = [ - 9.86494403484714822705e-03 , - 6.93858572707181764372e-01 , - 1.05586262253232909814e01 , - 6.23753324503260060396e01 , - 1.62396669462573470355e02 , - 1.84605092906711035994e02 , - 8.12874355063065934246e01 , - 9.81432934416914548592e00 ] eSa = [ 1.96512716674392571292e01 , 1.37657754143519042600e02 , 4.34565877475229228821e02 , 6.45387271733267880336e02 , 4.29008140027567833386e02 , 1.08635005541779435134e02 , 6.57024977031928170135e00 , - 6.04244152148580987438e-02 ] eRb = [ - 9.86494292470009928597e-03 , - 7.99283237680523006574e-01 , - 1.77579549177547519889e01 , - 1.60636384855821916062e02 , - 6.37566443368389627722e02 , - 1.02509513161107724954e03 , - 4.83519191608651397019e02 ] eSb = [ 3.03380607434824582924e01 , 3.25792512996573918826e02 , 1.53672958608443695994e03 , 3.19985821950859553908e03 , 2.55305040643316442583e03 , 4.74528541206955367215e02 , - 2.24409524465858183362e01 ] abs_x = ( if x >= 0.0 then x else - x end ) if abs_x < 1.25 retval = 1.0 - error ( abs_x ) elsif abs_x > 28.0 retval = 0.0 else s = 1.0 / ( abs_x * abs_x ) if abs_x < 2.8571428 r = eRa [ 0 ] + s * ( eRa [ 1 ] + s * ( eRa [ 2 ] + s * ( eRa [ 3 ] + s * ( eRa [ 4 ] + s * ( eRa [ 5 ] + s * ( eRa [ 6 ] + s * eRa [ 7 ] ) ) ) ) ) ) s = 1.0 + s * ( eSa [ 0 ] + s * ( eSa [ 1 ] + s * ( eSa [ 2 ] + s * ( eSa [ 3 ] + s * ( eSa [ 4 ] + s * ( eSa [ 5 ] + s * ( eSa [ 6 ] + s * eSa [ 7 ] ) ) ) ) ) ) ) else r = eRb [ 0 ] + s * ( eRb [ 1 ] + s * ( eRb [ 2 ] + s * ( eRb [ 3 ] + s * ( eRb [ 4 ] + s * ( eRb [ 5 ] + s * eRb [ 6 ] ) ) ) ) ) s = 1.0 + s * ( eSb [ 0 ] + s * ( eSb [ 1 ] + s * ( eSb [ 2 ] + s * ( eSb [ 3 ] + s * ( eSb [ 4 ] + s * ( eSb [ 5 ] + s * eSb [ 6 ] ) ) ) ) ) ) end retval = Math . exp ( - x * x - 0.5625 + r / s ) / abs_x end return ( if x >= 0.0 then retval else 2.0 - retval end ) end
Complementary error function.
Complementary error function .
# Coefficients for approximation of erfc in [1.25,1/.35] # Coefficients for approximation to erfc in [1/.35,28] # 1.25 < |x| < 28
x
<not_specific>