Simulation

download Simulation

If you can't read please download the document

description

maths

Transcript of Simulation

29-Mar-13Dr.B.Mishra (Prob & Stat)1 Simulation Simulation Nowadayssimulationtechniquesarebeing appliedtomanyproblemsinScienceand Engineering.Iftheprocessesbeingsimulated involve an element of chance, these simulation techniquesarereferredtoasMonteCarlo methods.Forexampletostudythenumberof customers arriving at an Airline Company or to study the amount of stocks in inventory, Monte Carlo techniques are used. 29-Mar-13Dr.B.Mishra (Prob & Stat)2 Random Numbers InMonteCarlomethods,oneusesthe tableofrandomnumberstogenerate randomdeviates(=valuesassumedbya randomvariable).Tableofrandom numbers consists of many pages on which thedigits0,1,2,3,4,5,6,7,8,9are distributedinsuchawaythatthe probabilityofanyonedigitappearingis the same,namely 110 = 0.1. 29-Mar-13Dr.B.Mishra (Prob & Stat)3 Useofrandomnumberstogenerate Heads and Tails Forexample,wechoosePage693,Row22, Column4andgoacrosssequentially.We read the digits 7410347070 (etc.). Associatingaheadtotheoccurrenceofan even digit and tail to an odd number, we may interpret this as THTHTHTH T H becausetheprobabilityofgettinganeven digit = the probability of an odd digit = 0.5. 29-Mar-13Dr.B.Mishra (Prob & Stat)4 We can also associate a head if we get one of the 5 digits 0, 1, 2, 3, 4 and a tail otherwise. This means that we got the sequence THHHHHTHTH InproblemsonSimulation,weshalladopt the second scheme as it is easy to use and is easilyextendableformorethantwo outcomes. 29-Mar-13Dr.B.Mishra (Prob & Stat)5 Supposeforexample,wehaveanexperiment with 4 outcomes with probability 0.1, 0.2. 0.3 and 0.4 respectively.Tosimulatetheoutcomesoftheabove experiment,wehavetoallotoneofthedigits tothefirstoutcome,twooftheremaining9 digitstothe2ndoutcome,threeofthe remaining7digitstothe3rdoutcomeandthe remaining 4 digits to the 4th outcome. Though this can be done in a variety of ways, we29-Mar-13Dr.B.Mishra (Prob & Stat)6 Associate the first digit 0 to the 1st outcome O1, Associate the next two digits, namely 1, 2 to the 2nd outcome O2, Associate next three digits, namely 3, 4, 5 to the 3rd outcome O3, Associate the remaining four digits, namely 6, 7, 8, 9 to the 4th outcome O4. choose the simplest way as follows: 29-Mar-13Dr.B.Mishra (Prob & Stat)7 Hence the above sequence 7410347070of random numbers would correspond to the sequence of outcomesO4O3O2O1 O3 O3O4O1O4 O1. Useoftwoandhigherdigitrandom numbers in Simulation Suppose we have a random experiment with three outcomes with probabilities 0.80, 0.15 and 0.05 respectively. 29-Mar-13Dr.B.Mishra (Prob & Stat)8 We now read two digits at a time: 74, 10, 34, 70, 70, 25, 30, 67 etc. SinceP(anyonedigit)=0.1,P(anytwo digits) = 0.1 0.1 = 0.01 = 1/100. Thus each twodigitrandomnumberoccurswitha probability 0.01. How can we use the table of random numbers to simulate the above experiment? 29-Mar-13Dr.B.Mishra (Prob & Stat)9 Sincethereare1002-digitrandomnumbers, namely00,01,,10,11,12,,99,we associatethefirst802-digitrandomnumbers, namely, 00, 01, .., 10, 11, , 78, 79 to the first outcomeO1,thenext152-digitrandom numbers,namely80,81,,93,94tothe secondoutcomeO2,andtheremaining52-digit random numbers, namely 95, 96, , 99 tothe3rdoutcomeO3.Thustheabove sequence 74, 10, 34, 70, 70 corresponds to the sequence of outcomesO1,O1,O1,O1,O1 29-Mar-13Dr.B.Mishra (Prob & Stat)10 We describe the above scheme in a diagram as follows: OutcomeProbabilityCumulative Probability * Random Numbers ** O1 0.800.8000 - 79 O2 0.150.9580 - 94 O3 0.051.0095 - 99 29-Mar-13Dr.B.Mishra (Prob & Stat)11 *Cumulative probability is got by adding all the probabilities at that position and above it. Thus the cumulative probability of the Outcome O2 = Probability of O1 and Probability of O2 = 0.80 + 0.15 = 0.95. ** We also observe that the beginning random number is 00 for the 1st outcome; and for the remaining outcomes, it is one more than the ending random number of the immediately preceding outcome. Also the ending random number is one less than the cumulative Prob. 29-Mar-13Dr.B.Mishra (Prob & Stat)12 Similarly three digit random numbers are used if the probability of an outcome has three decimal places.29-Mar-13Dr.B.Mishra (Prob & Stat)13 Example Supposethattheprobabilitiesare0.2466, 0.3452, 0.2417, 0.1128, 0.0395, 0.0111, 0.0026, and 0.0005 that there will be 0, 1, 2, 3, 4, 5, 6, or7pollutingspillsintheGreatLakesonany one day. (a)Describethefour-digitrandomnumbers from0000to9999tothe8valuesofthis random variable, so that the corresponding randomnumberscanbeusedtosimulate daily polluting spills in the Great Lakes. 29-Mar-13Dr.B.Mishra (Prob & Stat)14 (b)Usetheresultsof(a)tosimulatethe numbersofpollutingspillsintheGreat lakes for 30 days. 29-Mar-13Dr.B.Mishra (Prob & Stat)15 No of polluting Spills ProbabilityCumulative Probability 4-digit Random Numbers 00.2466 10.3452 20.2417 30.1128 40.0395 50.0111 60.0026 70.0005 Scheme for Simulating Polluting Spills 0.24660000 24650.59182466 59170.83355918 83340.9463 8335 94629463 98579858 99689969 99949995 99990.9858 0.9969 0.9995 1.0000 29-Mar-13Dr.B.Mishra (Prob & Stat)16 (b) Let us start on Page 693, Row 22, Column 4 and go across sequentially: We read out the 4-digit random numbers as: 7410, 3470, 7025, 3067, 6468, 2638, 4581, 1510, 6646, etc.The simulated polluting spills are: 2, 1, 2 , 1, 2, 1, 1,0, 2, etc. 29-Mar-13Dr.B.Mishra (Prob & Stat)17 Example Dependingontheavailabilityofparts,a company can manufacture 3, 4, 5, or 6 units of acertainitemperweekwithcorresponding probabilities0.10,0.40,0.0.30,and0.20.The probabilitiesthattherewillbeaweekly demand of 0, 1, 2, , 8 units are, respectively, 0.05,0.10,0.30,0.30,0.10,0.05,0.05,0.04, and 0.01. If a unit is sold during the week that it ismade,itwillyieldaprofitof$100;this profit is reduced by $20 for each week it has to 29-Mar-13Dr.B.Mishra (Prob & Stat)18 stored.Userandomnumberstosimulatethe operation of this company for 50 consecutive weeksandestimateitsexpectedweekly profit. Random Nos. for units produced: 27, 57, 26, 50, 87, 27,39, 53, 95, 79, 24, 42 Random Nos. for units demanded: 98, 86, 67, 44, 30, 97, 88, 94, 04, 46, 34, 94 29-Mar-13Dr.B.Mishra (Prob & Stat)19 Scheme for simulating the number of units produced per week No of units produced ProbabilityCumulative Probability Random Numbers 30.10 40.40 50.30 60.20 0.10 0.50 0.80 1.00 00 0910 4950 7980 9929-Mar-13Dr.B.Mishra (Prob & Stat)20 Scheme for simulating the weekly demand Weekly Demand ProbabilityCumulative Probability Random Numbers 00.050.0500 0410.100.1505 1420.300.4515 4430.300.7545 7440.100.8575 8429-Mar-13Dr.B.Mishra (Prob & Stat)21 Scheme for simulating the weekly demand Weekly Demand ProbabilityCumulative Probability Random Numbers 50.050.9085 8960.050.9590 9470.040.9995 9880.011.009929-Mar-13Dr.B.Mishra (Prob & Stat)22 (1)(2)(3)(4)(5)(6)(7)(8)(9) WeekNo in Stock RN for prod No Produced RN for Demand No demanded No sold=Min {(2) +(4), (6)} No unsold = max{0, (2)+(4)-(7)} Profit = (7) *100-(2) * 20 We can continue like this. 40127 4 9870400 2 0 57586550500 3026467331300 4150544224180 5487630228120 Av. Profit =30029-Mar-13Dr.B.Mishra (Prob & Stat)23 Simulating a Continuous random variate SupposeXisacontinuousrandomvariable with density f (x) and cdfF(x). We know that

U = F (X) isacontinuousrandomvariablehaving uniform density on [0, 1]. 29-Mar-13Dr.B.Mishra (Prob & Stat)24 Notingthatarandomnumberisnothingbut thevalueassumedbyarandomvariableU havinguniformdistributionover[0,1],we thussimulatethevalueassumedbya continuous random variable X as follows: Step 1 Find the cdf, F (x) of X Step2Selecta(2or3digit)random number U from a table of random digits.29-Mar-13Dr.B.Mishra (Prob & Stat)25 Forexampleiftherandomnumberis243, then it corresponds to the value 0.243. Step 3: Solve for X, the equation F (X) = U. Be sure to note U is a decimal between 0 and 1 (and so put a decimal point at the start). 29-Mar-13Dr.B.Mishra (Prob & Stat)26 Simulating an exponential density Example Let X be a random variable having exponential density with parameter |.( ) 1xF x e|= = u Solving for x we get 1ln1xu| =Hence the cdf of X is29-Mar-13Dr.B.Mishra (Prob & Stat)27 Since whenever u is a random number, so also is 1 u,we can also write the value assumed by a random variable having an exponential density with parameter| as 1ln xu| =(We ignore the case when u = 0.) 29-Mar-13Dr.B.Mishra (Prob & Stat)28 Example Simulating a uniform density LetXbeacontinuousrandomvariable having uniform density on [a, b]. Hence the cdf of X is( )x aF xb a== u Solving for x,we get( ) x a b a u = + 29-Mar-13Dr.B.Mishra (Prob & Stat)29 Example Let X be a continuous random variable having density f (x) = 2x, 0 < x < 1. Hence the cdf of X is = u Solving for x,we getx u =(only positive square root) F(x) = x2 29-Mar-13Dr.B.Mishra (Prob & Stat)30 Example Let X be a continuous random variable having density f (x) = | x |, -1 < x < 1. Hence the cdf of X is221 1, 1 02 2( )1 1, 0 12 2x xF xx x