Skip to content

Instantly share code, notes, and snippets.

@danielc192
danielc192 / InverseError.rb
Last active December 19, 2015 00:39
Code to calculate the Inverse Error function using a power series approximation. Based on information at http://en.wikipedia.org/wiki/Error_function#Inverse_functions. Implemented as a method in the Math module, but it could easily be run independently.
module Math
def self.invErf(x)
c = []
c[0] = 1.0
c[1] = 1.0
result = 0.0
(0..100).each do |k|
# Calculate C sub k
if k > 1 then
c[k] = 0.0
@danielc192
danielc192 / 2F1Hypergeometic.rb
Created June 25, 2013 19:47
This might be helpful for anyone trying to implement a t-distribution or other function which requires the 2F1 hypergeometic function. This code is based on an algorithm from http://people.maths.ox.ac.uk/porterm/research/pearson_final.pdf, and extends the Math module, although it could easily be implemented independently.
module Math
##
# hypergeom(a, b, c, z) => Float
# Implementation of the 2F1 Hypergeometic Function using converging Taylor Series.
# Note 10,000 iterations is normally more than enough to achieve convergence, but feel free to increase
#
def self.hypergeom(a, b, c, z)
s = []
cj = []
cj[0] = 1