#!/usr/bin/env python #---------------------------------------------------------------------- # stdnorml.py # # This program outputs a table showing areas under the standard # Normal Distribution from 0 to z > 0 in increments of 0.01. # # execute using: $ python ./stdnorml.py # # programmer: ALLAN CRUSE # written on: 22 FEB 2011 #---------------------------------------------------------------------- import math def phi( z ): root_2pi = math.sqrt( 2.0 * 3.141592653589793 ) den = root_2pi * math.exp( z * z / 2.0 ) return 1.0 / den def area( z ): # returns area under graph of y = phi() from 0 to z # computed using the Trapezoid Rule with 400 rectangles areasum = 0.0 delta_x = z / 400.0 x0 = 0.0 x1 = delta_x for i in range( 400 ): phi_0 = phi( x0 ) phi_1 = phi( x1 ) areasum += (phi_0 + phi_1) * delta_x / 2.0 x0 += delta_x x1 += delta_x return areasum print print print " ", print "Table of areas under the standard normal curve from 0 to z " print print print " z ", for col in range( 10 ): print " %d " % col, print z = 0.0 delta_z = 0.01 for row in range( 40 ): print " %1.2f: " % z, for col in range( 10 ): val = area( z ) z += delta_z print "%1.4f" % val, print if ( (row % 5) == 4 ): print print