-
Notifications
You must be signed in to change notification settings - Fork 0
/
monte-main.html
221 lines (216 loc) · 15 KB
/
monte-main.html
1
2
3
4
5
6
7
8
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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdn.jsdelivr.net/gh/CDNSFree2/PrismJS@latest/prism.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Monte-Carlo Estimation of Pi
</title>
<link rel="stylesheet" href="css/style_monte-main.css" />
<link rel="icon" type="image/x-icon" href="images/FavAndLogo.jpg">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/CDNSFree2/PrismJS@latest/prism.min.css">
</head>
<body>
<header>
<div class="logo"><img class="logo" src="images/andc_logo.jpg"></div>
<h1>V-Lab @ ANDC</h1>
<ul class="navigation">
<li><a href="index.html">Home</a></li>
<li><a href="index.html#labs_section">Labs</a></li>
<li><a href="index.html#team">Team</a></li>
<li><a href="contact.html">Contact Us</a></li>
<li><a href="https://www.andcollege.du.ac.in/" target="_blank" rel="noopener noreferrer">College Website</a>
</li>
</ul>
</header>
<div class="exp-heading">
<h1>Monte-Carlo Estimation of Pi</h1>
</div>
<nav>
<div class="boxq">
<a class="internal_link" href="#aim">
<img class="icon"
src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTBmpbB3jSjMF-FDgIL1E-eRN6eeCDLSsvoAQ&usqp=CAU"><br>
Aim</a>
</div>
<div class="boxq">
<a class="internal_link" href="#theory">
<img class="icon" src="https://cdn-icons-png.flaticon.com/512/1648/1648697.png"><br>
Theory</a>
</div>
<div class="boxq">
<a class="internal_link" href="#procedure">
<img class="icon"
src="https://cdn4.iconfinder.com/data/icons/project-management-1-11/65/23-512.png"><br>
Procedure</a>
</div>
<div class="boxq">
<a onclick="openTab()" class="internal_link" href="#code">
<img class="icon"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAyVBMVEX///8AhtQAVJ0AdcAAgtMAcL5/s+AAc787iskAh9UAfdEAhNMAf9IAUpwAbb0AfNEAabu0y+WErdUATZrs9fsASZgARJYARpfF2+7P3e6cwOAAS5kAQZUZfMNhmM709/u01O8AYatzseLV5/YAZrDu8/gAWqFGnNtnq+Axk9i92fHe7fiKtNsvhceLpsk9cKtxk76etdJUf7O/zuFlirlPn9yOv+eStdunxeNuotOoyOXU3+uvwdlchbcpZaamu9UAV6qCn8U2bKnbTY4BAAALhklEQVR4nO2de3uaSBTGq8EYGAh2EdFoq9F6i40xGt1dTZrNfv8PteAVYXDOGWaAdHn/6tPK5Qdz7qP98iVXrly5cuXKlStXrly5Ppl6qyEpkOXdJO0bkaT60FSIJ8UcVdO+GQmaLE1SOIiY1+20b0i0rrUTnydFuUv7loTqTlcKARFdfUj7toSpo+okCOgxauNe2rcmRL2hRuPbmeNv4HKqo0i+rTnq12nfYUyttJABBhmVddo3GUNrwuL73C7nYUx1MDRzHH5GlzOJdjA0xk/nctpdBJ8nRV+lfc8osR1MWLrSSfu2wXIjPJqv8IkygPoYuUB9jOYy+4XVZMnNt3uPGS862tdmHD5P2XY5dwrewYRfo6520gaJUEQJwcGojetpw1DU43cwFMbsuZzqKLYBBhgz5nJW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FgO97QJf4ko7wLL1bYs2xWUx6WxlTbXgHgi2rxdo5nIqQRUe0UozwLAlxOSlHeJY4iw6f0o/wLMXLAKxmBiI8SzGKDiupGj6uOIuOTEV4lhqIweNBWYvwLD0buCzHFt+ll632FGGOboT/HAZ4rj606BA2BkxeoAwg4xGepVdm0fHZHExYz81L5phCk1C8LhQdmanh4yoiA/hUEZ4lytYjyWPA5PV+3nZ084HM1fBx1Z7WTubI/vbvp1R/VvMmaoZlx9uRkmX1398GxcHb+2fNYHLlypUrV65cuXLlyvU/1n9VUE6S3XTYtAAAAABJRU5ErkJggg=="><br>
C++ Code</a>
</div>
<div class="boxq">
<a class="internal_link" href="#simulator">
<img class="icon"
src="https://thumbs.dreamstime.com/b/computer-simulation-icon-flat-style-vr-device-vector-illustration-black-round-background-long-shadow-technology-149360530.jpg"><br>
Simulator</a>
</div>
<div class="boxq">
<a class="internal_link" href="#observation">
<img class="icon"
src="https://img.freepik.com/free-vector/business-management-vector_53876-44131.jpg?size=338&ext=jpg"><br>
Observations</a>
</div>
<div class="boxq">
<a class="internal_link" href="#result">
<img class="icon"
src="https://cdn4.iconfinder.com/data/icons/collection-of-online-business-icons/64/Board_Chart_Results_Business-512.png"><br>
Result</a>
</div>
<div class="boxq">
<a class="internal_link" href="#references">
<img class="icon" src="https://image.pngaaa.com/134/5592134-middle.png"><br>
References</a>
</div>
</nav>
<section id="exp">
<div class="container">
<div class="box" id="aim">
<div class="title">
<h2 class="heading">Aim</h2>
</div>
<div class="desc1">
<p class="desc">To calculate value of π using Monte-Carlo simulations.</p>
</div>
</div>
<div class="box" id="theory">
<div class="title">
<h1 class="heading">Theory</h1>
</div>
<div class="desc1">
<p class="desc">
<h2 class="desc-heading">What is Pi?</h2>
<p class="desc">Pi is the famous circle number approximately given by 3.14159…</p>
<p class="desc">It is the area of the unit circle (i.e. the circle with radius 1) or half the
perimeter of the unit circle.</p>
<h2 class="desc">What is a Monte-Carlo Simulation?</h2>
<p class="desc">Monte-Carlo Simulations are experiments or computational algorithms that rely on
sampling of random numbers. An experiment or a simulation of random numbers is repeated a large
number of times to estimate something that may be determined deterministically as well (such as
π, as it is a deterministic number, i.e. it does not depend on randomness or chance).</p>
<p class="desc">Monte-Carlo Simulations are used whenever calculating something in a deterministic
fashion is too computationally expensive or not feasible anymore. Or when you’re just too lazy
to compute something exactly.
And sometimes it is not even necessary to use Monte-Carlo Simulations and the only reason to use
them is to show how beautiful Math and Probabilities can be.</p>
</p>
</div>
</div>
<div class="box" id="procedure">
<div class="title">
<h2 class="heading">Procedure</h2>
</div>
<div class="desc1">
<ol class="desc">
<li>Initialize circle_points, square_points and interval to 0. </li>
<li>Generate random point x. </li>
<li>Generate random point y.</li>
<li>Calculate d = x*x + y*y.</li>
<li>If d <= 1, increment circle_points.</li>
<li>Increment square_points.</li>
<li>Increment interval.</li>
<li>Calculate pi = 4*(circle_points/square_points).</li>
<li>If Interval <= NO_OF_ITERATIONS, repeat from 2.</li>
<li>Terminate.</li>
</ol>
</div>
</div>
<div class="box" id="code">
<div class="title">
<h2 class="heading">C++ Code</h2>
</div>
<pre>
<code class="language-cpp line-numbers">
#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<iomanip>
using namespace std;
int main()
{
cout.setf(ios::fixed);
cout<<"------------------------------------------------------------"<<endl;
cout<<"x"<<setw(15)<<"y"<<setw(14)<<"circle_pt"<<setw(12)<<"square_pt"<<setw(10)<<"pi"<<endl;
cout<<"------------------------------------------------------------"<<endl;
int i, intrval=1000;
int cr_pt=0, sq_pt=0;
double x,y,pi,r;
srand(time(NULL));
for (i=0; (i<intrval); i++)
{
x=double((1+rand()%intrval))/intrval;
y=double((1+rand()%intrval))/intrval;
r= x*x + y*y;
if (r<=1)
cr_pt++;
sq_pt++;
pi=double(4*cr_pt)/sq_pt;
cout<<x<<setw(10)<<y<<setw(10)<<cr_pt<<setw(10)<<sq_pt<<setw(15)<<pi<<endl;
}
return 0;
}
</code></pre>
</div>
<div class="box" id="simulator">
<div class="title">
<h2 class="heading">Simulator</h2>
</div>
<a href="monte-sim.html">
<div class="desc1">
<p class="desc">To calculate value of π using Monte-Carlo simulations.</p>
</div>
</a>
</div>
<div class="box" id="observation">
<div class="title">
<h2 class="heading">Observations</h2>
</div>
<div class="desc1">
<p class="desc">Take Observations from simulator and tabulate it for π and Interval.
</div>
<div class="desc1">
<p class="desc">Plot a graph also. (π vs Interval).
</div>
<img class="obsv-image" src="images/newplot.png"/>
</div>
<div class="box" id="result">
<div class="title">
<h2 class="heading">Result</h2>
</div>
<div class="desc1">
<p class="desc">The value of π is--> 3.14159265359</p>
</div>
<div class="desc1">
<p class="desc">But, we take π approximately equal to 3.14.</p>
</div>
<div class="desc1">
<p class="desc">Any result coming in range 3.13 to 3.15 may be considered as successful simulation
of the method. </p>
</div>
</div>
<div class="box">
<div class="title" id="references">
<h2 class="heading">References</h2>
</div>
<div class="desc1">
<p class="desc"><a href="https://en.wikipedia.org/wiki/Monte_Carlo_method">Monte_Carlo_method-on
Wikipedia</a></p>
<p class="desc"><a href="https://brilliant.org/wiki/monte-carlo/">Monte_Carlo_method-on
Brilliant.org</a></p>
</div>
</div>
</div>
</section>
</body>
</html>