ST.
XAVIER'S COLLEGE
(Affiliated to Tribhuvan University)
Maitighar, Kathmandu
Computer Simulation and Modeling
Lab Report 2 and 3
SUBMITTED BY
Kshitiz Adhikari
Roll No.: 011BSCIT019
BSc.CSIT, 5th semester
SUBMITTED TO
Department of Computer Science and Information Technology
St.Xavier’s College
Maitighar, Kathmandu
Downloaded from CSIT Tutor
Mr. Ganesh Yogi
Lecturer
LAB #2
Title: Probability of Birth Child.
Initial Conditions:
No. of children checked = 4
No. of sample cases = 100
Value assigned for girl child = 1
Value assigned for boy child = 0
Theory:
In this simulation, it is attempted to study the probability of having a boy or a girl child during a
birth. The study starts with the condition that 4 births are checked at a time and the total number
of sampling is done 100 times. The children are represented as child 1, child 2, child 3, and child
4 for each birth. Then, the number of boys, girls is calculated in total and finally the probability is
calculated by dividing the number by total number of children.
Procedure:
Children are represented as child 1, child 2, child 3 and child 4 for each birth.
If the child is girl then it is represented using 1 and if the child is boy then it is
represented using 0. This is simulated by using =RANDBETWEEN(0,1) function in
EXCEL which gives either 0 or 1 randomly.
Then using the =SUM(X,Y) function, the number of girls are calculated for each
birth. Subtracting the number from 4 for each birth gives the number of boys.
Then the same function is again used to calculate the total number of boys and girls.
A pie chart is created using the number of boys and girls in total to display the ratio of
boys and girls.
Also number of cases with exactly 3 girls is calculated using COUNTIF( ) function.
Also the probability of having exacty 3 girls is also calculated by dividing the number
by number of cases.
Downloaded from CSIT Tutor
Sample Data:
Output:
No. of Cases with Exactly 3 girls
26
Probability of having exaclty 3 girls
0.26
total girls total boys
197 199
Downloaded from CSIT Tutor
CONCLUSION:
Hence, in this way the probability of child birth was simulated in Excel.
LAB #3
Title: To simulate the occurrences of numbers on three dices simultaneously
Initial Conditions:
We assume 3 dices with numbers 1 to 6 on them and we assume that all three dices will produce
a number when thrown.
Theory:
A dice is a cube with numbers 1 to 6 marked on its six faces used in board games such as Ludo,
Monopoly and so on. For the simulation, it is supposed that three dices are thrown
simultaneously. The occurrence of the numbers on three dices for a throw is to be simulated. This
is done by using =RANDBETWEEN(1,6) function which gives a number between 1 and 6
randomly.
Procedure:
Three boxes or cells are taken to be the dices.
Each box is given the function =RANDBETWEEN(1,6) to simulate them as dices.
Whenever F9 is pressed, the values of the dices change.
Output:
Sample Case 1:
4 2 1
Downloaded from CSIT Tutor
Sample Case 2:
5 3 5
Conclusion:
Hence, in this way the simulation of occurrence of numbers on 3 dices thrown simultaneously
was simulated.
Downloaded from CSIT Tutor
ST. XAVIER’S COLLEGE
(Affiliated to Tribhuvan University)
Maitighar, Kathmandu
Simulation and Modelling
Lab Assignment #4
SUBMITTED BY:
Siddhant Rimal
013BSCCSIT039
SUBMITTED TO
Mr. Ganesh Yogi
( Lecturer )
Department of Computer Science
Downloaded from CSIT Tutor
Submission Date: 29th March 2016
Downloaded from CSIT Tutor
Simulation and Modelling | Lab Assignment #4
STATEMENT: CALCULATE THE VALUE OF PI USING MONTE CARLO METHOD
ALGORITHM:
STEP-1: START
STEP-2: Plot Random points between -1 to 1 bounds on X-Axis and Y-axis for rectangle using
the formula:
=1-2*RAND()
STEP-3: Compute which points inside the rectangle bounds also fall under the area bounded
by circle inside it, using the formula:
For X-axis For Y-axis
=IF((X^2+Y^2)<1,X,0) =IF((X^2+Y^2)<1,Y,0)
STEP-4: If the points fall inside the circle, mark those points as TRUE(1) and FALSE(0) in next
column. Use the formula: =IF((X^2+Y^2)<1,1,0) to achieve this.
STEP-5: Calculate about 1000 such points for accuracy
STEP-6: Make a scatter diagram each for the points in Rectangle and points in Circle
STEP-7: Calculate the total number of points that lie inside the circle bound as found from
STEP-4
STEP-8: Calculate the value of PI using the formula:
=n/N*4
Where,
n = Total number of points inside circle bound
N = Total number of points used
SAMPLE DATA:
Fig: Sample Format for calculating value of PI using Monte Carlo method
Page 3
Downloaded from CSIT Tutor
Simulation and Modelling | Lab Assignment #4
OUTPUT:
Fig-1: Plotting points of Rectangle and Circle respectively on a graph
TOTAL POINTS INSIDE CIRCLE(n) 797
TOTAL NUMBER OF SAMPLES(N) 1000
n/N 0.797
Value of PI 3.188
Table-1: Calculating the value of PI the generated points
CONCLUSION:
Page 4
Downloaded from CSIT Tutor