NORMAL SIMULATION THROUGH APL COMPUTER LANGUAGE Edward J. Danial and S.K. Ka~i Finally, the process is repeated as much as the value o f M requires. The A P L function NOtVJISIlil. VNORR'S/MI[D]V ABSTRACT [o13 V A very simple A P L function with the capability of simulating random sample from the widely applied normal d i s t r i b u t i o n , t h r o u g h the very important central limit theorem, is introduced. Documentations and examples are presented. Introdut-tion. Let x t,X 2.... ,X, be a random sample of random vari ables (r.v.'s) from a certain population with mean # and standard deviation ~. Then, the central limit theorem implies that for l a r g e , , the statistic (or r.v.) Z - ~ J~-~ (I) v Z÷NOPJiSIM1 M Z÷-6+O.OO1x/-1+?(R,12)P1001 Sample eX~LIUOn Of NORMSIM1. NORI~SIM1 is written in " I B M Personal Computer A P L " , Version 1.0. It can be accessed through IBM PC/XT/AT. On the mainframe, an IBM/370 system should be convenient too. T h e following are some NOR/~S.I'M1 scsions. HORNSZR1 10 has approximately a standard normal distribution, where J? = I ~ X , R I--I is the sample mean. In particular, if the above population is r e p u t e d by a continuous uniform r.v. on the interval (0,1), then equation (1) becomes z - -0.577 -0.658 -0.927 -0.836 -0.156 -0.635 -1.813 -0.252 -0.q~9 NORMSI~I I0 -1.222 -0.752 0.055 -0.~2~ 0.667 -0.627 0.668 0.528 -0.932 0.263 WORJl/SIM1 10 0.151 0.038 0.87 0.53~ -1.208 0.782 0.275 -1.136 2.17 0.q56 NORMSZR1 2 3 -0.258 . (2) (Since in this case . - ~ a n d ~ = - - - ~ ) . . - 12, equation (2) reduces to Consequantly, for -1.q88 2.2 0.3~1 0.385 -0.02~ -0.6q9 NORMSIR1 2 3 1.313 -0.355 -0.68 0.0~8 0.531 -0.62 NOPJISZM1 2 3 q z - (12/-6) i=l . (3) T h e aim of this p a p e r is to implement the central limit theorem in terms of APL. This is achieved through a convenient A P L function, namely, /JOR//$I//1. NOP~$.TM1 is based on equation (3), i.e. the average of 12 uniform random variables, adjusted for the mean, is standard normal. The A P L random number generator F (the "roll" function) plays an important role. Simulation or normal random sample. R a n d o m samples from normal probability distribution are simulated via NORMSI//1. NORM$IM1 is a straight forward A P L function with only two variables and one A P L statement. T h e variable M, which is nl.u'b the argument of NORMSIM1, could be a scalar or vector. T h e resultant Z could be a scalar, a vector or at least one matrix of standard normal variables. T h e number of the standard normal variables needed is controlled by the components values of M (See sample execution of X0RMSIM1). The A P L statement appearing in line ( 1 ) p e r f o r m s the operation in equation (3). First, 12 uniform numbers are generated as explained in Danial and Kat'ti (1988). Secondly, the operations in equation (3) are performed. -0.07q -2.19q 1.2q2 -0.211 -0.071 -0.115 1.008 -0.7q6 0.739 0.~8 -1.27q 0.767 0.809 0.23q 2.979 0.878 1.229 -0.6 -0.389 -0.q71 -2.609 0.27 -1.q~q -1.627 Refel~[io~. Danial, E. and Katti, S., Monte Carlo Simulation through A P L C.xJmputer Language, to appear A P L Quote Quad 18 (4), 1988. Dept. of Mathemalics Towson State University Towson, M D 21204 USA A P L Q u o t e Qktad 19 3 M a r c h 1989
/lp/association-for-computing-machinery/normal-simulation-through-apl-computer-language-uN4S6Bm7fV