DECLARE FUNCTION PHI# (u AS DOUBLE) DECLARE FUNCTION XNORMAL# (P AS DOUBLE) '********************************************************************** '* NORMAL AND INVERSE NORMAL PROBABILITY FUNCTIONS * '* ------------------------------------------------------------------ * '* SAMPLE RUN: * '* * '* Value of variable: 0.2 * '* * '* Probability = .391042693975443 * '* * '* Verify: * '* X = .200000286102949 * '* * '* Basic Version By J-P Moreau, Paris. * '* (www.jpmoreau.fr) * '********************************************************************** DEFDBL A-H, O-Z DEFINT I-N CLS PRINT INPUT " Value of variable: ", X PRINT P = PHI(X) PRINT " Probability = "; P PRINT PRINT " Verify:" Y = XNORMAL(P) PRINT " X = "; Y END 'of main program FUNCTION PHI (u AS DOUBLE) 'Standard Normal Probability Function PI = 3.14159265359# PHI = (1# / ((2# * PI) ^ .5)) * EXP(-.5 * (u ^ 2)) END FUNCTION FUNCTION XNORMAL (P AS DOUBLE) 'Inverse Standard Normal Function epsilon = .000001 chimax = 100000# xminchisq = 0# xmaxchisq = chimax IF P <= 0# THEN XNORMAL = xmaxchisq EXIT FUNCTION ELSE IF P >= 1# THEN XNORMAL = 0# EXIT FUNCTION END IF END IF chisqval = .5# WHILE ABS(xmaxchisq - xminchisq) > epsilon IF (PHI(chisqval) < P) THEN xmaxchisq = chisqval ELSE xminchisq = chisqval END IF chisqval = (xmaxchisq + xminchisq) * .5 WEND XNORMAL = chisqval END FUNCTION