SEE HERE:

See here:

See here:

# LECTRUE 1.2: DART GAME

Once we have specified the INPUT and the logic, we can run the simulation to see the outcomes. The OUTPUT is the measurements of the outcomes. For example, the mean profit and its 95 percent confidence internal. Typically it involves statistic analysis. Taking together, we have
$OUPUT = logic (INPUT)$.

To illustrate, we consider a dart game. Kobe is to play the dart game with his friend. The board is of two by two size, with the circle of radius one. Kobe is a lousy shooter. He can make each shot on the square board, beyond that his shots are random. His friend makes a generous offer: Kobe gets free beer if he hits in the circle. So what is the probability $p$ that Kobe gets free bee?

There are several ways to solve this problem. For example, since Kobe shots uniformly on the dart board, his chance of hitting the board is one. Given that, his chance of hitting in the circle would equal the ratio between the circle area and the board area: $p= \frac{\pi r^2}{2\times 2} = \pi/4$.

This approach requires the knowledge of the circle area formula and the value of pi. If you don’t, you can still figure out through experiments, e.g., by asking Kobe to shot. For example, If Kobe shots $N=100$ times, and you can count the number $n$ of times he hits in the circle. Then $p= \frac{n}{N}$.

When the sample size $N$ is large, it may be too costly or even infeasible to do real experiments. Instead, we can carry out on computer. We focus on a quarter of the board. First, specify the INPUT. In this case, we know there is only one random variable, the shot $(X,Y)\in [0,1]^2$, and $X, Y\sim [0,1]$. In Excel: RAND().

Next, we figure out the logic. For each shot $(X,Y)$, we need to know whether it is a hit. That is, $h= IF( d <1, 1, 0)$, where $d = \sqrt{ X^2 + Y^2}$ is the distance between the shot $(X,Y)$ and the center $(0,0)$. So $h$ is an indicator. In Excel: $h= IF( sqrt( X^2 + Y^2 )<1, 1, 0)$, or simply $h= 1*( sqrt( X^2 + Y^2 )<1)$.

To generate a sample, we replicate $N=1000$ shots. For each shot $(X_i,Y_i)$, we know whether it is a hit, $h_i =1$ or $0$. We then do statistic analysis. The total number of hits is $\sum_{i=1}^N h_i$, and the probability $p= \frac{ \sum_{i=1}^N h_i }{N}$.

# Lecture 1.1

Simulation is a way of thinking. Just as every story has actors, plots, and contexts, so does simulation. In a story, we want to know how the actors interact, under what context, and what is the outcome of their play. In simulation, random variables are our heroes, and we seek to understand how and why their interplay leads to certain outcomes.

For each simulation, we must first specify the relevant random variables. Like actors, they each have names and behaviors (personalities, characters). For example, Bernoulli, Binomial, and Normal are the names of typical random variables. Their behaviors are uniquely defined by their distribution functions—probability distribution function (PDF) $f$, or cumulative distribution function (CDF) $F$. Depending on the problem, either one can be pleasant to work with. Their relation is $F(x) = \int_{-\infty}^x f(t) dt.$

Second, we care about the context of the simulation. This is done by specifying the economic and other environmental parameters. For example, the time horizon, the production cost, and the market price. Along with the parameters of random variables, they constitute the INPUT of the simulation.

Third, we need to figure out the logic—the plot—of the simulation. That is, how the random variables interact in each context. This is the most important but least teachable part of the simulation, because the logic depends on the problem specifics, and there is no universal rule for all problems. We must analyze each on its own merit.