macro normal z cdf #This macro finds the area under the left tail of the normal distribution #relative to the specified z value. The answer is a constant called cdf. #z is the standard normal z value #cdf is the area under the normal curve in the left tail relative to z #Example calling statement: # mtb> %normal 2.0 k1 #Answer cdf = 0.977252 #Algorithm from AMS55 p. 932 26.2.10 for z>0 #Copyright (c) Paul G. Mathews 8 Oct 01 All Rights Reserved mconstant z cdf term err n lastcdf negative let negative=(z<0) let z=abs(z) let term=z #first term in the summation let cdf=z let err=1 let n=1 while err>1e-4 let lastcdf=cdf let term=term*(-1)*z*z/n/2 let cdf=cdf+term/(2*n+1) let err=abs(1-lastcdf/cdf) let n=n+1 endwhile let cdf=0.5+cdf/sqrt(2*3.14159) if negative let cdf=1-cdf endif print z cdf endmacro