Must be solved in C++ code Using C++: Determining Expertmentally: Recall that is
ID: 3595732 • Letter: M
Question
Must be solved in C++ code
Using C++: Determining Expertmentally: Recall that is the ratio of a cicle's cicumference to its diameter and that we can calculate the area of a circle with the formula A=m2. Below is a drle engribed within the unit square. 1. What is the ratio of the areas of the enscnbed circle to that of the unit square? 2. If we pick a random point within the unit square what is the probability that the point will also lie within the circle? 3. If we repeat this experiment an arbitrarily large number of times the ratio of the number of points which lie within the circle to the number of points within the unit square (all of them) will approach /4 4. Using the language structures we have discussed wite a program that will do the above experiment an arbitary (determined at run-time) number of times and report back the approximate value of .Explanation / Answer
The ratio of area of circle to square is:
area of square = s^2 //assumin the side of the square is s
area of circle = pi * (s/2)^2
Ratio will be = pi/4
2. The probability that a point lies with in the circle will
also be equal to the ratio of area of circle to area of square as per
monte carlo approximation.
4. A program in c++
#include<iostream>
#include<math.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int main(){
srand(time(NULL));
double x,y;
double ratio;
int count;
long loop_cnt;
count = 0;
loop_cnt = 0;
while(loop_cnt <4000000000){ // Assuming r = 20;
x = rand() % 20;
y = rand() % 20;
if (sqrt(x*x + y*y) < 20)
count++;
loop_cnt++;
cout << loop_cnt << endl;
}
cout << "The value is " << count/loop_cnt << endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.