Tuesday, June 11, 2013

Start on Normal cumulative distribution function


This a javascript code of this function



For resolve the non centered and reduced distribution we use a Gauss error function.
//Erf function based

function erfAppro6(x)
{
 returne=1.0;
  a1=0.0705230784; a2=0.0422820123; a3=0.0092705272; a4=0.0001520143; a5=0.0002765672; a6=0.0000430638;
 returne=returne-1/Math.pow((1+a1*x+0.230389*x*x+a2*x*x*x+a3*x*x*x*x+a4*x*x*x*x*x+a5*x*x*x*x*x*x+a6*x*x*x*x*x*x*x),16); 
 return returne;
}


//Normal centered and reduct mu==0 && sigma==1
function NCDF2(z)

{
 
 res=1/(1+Math.exp(-(0.07056*z*z*z+1.5976*z)));
 if (res>1.0) res=1.0;
 return res;
}
//Normal with mu & sigma
function NCDF(x,mu,sigma)
{
 if (mu==0&&sigma==1)
 return NCDF2(x);
 res=0.5*(1+erfAppro6(((x-mu)/(sigma*Math.sqrt(2)))));
 if (res>1.0) res=1.0;
 return res;
}


No comments: