0% found this document useful (0 votes)
8 views12 pages

In Class

The document discusses the Linear Congruential Method (LCM) for generating pseudorandom numbers, detailing its formula, desirable properties of random number generators, and potential pitfalls along with mitigation strategies. It also covers simulation, its importance in real-world applications, and the differences between discrete-event and continuous simulation. Additionally, it explains single-server queueing systems, the M/M/1 queueing model assumptions, and includes examples of Monte Carlo simulation and sensitivity analysis in queueing systems.

Uploaded by

fungisaigurenje
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views12 pages

In Class

The document discusses the Linear Congruential Method (LCM) for generating pseudorandom numbers, detailing its formula, desirable properties of random number generators, and potential pitfalls along with mitigation strategies. It also covers simulation, its importance in real-world applications, and the differences between discrete-event and continuous simulation. Additionally, it explains single-server queueing systems, the M/M/1 queueing model assumptions, and includes examples of Monte Carlo simulation and sensitivity analysis in queueing systems.

Uploaded by

fungisaigurenje
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

INCLASS TEST

i. Explain the Linear Congruential Method (LCM) for generating


pseudorandom numbers. (10)

The Linear Congruential Method (LCM) is a technique used to


generate a sequence of pseudorandom numbers using a recurrence
relation:

X n+1=(a X n + c)mod m

Where:

 X n= current number

 a = multiplier

 c = increment

 m = modulus

 X 0= seed (starting value)

The generated numbers are then normalized to values between 0 and 1


using:
Xn
Un=
m
It is widely used because it is simple, fast, and easy to implement,
though not perfectly random.

ii. Describe N desirable properties of a good random number generator?


How does the LCM achieve these properties? (10)

Desirable Properties

 Uniformity – numbers should be evenly distributed.

 Independence – no predictable pattern between numbers.

 Long period – sequence should not repeat quickly.

 Efficiency – fast to compute.

 Reproducibility – same seed gives same results.

How LCM Achieves Them


 Proper choice of a , c , mensures uniform distribution.

 Mathematical formula reduces obvious patterns → partial


independence.

 Good parameters produce a maximum period of m .

 Uses simple arithmetic → very efficient.

 Uses seed → ensures reproducibility.

iii. Given the parameters ( a = 5, c = 3, m = 16 ) and ( X_0 = 7 ), generate


the first 5 pseudorandom numbers using the Linear Congruential Method.
(10)

X n+1=(5 X n +3)mod 16

Calculations:

1. X 1 =(5 ×7+ 3)mod 16=38 mod 16=6

2. X 2 =(5 ×6 +3)mod 16=33 mod 16=1

3. X 3 =(5 ×1+3) mod 16=8 mod 16=8

4. X 4=(5 ×8+3)mod 16=43 mod 16=11

5. X 5 =(5 ×11+3)mod 16=58 mod 16=10

Answer:

Sequence: 6, 1, 8, 11, 10

iv. Describe the potential pitfalls of using the Linear Congruential Method?
How can they be mitigated? (10)

Pitfalls

 Short repetition cycles (small period).

 Patterns may appear (not truly random).

 Poor parameter selection leads to bad results.

 Not suitable for high-precision simulations.

Mitigation

 Choose parameters carefully (e.g. large m , good a , c ).

 Use full-period conditions.


 Combine multiple generators.

 Use more advanced generators when needed

QUESTION 2

* Define simulation and explain its importance in real-world applications.


(5)

Simulation is the process of creating a model of a real-world system and


experimenting with it to study its behavior under different conditions over
time.

It imitates the operation of a real system using mathematical or computer-


based models

1. Reduces Cost

Simulation allows organizations to test systems without building the actual


system first.

Example:

 A factory can simulate a production line before purchasing


expensive machines.

2. Saves Time

Experiments can be performed faster than in real life.

Example:

 Traffic simulations can predict congestion in minutes instead of


waiting months for real observations.

3. Improves Decision Making

Managers can compare different alternatives and choose the best


solution.

Example:

 A supermarket can test different numbers of checkout counters to


reduce waiting time.

4. Helps Understand Complex Systems


Simulation makes it easier to study systems with many interacting parts.

Example:

 Weather forecasting systems simulate atmospheric conditions.

5. Reduces Risk

Dangerous or sensitive situations can be tested safely.

Example:

 Pilots use flight simulators for training instead of real aircraft during
emergencies.

6. Predicts Future Performance

Simulation helps estimate future outcomes under different scenarios.

Example:

 Banks simulate customer demand and cash flow.

7. Useful When Real Experimentation is Impossible

Some systems are too expensive, risky, or impossible to test directly.

Example:

 Space missions are simulated before launch.

* What are the advantages and disadvantages of simulation as a problem-


solving tool? (5) (notes)

* Describe the steps involved in a simulation study. (5)

* Differentiate between discrete-event simulation and continuous


simulation. Provide examples of each. (5)

Aspect Discrete-Event Simulation Continuous Simulation

A simulation where changes


A simulation where changes
Definition occur at specific points in time
occur continuously over time.
due to events.

Nature of State changes are sudden and State changes are smooth
Change distinct. and continuous.

Time Time jumps from one event to


Time changes continuously.
Handling another.

Focus Focuses on events such as Focuses on continuous


Aspect Discrete-Event Simulation Continuous Simulation

variables such as
arrivals or departures.
temperature or speed.

Common Queueing systems, banking Weather systems, chemical


Use systems, inventory systems. processes, population growth.

CHECK NOTES ON QUESTION 2

QUESTION 3

i. Define a single-server queueing system and list its key components. (5)

Single-Server Queueing System

A single-server queueing system is a waiting line system in which


customers arrive, wait in a queue if necessary, and are served by only one
server before leaving the system.

It is commonly represented as an M/M/1 queue.

Key Components of a Single-Server Queueing System

1. Arrival Process

Describes how customers enter the system.

Example:

 Customers arriving at a bank or supermarket.

Usually represented by the arrival rate λ .

2. Queue (Waiting Line)

The place where customers wait if the server is busy.

Example:

 People waiting in line at a clinic.

3. Server

The single service facility that serves customers one at a time.

Example:

 One cashier in a shop.


4. Service Process

Describes how customers are served and how long service takes.

Usually represented by the service rate μ.

5. Departure Process

Customers leave the system after being served.

Example:

 A customer leaving the bank after completing a transaction.

ii. Describe/State the assumptions of the M/M/1 queueing model? (3)

Assumptions of the M/M/1 Queueing Model

The M/M/1 queueing model is a single-server queueing system with the


following assumptions:

1. Poisson Arrivals (First M)

Customers arrive randomly according to a Poisson distribution with arrival


rate λ .

Meaning:

 Arrivals are independent.

 The number of arrivals varies randomly over time.

2. Exponential Service Times (Second M)

Service times follow an exponential distribution with service rate μ.

Meaning:

 Service duration is random.

 The probability of finishing service is memoryless.

3. One Server (1)

There is only one server serving customers one at a time.


Example:

 One cashier in a shop.

Other Common Assumptions

 Queue discipline is First Come First Served (FCFS).

 The queue capacity is unlimited.

 The customer population is infinite.

 Arrival rate is less than service rate:


λ< μ

iii. Differentiate between the M/M/1 and M/G/1 queueing models? (2)

Feature M/M/1 M/G/1

Service Exponenti General


time al distribution

Flexibility Less More

Complexit
simple More complex
y

iv. For an M/M/1 queueing system with an arrival rate ( \lambda ) of 4


customers per hour and a service rate ( \mu ) of 5 customers per hour,
calculate:

(a) The utilization factor ( \rho ).

Utilization ( ρ )
λ 4
ρ= = =0.8
μ 5
(b) The average number of customers in the system ( (L) ).

Average number in system (L)


λ 4
L= = =4
μ− λ 5−4

(c) The average time a customer spends in the system ( (W) ).

Average time in system (W)


1 1
W= = =1 hour
μ−λ 1
(d) The average number of customers in the queue ( (L_q) ).

Average number in queue (Lq)


2
λ 16
Lq = = =3.2
μ( μ−λ) 5× 1

(e) The average time a customer spends waiting in the queue ( (W_q) )

Average waiting time (Wq)


λ 4
W q= = =0.8 hours
μ (μ− λ) 5 ×1

 L=4

 W =1hour

 Lq=3.2

 W q=0.8 hours

QUESTION 4

function 𝑓(𝑥) = 𝑥^2 over the interval [0, 1].


i. Use Monte Carlo simulation to estimate the integral of a

(10)
Solution
Step 1: Define the function
f(x)=x^2
Step 2: Generate Random Numbers
Choose random values between 0 and 1.
Example random numbers:
2
Random x x

0.0
0.1
1

0.1
0.4
6

0.4
0.7
9

0.9 0.8
2
Random x x

0.2
0.5
5

Step 3: Find the Average of x 2


Add all values:
0.01+0.16+ 0.49+0.81+0.25
Calculate step-by-step:
0.01+0.16=0.170.17+ 0.49=0.66
0.66+ 0.81=1.471.47+ 0.25=1.72
Average:
1.72
=0.344
5
Step 4: Estimate the Integral
Monte Carlo estimate:
Integral ≈( b−a)× Average
where:
a=0 , b=1
So:
(1−0)× 0.344=0.344Final Answer
1

∫ x 2 dx ≈ 0.344
0

The estimate is close to the exact


value:
0.3333

ii. Develop a simulation model to analyse the impact of


changing the number of servers in a queueing system.
(5)
Step 1: Define the Problem
We want to study how changing the number of servers
affects:
* waiting time,
* queue length,
* and system performance.
Example Scenario
A bank has:
* customers arriving randomly,
* and tellers serving customers.
We want to compare:
* 1 teller,
* 2 tellers,
* 3 tellers.

Step 2: Define Inputs


Inputs may include:
* customer arrival rate,
* service rate,
* number of servers,
* simulation time.
Example:
* Arrival rate = 10 customers/hour
* Service rate = 12 customers/hour

Step 3: Define Outputs


Outputs to measure:
* average waiting time,
* average queue length,
* server utilization.
Step 4: Build the Simulation Logic
Simulation process:
text id="lsgywb"
Customer Arrives

Check for Free Server

If Busy → Join Queue
If Free → Receive Service

Customer Leaves
Step 5: Run Different Scenarios

Run simulation for:

* 1 server,
* 2 servers,
* 3 servers.
Compare results.
Expected Observation
As the number of servers increases:
* waiting time decreases,
* queue length decreases,
* customer satisfaction improves.
iii. Perform a sensitivity analysis on a simulation model to
determine the effect of varying input parameters.
(5)
Sensitivity analysis studies how changes in input values
affect simulation outputs.
It helps determine:
* which variables are most important,
* and how sensitive the system is to changes.
Example
Suppose we have a queueing simulation.

We vary:
* arrival rate,
* service rate,
* or number of servers.

Then observe changes in:


* waiting time,
* queue length,
* system utilization.

Step 1: Choose Input Parameter


Example:
* customer arrival rate.

Step 2: Change the Parameter


Test different values.

| Scenario | Arrival Rate |


| -------- | ----------------- |
|1 | 5 customers/hour |
|2 | 10 customers/hour |
|3 | 15 customers/hour |
Step 3: Run the Simulation
Run the model for each scenario.

Step 4: Record Outputs

Example outputs:

| Arrival Rate | Average Waiting Time |


| ------------ | -------------------- |
|5 | 2 minutes |
| 10 | 7 minutes |
| 15 | 20 minutes |

Step 5: Analyse Results

Observation:

* increasing arrival rate increases waiting time.

This means:

* the system is sensitive to arrival rate changes.

# Importance of Sensitivity Analysis

1. Identifies critical variables.

2. Helps improve decision making.

3. Shows system weaknesses.

4. Helps optimize performance.

5. Improves model understanding.

You might also like