Excel Exam Simulation
I have 1 hour exam
There would be 3 questions, I need answers back in an hour
I have attached reading material
Module 4: Some Common applications Table o content
1- Inventory System Simulation 2- The M-N Inventory System 3- Machine reliability study 4- Evaluation of integral
5 - Simulation of hitting a Target Case I: Inventory system simulation.
Introduction. The Inventory management is one of the crucial aspects for any manufacturing firm and well known
topic in both corporate and academic world. Inventory management involves a set of decisions that aim
at matching existing demand with the supply of products and materials over space and time in order to
achieve profitable operations. An inventory is considered as one of the major assets of a business and it
represents an investment that is tied up until the item is sold or used in the production of an item. It costs
money to store, track and insure inventory. Inventories that are not well managed can create significant
financial problems for a business, whether the problem results in an inventory glut or an inventory
shortage. Proper management of inventories would help to utilize capital more effectively.
Why Is Inventory Control Important?
If your business requires maintaining an inventory, you might sometimes feel like you're walking a
tightrope. Not having enough inventory means you run the risk of losing sales, while having too much
inventory is costly in more ways than one. That's why having an efficient inventory control system is so
important.
Avoiding Stock-outs.
One of the worst things you can do in business is to turn away customers -- people who are ready to give
you their money -- because you've run out of the item they want. "Stock outs" not only cost you money
from missed sales, they can also make you lose customers for good, as people resolve to take their
business somewhere that can satisfy their needs. An efficient inventory control system tracks how much
product you have in stock and forecasts how long your supplies will last based on sales activity. This
allows you to place orders far enough ahead of time to prevent stock-outs.
Overstock Hazards
When inventory isn't managed well, you can also wind up with overstock -- too much of certain items.
Overstock comes with its own set of problems. The longer an item sits unsold in inventory, the greater
the chance it will never sell at all, meaning you'll have to write it off, or at least discount it deeply.
Products go out of style or become obsolete. Perishable items spoil. Items that linger in storage get
damaged or stolen. And excessive inventory has to be stored, counted and handled, which can add
ongoing costs.
2
Working Capital Issues
Inventory is expensive to acquire. When you pay, say, $15 for an item from a supplier, you do so with
the expectation that you will soon sell the item for a higher price, allowing you to recoup the cost plus
some profit. As long as the item sits on the shelf, though, its value is locked up in inventory. That's $15
you can't use elsewhere in your business. So inventory control isn't just about managing the "stuff"
going in and out of your company; it's also about managing your working capital, keeping you from
having too much precious cash tied up in operations.
Manufacturer's Angle
Inventory control isn't just a concern for companies that deal in finished goods, such as retailers and
wholesalers. It's also critical for manufacturers, who maintain three types of inventory: raw materials,
works in process and finished goods. If you run out of an essential ingredient or component, production
will halt, which can be extremely costly. If you don't have a supply of finished goods on hand to fill
orders at they come in, you risk losing customers. Staying on top of inventory is essential if you're to
keep the line running and keep products moving out the door.
I-2: Analysis, Modeling and Simulation
Careful inventory management is critical to the financial health of businesses whose primary
venture is manufacturing or retailing. In retail and manufacturing companies, huge amounts
of time and $'s are expended in keeping and managing inventory. A simple graphical
representation of inventory system is shown in Figure 1 below
Basic concepts involved in inventory management. we will build an inventory model to
answer the following two questions:
• How much do we order? (see figure 1)
• When to order? - with the goal of minimizing the total inventory costs.
X: Flow rate in (order)
Inventory fluctuation in the Tank
is a function of (X-Y)
Y: Flow rate out (Demand)
I X: flow rate (i.e., gallons /hour)
Y = Demand rate ( used by customers)
Figure 1. A simple inventory system
3
In most basic inventory models we are going to make several important assumptions in order
to keep the model simple.
Assumptions:
• Only one item is considered.
• An entire order arrives at once.
• Shortages may or may not be allowed.
• The demand is probabilistic and its probability distribution is known
• The time value of money is zero.
• Price for items is not a function of order quantity (no Quantity discount)
• Lead-time is known and constant.
There are three basic types of inventory - raw materials, work-in-process, finished
goods. Our analysis may apply to any of the three with minor variations. The principle
remains the same. In inventory analysis, we work with two variables
a) Independent demand which in most cases is represented as a random variable since
we do not have any control on number of customers and their demand level.
Independent demand is most frequently associated with finished goods where the
demand is more or less unknown.
b) Dependent demand refers to those items (i.e., inventory level, demand for labor hours
and so on) which are determined as a function of the independent demand.
The costs associated with inventory fall into two broad categories or components. All
the costs associated with keeping stock in inventory is “lumped together as carrying cost (we
may also call it the holding cost component). All the costs associated with ordering and
delivering the stock is "lumped" together, and called the ordering cost component. Some
costs which may be included in the holding cost component are:
• opportunity cost
• taxes
• insurance
• storage
• shrinkage
Some costs which may be included in the ordering cost component are:
• ordering costs
• set-up costs
• transportation costs
• small lot costs
• stock-outs and backorders
4
To simulate a simple inventory system, we first build a mathematical (analytical) model.
Following typical conventions, we need some descriptions and shorthand notation for
variables used in the model (These notations are those used in different textbook in modeling
a general inventory system. The analysis may use alternative notations).
Order quantity (Q) - Number of units ordered, also called the lot or batch size.
Demand (D) - Usually the annual demand. You may need to convert available information
to annualized data.
Item Cost (C) - Purchase price of raw materials or value of finished goods or WIP.
Carrying charge rate (i) - Composite % or decimal fraction of the item's cost that reflects
the cost of keeping one unit in inventory for one year. Usually, but not always, expressed in
% per unit per year.
Holding Cost per unit (H) - Cost, in dollars, to keep one unit in inventory for one year, H =
i x C. Make sure you don't confuse this with the holding cost component.
Ordering Cost (Co) - Cost to place one order, not to be confused with the Ordering Cost
Component. Frequently, this is designated S, the set-up cost, when dealing with WIP or
finished goods inventory.
Lead Time (LT) - The time that elapses between placing an order and receipt of that order.
Re-Order Point (ROP) - The on-hand inventory level at which we should place the order for
the next batch.
Stock-out Cost (S)- The cost incurred when there is insufficient inventory.
1-3. M-N Inventory System simulation &&Assignment
An M-N inventory system, generally used by small companies, is a system that has an inventory review
every N time periods (i.e., every 20 days), and when we replenish, we always bring the inventory level
to A maximum of M units. At each N time units, the inventory level is checked and an order placed to
bring the inventory up to level M. The operation of the system (shown in Figure 2 below) is based on
the following assumptions
1)- The lead time (for ordering and receiving) is assumed zero
2)- There are two customers, Company A and B. Demand by these customers (called X and Y) are
random. Note that since X and Y are random, then total demand Z= X+Y is also random
3)- Shortages are backordered. This means, if we do not have it now, we will supply the customer
next period. 4)- At the end of time period “0” (initial inventory for period 1) = I0.
5
Time
Inventory level Figure 2. An M-N Inventory System
M
Io
Let: BINi = Beginning Inventory, period i
EINi = Ending Inventory, period i
Xi & Yi = Demand for the product by internal customers (Y), and external customers (X) in period
ORDi = Amount to order @ the end of period I (This is shown as Qi in the graph)
EXCi = Excess inventory, end of period i
SHTi = Shortage end of period i
n = # of replications
N = Time between orders ( we order every N units of
time) M = Max Inventory Level allowed
J = Number of time shortage happened
What you need to do:
a). Develop the equations (Models) of the system
b)- Use spreadsheet and simulation the system 100 tomes.
c)- From the output, for a given “M”, determine what % of time the end of period inventory will be
negative (need backordering). Develop a histogram of the variable “ENIi”
d)- If we want s safety stock of 50 units, what the optimum value of “M” should be?
HINT: How to use Spreadsheet To simulate this type of systems?
Step 1; We start in period 0 (this is for setting initial condition and getting ready to start period
( 1, 2, 3,…). Now let:
EIN0 = I0, then ORD0 = M-Io (this is because we are assuming that at the end of each period we
will order enough material to bring the total inventory to “M” for the start of next day). Enter
in top row of excel the following information for period “0”.
BIN0 =0, Z0 = 0, EIN0=I0, ORD0 =M -I0, EXC0 =0, and SHT0 =0
X1+Y1
X2+Y2
X3+Y3
X4+Y4
Q1
Q2 Q3
Q4 Q5 0 1
2
3 4
N N
N N
6
Row A B
Period Starting
1 Inventory
C D E F
Order Demand Ending Shortage
Quantity Inventory Units
Excess
Units
2
3
0
1
0
= E2 =M-E2
0
=Z
Io
=M-D3
0 0
=IF(E3>0, 0,E3) =IF(E3<0, 0,E3)
copy
Step 2; for periods 1, 2, 3,…n, find the value of different elements as follows;
BINi = EIN i --1 +ORD i –1 [i.e., beginning inventory on period 10 equals ending inventory of
period 9 plus what we receive (ordered before) beginning of period 10]
Xi is generated randomly This is generated randomly from the probability distribution of Z
EINi = BINi – Zi [i.e., ending inventory of say period 10 is equal to it beginning – demand In period 10]
ORDi = M – EINi [i.e., The amount we order (say at the beginning of period 10) must be enough to bring inventory level to “M” units
If EINi > 0, then EXCi = EINi, and SHTi = 0 and vice-vera
n excel worksheet, the simulation will proceed as in Table 1below.
,
Table 1
Note that in simulating an inventory system, the objective may be to determine response to many (other
than what is discussed here) managerial questions, including; calculating average or an
appropriate value for M, or testing validity of assumptions (on which this simulation is based),
and so on. In those cases, we have to modify some or all of the above equations (models)
Step 3; Run the simulation n times (n.>50). And
Step 4: Calculate system metrics/performance measures, including, A). Percent of time there was
shortage
B). Maximum or average shortage quantity
C). Probability distribution of shortage quantity D).
Probability distribution of order quantity
E) If we desire to have “K” units in inventory as safety stock, what the optimum value of “M”
should be
F). Others …………………………………
7
Problem 4A-1 Basic N_N Inventory Simulate the M-N inventory system, discussed above, with the following input data:
• I0 =120 units (initial Inventory)
• M=480 units
• N= 1 week (5 working days)
• X= Uniform distribution with Min =270 units/week and Max=350
Y(units/week) 160 175 195
Pr(Y) 0.40 0.32 0.28
What you need to do:
a). Develop the equations (Models) of the system
b)- Use spreadsheet and simulation the system 100 tomes.
c)- From the output, determine what % of time the end of period inventory will
be negative (need backordering). Develop a histogram of the variable “ENIi”
d)- If we want a safety stock of 50 units, what the optimum value of “M” should be?
Problem 4A-2: The newspaper seller's problem A classical inventory problem concerns the purchase and sale of newspapers. The paper seller
buys the papers for 33 cents each and sells them for 50 cents each. Newspapers not sold at the
end of the day are sold as scrap for 5 cents each. Newspapers can be purchased in bundles of
10. Thus, the paper seller can buy 50, 60, and so on. There are three types of news days,
“good,” “fair,” and “poor,” with probabilities of 0.35, 0.45, and 0.20, respectively. The
distribution of papers demanded on each of these days is given in Table 1 below. The problem
is to determine the optimal number of papers the newspaper seller should purchase. This
will be accomplished by simulating demands for 40 days and recording profits from sales
each day.
Table 1. Distribution of Newspapers Demanded
Demand
Demand Probability Distribution
Good Fair Poor
40 0.03 0.10 0.44
50 0.05 0.18 0.22
60 0.15 0.40 0.16
70 0.20 0.20 0.12
80 0.35 0.08 0.06
90 0.15 0.04 0.00
100 0.07 0.00 0.00
Problem 4A-3: Simulation of a Special (M, N) inventory system.
Consider a system where the inventory level follows the pattern of the probabilistic order-level
inventory system shown in Figure 2. Suppose that the maximum inventory level, M =11 units
ASSIGNMENT 4A
8
and the review period, N, is 5 days. The problem is to estimate, by simulation, the average ending units in inventory and the number of days when a shortage condition occurs. The
distribution of the number of units demanded per day is shown in Table 2. In this problem, lead
time is a random variable, as shown in Table 2. Assume that orders are placed at the close of
business day and are received for inventory at the beginning of business day as determined by
the lead time
Figure 2. Probabilistic Order level Inventory System Amount in inventory
Time
Table 2: Probability distribution of demand and lead time
Demand/day Probability Lead Time (Days) Probability 0 0.1 1 0.60
1 0.25 2 0.30
2 0.35 3 0.10 3 0.21
4 0.09
Part I: Estimate, by simulation, the average ending units in inventory and the number of days
when a shortage condition occurs.
Part II: a)- Extend the case for 15 more cycles and draw conclusions.
b)- Rework the example for 10 cycles with M = 10, and N=6
====================================
2. Simulating machine reliability
II-1)- What is Reliability?
Reliability refers to the % of time a machine is up and working (A machine may be down for a
number of reasons). For a brief discussion of reliability and related subjects, see he Appendix 1
at the end of this section.is presented below.
Q3
Time
Q2 Q1
9
EXAMPLE: Machine A is (on average) down 40 minutes per day (day of work = 8 hours).
The reliability factor = (8*60 -40)/(8*60) = 91.67 %
This says that, the machine is only 91.67% reliable and about
8.33% of time will be Idle
II-2) how to use simulation to determine reliability of a machine?
EXAMPLE: A machine has two different bearing that fail in service. The distribution of life (time between breakdowns) are as follows
life in minutes (ti)➔ 40 100 120
Probability ➔ 0.3 0.45 0.25
When a bearing fails, maintenance department is called to install a new bearing. Maintenance
jobs are started immediately after a breakdown. The time it takes to fix the problem is as
follows
Time to install a bearing (RTi)➔ 5 Min. 10Min. 15Min.
Probability ➔ 0.35 0.45 0.20
Note: When a Bearing fails, the company incurs two types of costs:
1) The machine becomes idle. This cost the company $20 an hour 2) We pay for a new bearing. The cost for bearing = $45
What is required.
1) Determine the reliability of the machine
2) Number of stoppage per day
3) Average cost of maintenance per day
4) What % of time the maintenance operator is busy working for this machine.
SOLUTION
First let us show the operation of the system on a time line
Let:
ti = time between arrival of successive failures on bearing #1, and
tĩ = time between arrival of successive failures on bearing #2
10
Figure 1 T=End of simulation
Repair Time
t1 t2 t3 \ Clock
0 Fail(A) Fail(B) Fail (A) Fail (A) Time t1̃ t2̃ t3̃
B Fails B Fails Clock Time
Fail B
Legend:
: This Symbol is used for Repair Time
: The (length of) inter-arrival s (Brown color for Bearing type A, and Green for B)
: Continuous Clock Time
Now we can generate ti and tĩ and on each case convert the numbers to clock hours. As shown
in Figure 1, above. This may be done as follows
Repair time
Number of Generate ti Clock# 1 generate tĩ Clock # 2 Bearing Bearing
Trials (Min) (Min) (min) (min) #1 (min) #2 (min)
------------- ---------------- ----------- ------------- ------------------- -------------------------
1 40 40 100 100 10 1 5
2 120 160 120 220 5 5
3 100 260 100 320 15 10
4 … …. …. … … ….
Totals 30 30
Conclusions:
a- T= Clock time = 320 +10 =330 min (See Figure 1). # of breakdowns = 6
b- Downtime = 30+30 = 60 minutes
c- Cost= $20*60min/60 = $20. Machine cost = (6) *$45 = $270 (for T min). Total cost = $270+$20 = $290
d- Operator busy time = (330 – 60) =270 ➔ Availability = 270/330 = 81,8% A Spreadsheet simulation format
A B C D E F
Number of
breakdown
ti (Time between
Breakdowns
Repair time
(RT)
Clock time
After repair
Clock time
Before repair
Cumulative
Down time
11
Run the simulation for 15 hours per day and answer the questions a, b, c, and d
(above) with the following additional assumptions:
1)- When there is a breakdown, in addition to repair time we spend X minutes for
testing and resetting up the system (X has a normal distribution with mean 10 and
standard deviation of 5 minutes)
2)- After every 4 hours of operations, we need to change a filter on the machine
which takes 20 minutes each time
==========================================================
APPENDIX 1
A brief Review of Reliability and Availability
Maintainability: It is the effort and cost of performing maintenance. It is affected by factors such as, the ease of access to equipment for maintenance, availability of spare parts and the skill level
required doing the maintenance. One measure of maintainability is Mean Time To Repair (MTTR). A high MTTR is an indication of low maintainability
MTTR= (Downtime for repair)/( Number of repairs)
Here, Downtime for repair includes
0 0 0 480 0 0
1
2
3
………
n
Totals ➔
Assignment 4B
12
a) Time waiting for repair TW
b) Time spent doing the repairs TR c) Time spent for testing and getting the equipment ready to resume production (of good
parts)
Note that in some organizations repair time is defined as the downtime for repair only.
Reliability:
It is the probability that the equipment will perform properly under normal operating
conditions for a given period of time. In some cases reliability is not defined over time but
over another measurement such as miles traveled etc.
One measure of reliability (R) is the probability of successive performance or R = ( Number of successes) / (Number of repetitions) Example 1: A machine produces 500 parts of which 480 are good, and then the machine is 480/500 = 96% reliable
Example 2: A machine used to test circuit boards for defects work 99% of the times (it misses 1% of all defective boards), then the machine is 99% reliable.
Availability: Availability is the proportion of time equipment is actually available to perform work out of the time it should be available one measure of availability (A) =MTBF / (MTBF-MTTR)
It is obvious that availability is increased through a combination of increasing MTBF,
decreasing MTTR or both. This relationship, while taking into account the repair-related
sources of downtime(MTTR), it ignores non-repair sources of downtime as a result, it
overstates the actual equipment availability. A better measure of availability is
A=( Actual running time)/ ( Planned running time)
Where, Planned Running Time= Total Plant Time- Planned Down Time Actual
Running Time= Planned Running Time- All Downtimes
Example: Suppose a plant 2 shifts (16 hrs) per weekday. During each shift, the plant has two hours of planned downtime Planned running time= 16-2(2)= 12 hrs Suppose the machine is stopped each day, an average of 110 minutes for setups and 75
minutes for breakdowns and repairs, then: Actual running time= 12(60)-(110+75=535 mins
13
The availability of equipment is thus A= 535/12(60)= 0.743 or 74.3%
Quality: Quality is defined as the degree by which product/services satisfy the user’s requirements. Quality of a product/service and reliability are dependent on each other. A high quality product will have a high reliability and vice versa.
Failure: Failure here simply means that equipment/component’s performance is not satisfactory. It can
also mean that equipment /component malfunctioning in some aspects or is completely
broken. A failure may be treated as random or deterministic by studying the physics of the
failure process. The more reliable equipment/component is, the less likely it will fail. The likelihood of
failure is shown with failure pattern (also called bath-tub-curve) which will be discussed later.
Mean Time Before Failure: A measure reliability and equipment failure is the mean time between failure (MTBF).
For equipment that can be repaired, MTBF represents the average time between failures. For equipment that cannot be repaired, it is average time to the first failure. If we assume a constant failure rate, then
MTBF=( Total running time)/ (Number of failure)
MTBF is usually determined on the basis of historical data on product/equipment downtime as shown below
| tw1 | tD1 | tw2 | tD2 | tw3 | tD3 | | tDn | Time line
Note: tW = System working, tD = System idle
MTBF = { ∑ Twi }/ n
Example: Twenty machines are operated for 100 hours. One machine fails after 60 hours and another after 70 hours. What is MTBF?
MTBF={ (20)(100)-[(100-70) +(100-60)]} /2 = 1930/2= =965 hours/failure
Alternatively MTBF= (18)(100)+70+60/2= 1930/2 = 965 hours/failure
Failure Distribution Reliability function
It is generally assumed that the probability distribution of tW is Exponential. And item will
not fail before t. Then
R(t)= e-λt (Here R(t) is the reliability function)
14
Where, 0 < = R(t) < =1
e = natural logarithmic base
t = specified time
λ=failure rate= 1/MTBF
Example:
If MTBF for a machine is 965 hours/failure, what is the reliability of the machine at 500
hours, 900 hours?
λ=1/965= 0.0010362
R(500)= e-(500)(0.0010362) = 0.596
R(900)=e-(900)(0.0010362) = 0.39
===========================================================
Case 3: Evaluation of Integral, Method 1
Consider the following polynomial. It is desired to evaluate the area under the curve from
x=0 to x =3. Use the method we discussed in class on Thursday. To assist you in this process,
below, I have provided a briefly explanation of the method and how you should apply it to this
(or any) function.
Objective:
Determining area under the above curve (integral) between Xmin and Xmax. This is the area
under the curve between point C and Point D. Suppose the equation of the curve [Y = f(X) ] is
very complex and could not be integrated, using simple integration rules. Therefore, we have
decided to use digital simulation to answer the problem. Y
Ymax.: A B
YE E
Figure 1. YR
Ymin C X E D X Xmin Xmax
Procedure: In Fig 1, p = a ratio defined as:
a)-p = (Area under the curve) (Total area of rectangle ABDC). (1)
15
b)-The area of the rectangle = (Xmax - Xmin)*( Ymax – Ymin).
c)- If p is known, then from equation (1),,
Area under the curve= (p)*(Area of rectangle ) =(p)*( CD x CA)
= (p)*[ (Xmax – Xmin )(Ymax - Ymin) ]
How to estimate p ?
Step 1: Generate a random number between Xmax and Xmin. Call it XE
Step 2: Substitute XE in Y = f(X) and find the value of Y. This is called YE
Step 3: Generate a random number between Ymax and Ymin. Call it YR (See Figure 2)
Step 4: Compare YR .with YE. . If YR ≤ YE, then, the point (XE, YR) is inside the curve,
(or under the curve) otherwise it is outside the curve . See Figure 2.
Example: In Fig. 2, point (XE, YR) is point F which is under the curve.
Step 5: Do steps 1 to 4 above, m times and count n = Number of times that, the
point was under the curve. After repeating m times, you can find p = n/m
Y
Ymax A B E
YE
Figure 2: YR F
Ymin C X E D X Xmin Xmax
How to determine the area of the rectangle ?
Area of the rectangle ABDC = (Xmax - Xmin)*( Ymax – Ymin). Note that in this equation;
• Xmax and Xmin are given quantities..
• Ymin = 0
• Ymax must be determined as follows:
To determine the value of Ymax, we can use one of the following methods: A). Find the derivative of the function Y = f(X) and set the derivative equal to zero. Assuming
it is possible to solve the equation, the solution will enable us to find all max and min
points of the function.
16
B). Use enumeration method. Determine the value of Y for different/all possible
values of X (see below) . Pick the largest value of Y and call it Ymax . For
instance we may change the values of X as follows
Values assigned to X : Xmin, 0.10 +Xmin , 0.20 +Xmin, 0.30 +Xmin,,……. Xmax
Note that since we are assuming it is not possible to use mathematical methods (i.e., using derivative of
the function) to determine the coordinates of the point where the function takes its maximum value, we
have to use an alternative method such as the one discussed in the previous paragraph. It should be noted
that, when we use this method, the Ymax obtained is an approximation and may not necessarily be equal
to the real maximum. However, it is possible to get as close to the real Maximum as possible if we
minimize the incremental increase from one (assigned) X value to the next one in the process.
Example Suppose the function we want to use simulation and determine the integral of that function is given as:
Y = 2X – X ² where 0 ≤ X ≤2. This implies that Xmax =2 and Xmin = 0 We can find Ymax by
assigning a series of possible values to X and calculating the value of Y for each X as follows:
Assign X = 0 0.1 0.2 0.3,………… 1, 1.1 1.2……………2
Calculate Y = 0 0.19 0.36 0.51 ………...1, 0.99 0.96…………..0
Ymax
Y
Therefore:
Xmax =2,
Xmin = 0 ,
Ymax =1, 1.0 Ymax Ymin =0.
Figure 3
X
0 1 2 (Xmax )
Therefore for this example, Area of rectangle = (2-0)*( 1-0) = 2
Use either method 1 or method 2 (discussed below) to estimate area under each curve.
ASSIGNMENTS 4C
17
A)-Use Monte Carlo simulation to approximate the integral B)- Use Monte Carlo simulation to approximate the area under the curve 4/(1+x2 ) Between x = 0.5 and x =2
III-2:Evaluation on Integral, Method 2(1)
An Overview
In this part we introduce an alternative method for estimating the area of a shape using the Monte
Carlo technique. The principle of a basic Monte Carlo estimation is this: imagine that we want to
integrate a one-dimensional function f(x) from aa to bb such as: b F= ∫ f(x)dx. a
As you may remember, the integral of a function f(x) can be interpreted as calculating the area
below the function's curve. This idea is illustrated in Figure 1. Now imagine that we just pick up
a random value, say x in the range [a,b], evaluate the function f(x) at x and multiply the result by
(b-a). Figure 2 shows what the result looks like: it's another rectangle (where f(x) is the height of
that rectangle and (b-a) its width), which in a way you can also look at a very crude
approximation of the area under the curve. If we evaluate the function at x1 (figure 3) we quite
drastically underestimate this area. If we evaluate the function at x2, we over-estimate the area.
But as we keep evaluating the function at different
Figure 1: the integral over the domain [a,b] can be seen as the area under the curve.
18
Figure 2: the curve can be evaluated at x and the result can be multiplied by (b - a).
If we pick random points between a and b, adding up the area of the rectangles and averaging
the sum, the resulting number gets closer and closer to the actual result of the integral. It's not
surprising in a way as the rectangles which are too large compensate for the rectangles which are
too small. And in fact, we can prove that summing them up and averaging their areas actually
converges to the integral "area" under the curve, as the number of samples used in the calculation
increases. This idea is illustrated in the following figure. The function was evaluated in four
different locations (In the simulation process, xi values must be generated randomly). The result
of the function as these four values of x randomly chosen, are then multiplied by (b-a), summed
up and averaged (we divide the sum by 4). The result can be considered as an approximation of
the actual integral.
19
Of course, as usual with Monte Carlo methods, this approximation converges to the integral
result as the number of rectangles or samples used increases.
We can formalize this idea with the following formula:
N-1
FN = (1/N) (b−a) ∑ f(Xi) (1) 0
N in equation (1), is the number of samples used (or number of trials in simulation) in the study
to estimate the area under the curve. FN is an approximation of area using N samples. As N
increases, the error of estimate approaches zero. This equation is called a basic Monte Carlo
estimator
Case 4. Simulation of hitting a target
In this case study we simulate a bombing mission where the actual location a bomb hits varies
from its target by a random amount defined by Normal distribution. The normal distribution is
used to estimate the random location the bomber hits each time. Recall that the Normal
distribution is symmetric around its mean with likely range determined by its standard deviation.
This is a classic use of normal distribution where the deviation from the mean (target) represent
error/ missing the target.
------------------------------------------------------------------------------
(1). https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/monte-
carlo-methods-in-practice/monte-carlo-integration
A Military Bomber must hit a target shown as a blue box in Figure 1. We want to use Digital
Simulation to estimate % of time the bomber will hit the target.
Assumptions: 1)- Bomber flies on Y access (as shown below) 2)- Real target is point “O” with X=Y=0
a). Deviation in X direction follows a Normal distribution with:
Mean = 0. & Standard Deviation = 150 meter
b). Similarly, deviations in Y direction follows a Normal Distribution with:
Mean = 0. & Standard deviation = 200 meter
Case study : Assignment: 4D-1
https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/monte-
20
Figure 1
Y Target inside this Square
X
a). Deviation in X direction follows a Normal distribution with:
Mean = 0. & Standard Deviation = 150 meter
b). Similarly, deviations in Y direction follows a Normal Distribution with:
Mean = 0. & Standard deviation = 200 meter
General Procedure to simulate the system.
1)- generate X and Y randomly (2)
2)- find out whether the point (X,Y) is inside the box or not,
3)- If it is inside the bob, add to count (numbers inside)
4)- Repeat steps 1, 2,, and 3, above “N” times. Suppose only M time your point was inside the box.
➔ Probability of hitting the target = M/N
Case Study 2.
In general, How to determine a randomly generated point is inside the target area or not.
Consider the following Example.
Case study 2 . Assignment 4D-2
21
EXAMPLE: Suppose You have generated X and Y Randomly (Point A ). And were planning to
hit the Target, which is inside the triangle OBC
Y
B
Y1 A
Yc
X
0 X1 C
Point is INSIDE or OUTSIDE the Target Area?
To determine answer to this question, we assume that the equation of Border lines ( like Line
BC) Are given. For example, in this case (above). Equation are:
• Line OC: Y=0
• Line OB: X=0
• Line BC: Y= 7 -1.75X ➔ Coordinated of B and C are: B:(0, 7), C: (4, 0)
Now you can use the following procedure to determine whether a point hit by the Bomber
(generated randomly) is inside or outside the OBC target area:
a)- Check to see if X1 (randomly generated) > XMax, if yes, point A is outside the triangular
area If it is not go to step b
b)- Substitute X1 in the equation of the line BC. This will give generate Yc ( Calculated
the value of “Y”)
c)- If y1 >Yc, then the point is outside the triangular area, if not it is inside
Problem #1: Simulate the system (Case study 1, Above) 50 times and estimate % of time the
Bomber will hit the target. Based on your simulation, which direction (Y or X) is the least
reliable/causes more Miss than the other
Problem 2: Solve problem #4A-3 ( see page 7, module 4), assuming that the distribution of
demand is as shown in Table 2 below. Note that you have to run the model at least 60 times in
order to get an accurate answer.
22
Table 2. Distribution of Newspapers Demanded
Demand Probability
40 0.10
50 0.18
60 0.40
70 0.20
80 0.08
90 0.04
100 0.00