Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Students are encouraged to use online resources (such as Wikipedia) to obtain ad

ID: 3749672 • Letter: S

Question

Students are encouraged to use online resources (such as Wikipedia) to obtain additional information that is not covered in the lecture. No late problem set will be accepted. The following set of exercises is designed to train you in the basics of Monte Carlo (MC) simulations. You will also apply MC simulations to estimate and study the Ising model. For each exercise, show us how you came to your answer and result. We highly encourage you to make drawings where appropriate. The code should be attached in the solution as text I. Use Monte Carlo (Random Sampling) Method to Estimate (30 points) N: Attempts made edge length-1 number of randomly selected points). You should test under 10, 100, 1000, 10000, and 100000 attempts to monitor how your estimations converge to the actual value of (-3.1415926535 ). Show your code, plot the randomly selected points using two different colors (to differentiate the points inside or outside the circle) as shown above, and briefly discuss your observations

Explanation / Answer

CODE:

#include <iostream>

#include <bits/stdc++.h>

#define SIZE 10000

using namespace std;

int main(){

int interval, i;

double x, y, distorigin, pi;

int pointscir = 0, pointsquare = 0;

srand(time(NULL));

for (i = 0; i < (SIZE * SIZE); i++) {

x = double(rand() % (SIZE + 1)) / SIZE;

y = double(rand() % (SIZE + 1)) / SIZE;

distorigin = x * x + y * y;

if (distorigin <= 1)

pointscir++;

pointsquare++;

pi = double(4 * pointscir) / pointsquare;

cout << x << " " << y << " " << pointscir << " " << pointsquare << " - " << pi << endl << endl;

if (i < 20)

getchar();

}

  

cout << " Final Estimation of Pi : " << pi;

return 0;

}