9
1 Exercise using Excel (see Exercise using Excel (see intro to Excel at end) intro to Excel at end) 1. 1. Using Excel’s rand() function, generate a column of 100 random Using Excel’s rand() function, generate a column of 100 random numbers in the range -1 to +1. Plot a histogram (see histogram numbers in the range -1 to +1. Plot a histogram (see histogram slide) of these numbers. Note that they are uniformly slide) of these numbers. Note that they are uniformly distributed. distributed. 2. 2. Also using Excel, generate a column of 100 normally distributed Also using Excel, generate a column of 100 normally distributed random numbers with mean=0.0 and standard deviation=1.0. (Hint: random numbers with mean=0.0 and standard deviation=1.0. (Hint: Use the polar form.) Also, plot (histogram) these random Use the polar form.) Also, plot (histogram) these random numbers. numbers. Do not use Excel’s built in normdist(), normsdist(), normsinv(), or an Do not use Excel’s built in normdist(), normsdist(), normsinv(), or an other Excel built in norm*() function. They aren’t generally other Excel built in norm*() function. They aren’t generally available in game engines. available in game engines. 3. 3. Also using Excel, generate a column of 100 normally distributed Also using Excel, generate a column of 100 normally distributed random numbers with mean=0.5 and standard deviation=0.25. (Hint: random numbers with mean=0.5 and standard deviation=0.25. (Hint: Use the polar form.) Also, plot (histogram) these random Use the polar form.) Also, plot (histogram) these random numbers. numbers. 4. 4. Create one plot (histogram) with all sets of random numbers. Create one plot (histogram) with all sets of random numbers. 5. 5. Answer the following. What happens when U Answer the following. What happens when U 1 =0? =0?

1 Exercise using Excel (see intro to Excel at end) 1. Using Excel’s rand() function, generate a column of 100 random numbers in the range -1 to +1. Plot

Embed Size (px)

Citation preview

Page 1: 1 Exercise using Excel (see intro to Excel at end) 1. Using Excel’s rand() function, generate a column of 100 random numbers in the range -1 to +1. Plot

11

Exercise using Excel (see intro to Exercise using Excel (see intro to Excel at end)Excel at end)

1.1. Using Excel’s rand() function, generate a column of 100 random Using Excel’s rand() function, generate a column of 100 random numbers in the range -1 to +1. Plot a histogram (see histogram slide) numbers in the range -1 to +1. Plot a histogram (see histogram slide) of these numbers. Note that they are uniformly distributed.of these numbers. Note that they are uniformly distributed.

2.2. Also using Excel, generate a column of 100 normally distributed Also using Excel, generate a column of 100 normally distributed random numbers with mean=0.0 and standard deviation=1.0. (Hint: random numbers with mean=0.0 and standard deviation=1.0. (Hint: Use the polar form.) Also, plot (histogram) these random numbers.Use the polar form.) Also, plot (histogram) these random numbers.

• Do not use Excel’s built in normdist(), normsdist(), normsinv(), or an other Do not use Excel’s built in normdist(), normsdist(), normsinv(), or an other Excel built in norm*() function. They aren’t generally available in game Excel built in norm*() function. They aren’t generally available in game engines.engines.

3.3. Also using Excel, generate a column of 100 normally distributed Also using Excel, generate a column of 100 normally distributed random numbers with mean=0.5 and standard deviation=0.25. (Hint: random numbers with mean=0.5 and standard deviation=0.25. (Hint: Use the polar form.) Also, plot (histogram) these random numbers.Use the polar form.) Also, plot (histogram) these random numbers.

4.4. Create one plot (histogram) with all sets of random numbers.Create one plot (histogram) with all sets of random numbers.

5.5. Answer the following. What happens when UAnswer the following. What happens when U11=0?=0?

Page 2: 1 Exercise using Excel (see intro to Excel at end) 1. Using Excel’s rand() function, generate a column of 100 random numbers in the range -1 to +1. Plot

Creating and plotting a Creating and plotting a histogram using Excelhistogram using Excel

Steps:Steps:

1. Create column of data.1. Create column of data.

2. Create column of bins 2. Create column of bins (categories).(categories).

3. Select “array” of columns 3. Select “array” of columns for histogram.for histogram.

4. Type in 4. Type in =frequency( a2:a1001, =frequency( a2:a1001, e2:e23 ) and then type e2:e23 ) and then type ctrl+shift+Enter.ctrl+shift+Enter.

22

Page 3: 1 Exercise using Excel (see intro to Excel at end) 1. Using Excel’s rand() function, generate a column of 100 random numbers in the range -1 to +1. Plot

Histogram resultHistogram result

33

Page 4: 1 Exercise using Excel (see intro to Excel at end) 1. Using Excel’s rand() function, generate a column of 100 random numbers in the range -1 to +1. Plot

44

Exercise using Unity and C#Exercise using Unity and C#

Create a new class called MyRandomGenerator, and Create a new class called MyRandomGenerator, and implement the following:implement the following:

6. Write a function called uniform that, given a min and 6. Write a function called uniform that, given a min and max, generates a random number in the interval max, generates a random number in the interval [min,max].[min,max].

7. Write a function called normalPolar that, given a mean 7. Write a function called normalPolar that, given a mean and standard deviation, generates a random number and standard deviation, generates a random number sampled from that distribution.sampled from that distribution.

8. Write a function called normalCartesian that, given a 8. Write a function called normalCartesian that, given a mean and standard deviation, generates a random mean and standard deviation, generates a random number sampled from that distribution.number sampled from that distribution.

9. Using some built in function to get the time, determine 9. Using some built in function to get the time, determine how much time is required to generate 1000 random how much time is required to generate 1000 random numbers via each of the above methods. (If 1000 numbers via each of the above methods. (If 1000 random numbers can be generated in < 5 seconds, use random numbers can be generated in < 5 seconds, use a number larger than 1000.)a number larger than 1000.)

Page 5: 1 Exercise using Excel (see intro to Excel at end) 1. Using Excel’s rand() function, generate a column of 100 random numbers in the range -1 to +1. Plot

55

Exercise using Java, C/C++, or C#Exercise using Java, C/C++, or C#

10. Real numbers (float and double) and integers (int, 10. Real numbers (float and double) and integers (int, short, char, byte (in Java)) are represented using a finite short, char, byte (in Java)) are represented using a finite number of bits. Therefore, we can only have a finite number of bits. Therefore, we can only have a finite number of real numbers or integers. What is the number of real numbers or integers. What is the smallest non-zero number that can be represented by a smallest non-zero number that can be represented by a double? (Hint: Consult java.lang.Double or limits.h.)double? (Hint: Consult java.lang.Double or limits.h.)

11. Given the above, is there a maximal value for Z11. Given the above, is there a maximal value for Z00 in the in the equation below?equation below?

12. Is the range of possible values sampled from a uniform 12. Is the range of possible values sampled from a uniform distribution bounded or unbounded? Is the range of distribution bounded or unbounded? Is the range of possible values sampled from a normal distribution possible values sampled from a normal distribution bounded or unbounded? Is the range of values bounded or unbounded? Is the range of values generated by an implementation of the polar form of the generated by an implementation of the polar form of the Box-Muller algorithm bounded or unbounded?Box-Muller algorithm bounded or unbounded?

Page 6: 1 Exercise using Excel (see intro to Excel at end) 1. Using Excel’s rand() function, generate a column of 100 random numbers in the range -1 to +1. Plot

A VERY BRIEF INTRODUCTION A VERY BRIEF INTRODUCTION TO EXCELTO EXCEL

66

Page 7: 1 Exercise using Excel (see intro to Excel at end) 1. Using Excel’s rand() function, generate a column of 100 random numbers in the range -1 to +1. Plot

Values and calculationsValues and calculations

Constants in col A; expressions in col B (calling built in Constants in col A; expressions in col B (calling built in functions and referring to values in other cells..functions and referring to values in other cells..

77

Page 8: 1 Exercise using Excel (see intro to Excel at end) 1. Using Excel’s rand() function, generate a column of 100 random numbers in the range -1 to +1. Plot

Copy exp in B1, select multiple cells, and paste. Note Copy exp in B1, select multiple cells, and paste. Note cell changes automatically.cell changes automatically.

88

Page 9: 1 Exercise using Excel (see intro to Excel at end) 1. Using Excel’s rand() function, generate a column of 100 random numbers in the range -1 to +1. Plot

Use : to refer to multiple cells. For example, Use : to refer to multiple cells. For example, =sum(a1:a4) calculates the sum of the values in cells a1 =sum(a1:a4) calculates the sum of the values in cells a1 through a4.through a4.

Avoid automatic cell changes by using $.Avoid automatic cell changes by using $.

99