SlideServe
Menu
Préférences
© SlideServe · v2026

A Brief Look at Random Numbers

glenna avatar
6 diapositives · 197 Views · Sep 15, 2014

This document outlines a method for estimating the value of π using random number generation within CSCI 317. It explains the geometric probability concept where points are randomly picked inside a square that encloses a circle. As each point's distance from the circle's center is computed, we determine how many points fall inside the circle. The ratio of points inside the circle to total points, multiplied by 4, approaches the value of π. The implementation in MATLAB is illustrated with graphics, demonstrating the convergence of the estimate with increased sample size.

A Brief Look at Random Numbers - slide 1
01 / 6A Brief Look at Random Numbers
1 / 17

Télécharger la présentation

A Brief Look at Random Numbers
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. A Brief Look at Random Numbers CSCI 317 Mike Heroux CSCI 317 Mike Heroux

  2. Computing Estimate of Pi • Area of circle C is AC = πr2. • Area of square S is AS = s2. • Pick random (x,y) pairs with x and y between (-1/2, 1/2). • Probability of (x, y) being inside C is AC / AS. • In our case: • AC = π(1/2)2 = π/4. • AS = 12 = 1. • AC / AS = π/4. Circle Radius r=1/2 (x, y) CSCI 317 Mike Heroux

  3. Algorithm to Estimate Pi • Get ntotal number random pairs (x, y). • For each pair: • Compute distance from center of circle: d = sqrt(x*x+y*y). • If d < radius of circle (d<1/2) increase count of points inside circle (ninside ) by 1. • Theory tells us: ninside / ntotal≈ π/4. • Multiplying both sides above by 4, we have: π ≈ 4* (ninside / ntotal ). CSCI 317 Mike Heroux

  4. Matlab Pi Estimator ‘mypi.m’ % Graphics (no C++ equivalent) pivals = zeros(size(mypivals)); pivals = pi; mypimin = min(mypivals); mypimax = max(mypivals); v = [0 ntry mypimin mypimax]; axis(v); plot([1:ntry],mypivals,[1:ntry],pivals); xlabel('Number of random samples'); ylabel('Estimate of Pi'); hold off nsample = 100000; ntry = 500; ntotal = 0; mypivals = zeros(ntry,1); xy = zeros(nsample,2); ninside = 0; % number of (x,y) within the circle for j=1:ntry % random x and y between -1/2 and 1/2 xy=rand(nsample,2) - 0.5; for k=1:nsample x = xy(k,1); y = xy(k,2); % distance from center of circle r = sqrt(x*x+y*y); if r <= 0.5 ninside = ninside + 1; end end ntotal = ntotal + nsample; mypivals(j) = 4*ninside/ntotal; end mypi_estimate = 4*ninside/ntotal CSCI 317 Mike Heroux

  5. Estimate vs. True Pi CSCI 317 Mike Heroux

  6. Monte Carlo Methods • Methods that use random numbers this way are called Monte Carlo methods. • Other simple applications: • Estimating the likelihood of random events. • Example: Poker hands: What is the probability of 3-of-a-kind? • Modeling atomic states. • Approximate answers to otherwise intractable problems. CSCI 317 Mike Heroux