chapter 7
Download
Skip this Video
Download Presentation
Chapter 7

Loading in 2 Seconds...

play fullscreen
1 / 5

Chapter 7 - PowerPoint PPT Presentation


  • 60 Views
  • Uploaded on

Chapter 7. Monte Carlo Methods to Compute Pi. Circle formed within a square, with unit radius so that square has sides 2*2. Ratio of the area of the circle to the square given by Points within square chosen randomly Score kept of how many points happen to lie within circle

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Chapter 7' - tatum-mclaughlin


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
monte carlo methods to compute pi
Monte Carlo Methods to Compute Pi
  • Circle formed within a square, with unit radius so that square has sides 2*2. Ratio of the area of the circle to the square given by
  • Points within square chosen randomly
  • Score kept of how many points happen to lie within circle
  • Fraction of points within the circle will be pi/4, given a sufficient number of randomly selected samples
monte carlo methods to compute pi2
Monte Carlo Methods to Compute Pi

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

int main(int argc, char* argv[])

{ double niter = 100000000;

double x,y;

int i;

int count=0;

double z;

double pi;

srand(time(NULL));

for (i=0; i<niter; ++i)

{ //get random points

x = (double)random()/RAND_MAX;

y = (double)random()/RAND_MAX;

z = sqrt((x*x)+(y*y));

if (z<=1)

{

++count;

}

}

pi = ((double)count/(double)niter)*4.0;

printf("Pi: %f\n", pi);

}

ad