Question: Use Python programming to solve. Different PRNGs in Matlab The latest version of Matlab has many different methods for creating pseudo-random uniform(0.1) sequences. You can
Use Python programming to solve.

Different PRNGs in Matlab The latest version of Matlab has many different methods for creating pseudo-random uniform(0.1) sequences. You can create multiple sequences (often called "streams") using different seeds or different methods and compare them. Here's how to create 3 different streams using 3 different methods. methodl - Randstream ('mcg16807); method2 - Randstream ' swb2712'); method3 - Randstream 'mt 19937ar'); Method I was Matlab's default before 1995. It is a LCG with m = 231 - 1 and a = 79. It is too simple for modern applications. Method 2 was Matlab's default from 1995 to 2006. It is not a LCG and it is awful. I once spent many hours debugging before I realized that the problem was with this PRNG. Method 3 is the Mersenne Twister, which is currently a very popular PRNG and which is Matlab's default since 2007. Assuming you have a recent version of Matlab, then if you just use rand in Matlab, then you will get method 3 without having to specify anything. To generate an rx carray of pseudo-random numbers using one of these streams and store it in the matrix U type U - rand (method?, r, c); where you replace the ? with one of the numbers 1,2, or 3 to get the desired method. (On later homework sets, when we are finished exploring PRNGs and just want the best PRNG, you can use U - rand (x,c); without specifying a method. This uses the default method 3, in this case - which seems to be the best of Matlab's choices. Demo Convince yourself that the PRNGs are deterministic. For example, create two copies of method 3, say method3a - Randstream'mt 19937ar'); and method3b - Randstream ('mt 19937ar'); Now rand (method3a) and rand (method3b) should behave identically. Call them repeatedly to verify. Four different PRNGs A. The LCG that you created in problem 1 [after converting to (0.1) by dividing each R, by m). B. Matlab method 1 above. C. Matlab method 2 above. D. Matlab method 3 above. The law of large numbers Recall that the law of large numbers (LLN) states that h(X) + E[(X)] as n U for any iid sequence X, X1, X2,... for which E (X)exists. So if a pseudo-random sequence ....,U, behaves like an iid Uniform(0.1) sequence, then we better have U HU) =EHU) for large n where U is Uniform(0.1). 2. For each of the four PRNGS (A-D) defined above, let U1 U 10000 be a sequence from the PRNG. Plot -1 Uhe versus n and also t-Uversus n for n=1..... 10000. What would you expect these sums to converge to as n for a truly iid sequence? Interpret your results. Different PRNGs in Matlab The latest version of Matlab has many different methods for creating pseudo-random uniform(0.1) sequences. You can create multiple sequences (often called "streams") using different seeds or different methods and compare them. Here's how to create 3 different streams using 3 different methods. methodl - Randstream ('mcg16807); method2 - Randstream ' swb2712'); method3 - Randstream 'mt 19937ar'); Method I was Matlab's default before 1995. It is a LCG with m = 231 - 1 and a = 79. It is too simple for modern applications. Method 2 was Matlab's default from 1995 to 2006. It is not a LCG and it is awful. I once spent many hours debugging before I realized that the problem was with this PRNG. Method 3 is the Mersenne Twister, which is currently a very popular PRNG and which is Matlab's default since 2007. Assuming you have a recent version of Matlab, then if you just use rand in Matlab, then you will get method 3 without having to specify anything. To generate an rx carray of pseudo-random numbers using one of these streams and store it in the matrix U type U - rand (method?, r, c); where you replace the ? with one of the numbers 1,2, or 3 to get the desired method. (On later homework sets, when we are finished exploring PRNGs and just want the best PRNG, you can use U - rand (x,c); without specifying a method. This uses the default method 3, in this case - which seems to be the best of Matlab's choices. Demo Convince yourself that the PRNGs are deterministic. For example, create two copies of method 3, say method3a - Randstream'mt 19937ar'); and method3b - Randstream ('mt 19937ar'); Now rand (method3a) and rand (method3b) should behave identically. Call them repeatedly to verify. Four different PRNGs A. The LCG that you created in problem 1 [after converting to (0.1) by dividing each R, by m). B. Matlab method 1 above. C. Matlab method 2 above. D. Matlab method 3 above. The law of large numbers Recall that the law of large numbers (LLN) states that h(X) + E[(X)] as n U for any iid sequence X, X1, X2,... for which E (X)exists. So if a pseudo-random sequence ....,U, behaves like an iid Uniform(0.1) sequence, then we better have U HU) =EHU) for large n where U is Uniform(0.1). 2. For each of the four PRNGS (A-D) defined above, let U1 U 10000 be a sequence from the PRNG. Plot -1 Uhe versus n and also t-Uversus n for n=1..... 10000. What would you expect these sums to converge to as n for a truly iid sequence? Interpret your results
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
