Sunteți pe pagina 1din 4

Technology for Chapter 5: Simulation Modeling in EXCEL

Using Monte Carlo simulation, find the approximate area under the curve y= cos (x) over

x .
the interval
2
2
In EXCEL, we can obtain random numbers by using the commands
=RAND( ) This generates a random number between 0-1
=RANDBETWEEN(a,b) This generates a random number as an integer between integers
a and b.
2. Deterministic Models
Area Under the Curve
y=f(x)=cos(x) between [-pi/2,pi/2] and 0 < cos(x) <2

INPUT

The total number of random points, N. The nonnegative function, f(x),


the interval for x [a,b] and an interval for y [0,M] where M > max
f(x),a<x<b.

OUTPUT

The approximate area under the curve, f(x) over the interval [a,b]

Step 1. Specify the function, f(x) and set all counters at 0


Step 2.

For i from 1 to N do step 3-5


Step 3.

Calculate random coordinates in the rectangular region:


a<xi<b, 0<yi<M

Step 4.

Calculate f(xi)

Step 5.

Compare f(xi) and yi . If yi <f(xi) then increment counter by 1.


Otherwise, do not increment counter.

Step 6.
Stop

Estimate the area by

The plot:
ARea Under Curve, y=cos(x)
2.5

1.5
y

Series1
Series2
1

0.5

0
-2

-1.5

-1

-0.5

0.5

1.5

The EXCEL Output:


WE will do 100 iterations
Iterations x
y
cos(x)
Counter
1 0.614429 1.540378 0.817103
2 -0.85002 0.441809 0.659968
3 -0.8188 0.765603 0.683098
4 -0.30872 0.252463 0.952724
5 0.144953 1.165235 0.989513
6 1.34791 0.78889 0.221045
7 -0.92075 0.80286 0.605225
8 -0.80346 1.549956 0.69422

Area=
0
1
0
1
0
0
0
0

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

1.123038
0.016517
-0.55727
-0.11547
0.281017
-0.0893
0.101115
0.943464
0.4383
0.479334
0.681015
1.092832
1.280599
-1.07154
-1.18037
0.169521
-0.8702
0.805563
0.407147
-1.40656
0.861091
-1.07828
-0.70854
-0.80858
-1.35813
0.129367
0.541742
1.569562
-0.39275
0.933381
-1.10147
1.135168
-0.63194
1.346449
-0.18473
-1.24099
1.40858
-0.4021
-0.18665
-1.1329
-0.52515
1.151625
-0.11583
0.344953
0.335369
-0.12774
0.140517
-1.5645
1.031425
-0.40539

1.599954
1.309035
1.323064
1.867228
1.933094
0.202792
1.375639
0.436537
1.708847
0.722906
1.342153
1.13835
1.720611
0.638368
0.496891
1.172678
1.412704
0.66016
1.159312
1.726509
1.93269
1.01462
0.842768
0.607992
1.164469
0.022001
1.843163
1.972188
0.626702
0.615082
1.641888
1.931666
0.469944
1.809136
0.601631
0.301875
0.296831
0.152461
0.809951
1.506694
0.820476
1.995533
1.142185
1.62168
0.057127
1.939639
1.858858
0.57871
1.198667
0.409063

0.432946
0.999864
0.848701
0.99334
0.960774
0.996016
0.994892
0.586987
0.905474
0.887302
0.776934
0.459973
0.286141
0.47877
0.38058
0.985666
0.644677
0.692705
0.918254
0.163503
0.65161
0.472847
0.759316
0.690525
0.211066
0.991644
0.856812
0.001235
0.92386
0.59512
0.452289
0.42198
0.806883
0.22247
0.982987
0.323858
0.161505
0.92024
0.982631
0.424031
0.865247
0.407004
0.993299
0.941091
0.944289
0.991852
0.990144
0.006292
0.513597
0.91895

0
0
0
0
0
1
0
1
0
1
0
0
0
0
0
0
0
1
0
0
0
0
0
1
0
1
0
0
1
0
0
0
1
0
1
1
0
1
1
0
1
0
0
0
1
0
0
0
0
1

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

0.385851
0.361118
0.028197
-0.36456
1.014951
-1.16692
-0.75591
0.235928
-0.75303
-0.16025
-0.19885
1.430908
-0.35336
0.203093
-0.4178
1.126729
1.068207
1.397421
1.246464
0.519294
0.618243
1.42582
-0.94829
-0.25549
-0.66453
1.537315
-0.86081
-0.26018
-0.91526
-1.51533
-0.90347
0.172927
-1.31661
-1.27197
-0.3552
-0.66336
0.716202
-1.09445
-1.27475
1.333781
0.277686
0.809884

0.695823
1.329776
0.616062
0.92314
0.54559
0.213632
1.921474
1.5666
0.662003
1.214153
0.431417
1.812025
0.431691
1.674002
1.232741
0.850714
1.438019
1.362517
1.104458
1.306986
1.98601
1.456081
0.444797
1.500115
1.732754
0.217347
0.110344
0.149297
1.432271
0.725801
0.121623
1.646032
1.009301
1.8148
0.288139
0.583429
1.341714
1.065013
0.084976
0.829555
1.530661
1.129383

0.926478
0.935502
0.999602
0.934282
0.527662
0.392988
0.727645
0.972298
0.729618
0.987187
0.980293
0.139432
0.938216
0.979447
0.913983
0.429615
0.481696
0.172508
0.318676
0.86817
0.814898
0.144469
0.583074
0.967539
0.787208
0.033475
0.65182
0.966345
0.609586
0.055439
0.618887
0.985085
0.251456
0.294395
0.937578
0.78793
0.754304
0.458532
0.291742
0.234803
0.961692
0.689583

1
0
1
1
0
1
0
0
1
0
1
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
1
1
0
0
1
0
0
0
1
1
0
0
1
0
0
0
31

S-ar putea să vă placă și