Pi & Random Numbers Perl Programming - Fort Collins, CO Copyright © XTR Systems, LLC Computing Pi & Random Numbers Instructor: Joseph DiVerdi, Ph.D., M.B.A.

Slides:



Advertisements
Similar presentations
Rare Events, Probability and Sample Size. Rare Events An event E is rare if its probability is very small, that is, if Pr{E} ≈ 0. Rare events require.
Advertisements

Thermo & Stat Mech - Spring 2006 Class 16 1 Thermodynamics and Statistical Mechanics Probabilities.
Monte Carlo Simulation of the Craps Dice Game Sencer Koç.
Dice Games & Probabilities. Thermo & Stat Mech - Spring 2006 Class 16 Dice Games l One die has 6 faces. So, the probabilities associated with a dice game.
Exercises (1) 1. In the usual dice experiment, let A, B and C, be the following events: A = {1,7,6} and B = {1,2,7,5} and C = {3,5} Find the following:
Monte-Carlo Techniques Roger Crawfis. June 9, 2015OSU/CIS 5412 Monte-Carlo Integration Overview 1.Generating Psuedo-Random Numbers 2.Multidimensional.
Monte Carlo Simulation and Risk Analysis James F. Wright, Ph.D.
1 Random numbers Random  completely unpredictable. No way to determine in advance what value will be chosen from a set of equally probable elements. Impossible.
Introduction to JavaScript Form Verification - Fort Collins, CO Copyright © XTR Systems, LLC Verifying Submitted Form Data with JavaScript Instructor:
Webmaster Overview Fort Collins, CO Copyright © XTR Systems, LLC Webmaster Overview Instructor: Joseph DiVerdi, Ph.D., MBA.
Internet & Web Overview Fort Collins, CO Copyright © XTR Systems, LLC How the WWW & the Internet Work or "I didn't know they aren't the same thing." Instructor:
Using Embedded JavaScript Fort Collins, CO Copyright © XTR Systems, LLC Embedding JavaScript In HTML Instructor: Joseph DiVerdi, Ph.D., MBA.
Using JavaScript in FORMs Fort Collins, CO Copyright © XTR Systems, LLC Learning to Use JavaScript in HTML FORMs Instructor: Joseph DiVerdi, Ph.D., MBA.
Understanding Linux Directories Fort Collins, CO Copyright © XTR Systems, LLC Understanding the Linux Directory Structure Instructor: Joseph DiVerdi, Ph.D.,
CSU - DCE Advanced Perl CGI Operation - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) on the.
CSU - DCE Webmaster I HTML - Forms - Fort Collins, CO Copyright © XTR Systems, LLC Designing Web Sites using HTML - Introduction to Forms Instructor:
Kinetic Monte Carlo Triangular lattice. Diffusion Thermodynamic factor Self Diffusion Coefficient.
Web Site Access Control with Apache Fort Collins, CO Copyright © XTR Systems, LLC Web Site Access Control Using the Apache Web Server Instructor: Joseph.
Monte Carlo Methods.
Monte Carlo Methods Versatile methods for analyzing the behavior of some activity, plan or process that involves uncertainty.
Simulation Time-stepping and Monte Carlo Methods Random Number Generation Shirley Moore CS 1401 Spring 2013 March 26, 2013.
Copyright © 2010 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin Chapter 5 Discrete Random Variables.
CSU - DCE Advanced Perl First Web Page - Fort Collins, CO Copyright © XTR Systems, LLC Creating Your First Web Page Instructor: Joseph DiVerdi,
CSU - DCE Advanced Perl Web Images - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to Imaging on the World Wide Web Instructor: Joseph.
If..else Use random numbers to compute an approximation of pi Simulation of a special game of darts Randomly place darts on the board pi can be computed.
Section 5.4 Sampling Distributions and the Central Limit Theorem Larson/Farber 4th ed.
Cryptography Overview and PGP - Fort Collins, CO Copyright © XTR Systems, LLC Cryptography Overview and Pretty Good Privacy Instructor: Joseph DiVerdi,
Fundamentals of WWW Imaging Fort Collins, CO Copyright © XTR Systems, LLC Fundamentals of Web Imaging Instructor: Joseph DiVerdi, Ph.D., MBA.
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) Instructor: Joseph DiVerdi,
Lesson 5 Menu 1.Find the area of the figure. Round to the nearest tenth if necessary. 2.Find the area of the figure. Round to the nearest tenth if necessary.
A Little Bit About Cookies Fort Collins, CO Copyright © XTR Systems, LLC A Little Bit About Cookies Instructor: Joseph DiVerdi, Ph.D., M.B.A.
Fundamentals of WWW Imaging Fort Collins, CO Copyright © XTR Systems, LLC Fundamentals of Web Imaging Instructor: Joseph DiVerdi, Ph.D., MBA.
Intermediate CGI & CGI.pm Webmaster II - Fort Collins, CO Copyright © XTR Systems, LLC CGI Programming & The CGI.pm Perl Module Instructor: Joseph DiVerdi,
Introduction & Overview Introduction to PHP - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to & Overview of PHP Instructor: Joseph DiVerdi,
CSU - DCE Webmaster I Scaling Issues - Fort Collins, CO Copyright © XTR Systems, LLC Web Site Scaling Issues (or Size Really Does Matter) Instructor:
Point Pattern Analysis Point Patterns fall between the two extremes, highly clustered and highly dispersed. Most tests of point patterns compare the observed.
CSU - DCE Webmaster I HTML - Tables - Fort Collins, CO Copyright © XTR Systems, LLC Designing Web Sites using HTML - Introduction to Tables Instructor:
CSU - DCE Advanced Perl WWW Overview - Fort Collins, CO Copyright © XTR Systems, LLC How the WWW & the Internet Work Instructor: Joseph DiVerdi,
CSU - DCE Introduction to CSS CSS Colors - Fort Collins, CO Copyright © XTR Systems, LLC Cascading Style Sheets - Specifying Color Instructor: Joseph.
Creating a Remotely-Hosted Web Site Fort Collins, CO Copyright © XTR Systems, LLC Creating Your First Remotely-Hosted Web Site Instructor: Joseph DiVerdi,
Computer simulation Sep. 9, QUIZ 2 Determine whether the following experiments have discrete or continuous out comes A fair die is tossed and the.
Introduction of XML & XHTML Webmaster - Fort Collins, CO Copyright © XTR Systems, LLC Overview of XML & XHTML Instructor: Joseph DiVerdi, Ph.D., MBA.
Random numbers in C++ Nobody knows what’s next....
Introduction to JavaScript Fort Collins, CO Copyright © XTR Systems, LLC Introduction to JavaScript Programming Instructor: Joseph DiVerdi, Ph.D., MBA.
Javier Junquera Importance sampling Monte Carlo. Cambridge University Press, Cambridge, 2002 ISBN Bibliography.
Webmaster II Introductions - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to Webmaster II Instructor: Joseph DiVerdi, Ph.D., MBA.
CSU - DCE Introduction to CSS CSS Length - Fort Collins, CO Copyright © XTR Systems, LLC Cascading Style Sheets - Specifying Length Instructor:
GEOMETRY HELP The length of the segment between 2 and 10 is 10 – 2 = 8. The length of the ruler is 12. P(landing between 2 and 10) = =, or length of favorable.
Copyright © 2011 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin Chapter 5 Discrete Random Variables.
CSU - DCE Introduction to CSS CSS URLs - Fort Collins, CO Copyright © XTR Systems, LLC Cascading Style Sheets - Specifying URLs Instructor: Joseph.
Probability and Simulation The Study of Randomness.
CSU - DCE Advanced Perl Introductions - Fort Collins, CO Copyright © XTR Systems, LLC Advanced Perl Programming Instructor: Joseph DiVerdi, Ph.D.
Geometric probability Objective: To use segment and area models to find the probability of events.
PHP Introduction & Overview Fort Collins, CO Copyright © XTR Systems, LLC Introduction to & Overview of PHP Instructor: Joseph DiVerdi, Ph.D., MBA.
JavaScript Syntax Fort Collins, CO Copyright © XTR Systems, LLC Introduction to JavaScript Syntax Instructor: Joseph DiVerdi, Ph.D., MBA.
COMPUTERS SIMULATION IN MATHEMATICS EDUCATION Dr. Ronit Hoffmann Kibbutzim College of Education, Israel.
Intro CS – Probability and Random Numbers Lesson Plan 6a.
CSU - DCE Webmaster JavaScript Class - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to Object-Oriented Perl and CGI.pm Instructor:
10.Deterministic Randomness 1.Random Sequences Random Sequences A sequence of numbers r 1, r 2,... is random if there are no discernible patterns.
CSU - DCE Webmaster I HTML & URLs - Fort Collins, CO Copyright © XTR Systems, LLC Designing Web Sites With HTML - Using Effective Links Instructor:
Linux & UNIX OS Overview Fort Collins, CO Copyright © XTR Systems, LLC Overview of the Linux & UNIX Operating Systems Instructor: Joseph DiVerdi, Ph.D.,
Monte Carlo Methods Some example applications in C++
Dice Games & Probabilities
Geometric Probability
Intro CS – Probability and Random Numbers
Dice Games & Probabilities
Random numbers What does it mean for a number to be random?
Random numbers What does it mean for a number to be random?
Monte Carlo Methods A so-called “embarrassingly parallel” computation as it decomposes into obviously independent tasks that can be done in parallel without.
Random numbers What does it mean for a number to be random?
Presentation transcript:

Pi & Random Numbers Perl Programming - Fort Collins, CO Copyright © XTR Systems, LLC Computing Pi & Random Numbers Instructor: Joseph DiVerdi, Ph.D., M.B.A.

Pi & Random Numbers Perl Programming - Fort Collins, CO Copyright © XTR Systems, LLC Calculating the Value of π Use a Square With an Inscribed Circle Area circle = πr 2 Area square = 4r 2 Area circle / Area square = πr 2 / 4r 2 4 * Area circle / Area square = π r

Pi & Random Numbers Perl Programming - Fort Collins, CO Copyright © XTR Systems, LLC Calculating the Value of π Calculate Areas by Placing & Counting Points –Points Are Either Placed At Random –Just Like a Barroom Dart Board On a Square Lattice –An Orderly and Evenly Spaced Set of Points The Area Is Approximated by the Point Count –To Compute π A Program Must Place A Point Determine If the Point Is in or on the Circle –Every Point Is on the Square Keep Count of the Points Compute The Final Value

Pi & Random Numbers Perl Programming - Fort Collins, CO Copyright © XTR Systems, LLC Calculating the Value of π Calculate Areas By Placing & Counting Points –The Area Is Approximated By The Number of Points Can Be Performed Either of Two Ways: Random Pattern (Monte Carlo) Regular Pattern (Lattice)

Pi & Random Numbers Perl Programming - Fort Collins, CO Copyright © XTR Systems, LLC Heart Of The Computation Equation Of A Circle x 2 + y 2 = r 2 sqrt(x 2 + y 2 ) = r If sqrt(x 2 + y 2 ) <= r –Then The Point Is On The Circle (r, r) (r, -r) (-r, r) (-r, -r) (0, 0) (x, y) r

Pi & Random Numbers Perl Programming - Fort Collins, CO Copyright © XTR Systems, LLC Simplification & Speed Setting r = 1 x 2 + y 2 = 1 2 = 1 If x 2 + y 2 <= 1 Then The Point Is On The Circle –That's Much Faster (1, 1) (1, -1) (-1, 1) (-1, -1) (0, 0)

Pi & Random Numbers Perl Programming - Fort Collins, CO Copyright © XTR Systems, LLC More Simplification All Four Quarters Are Identical Only Necessary to Compute One Quarter (1, 1) (1, 0) (0, 0) (0, 1) (1, 1) (1, -1) (-1, 1) (-1, -1) (0, 0)

Pi & Random Numbers Perl Programming - Fort Collins, CO Copyright © XTR Systems, LLC More Simplification All Four Quarters Are Identical Only Necessary to Compute One Quarter (1, 1) (1, 0) (0, 0) (0, 1) (1, 1) (1, 0) (0, 1) (0, 0)

Pi & Random Numbers Perl Programming - Fort Collins, CO Copyright © XTR Systems, LLC Using Lattice Method Compute # Of Points On Each Edge Compute Delta For Each Point Use foreach Loop foreach my $x_point (0..$count - 1) { $x = $x_point / ($count - 1); foreach my $y_point (0..$count - 1) { $x = $y_point / ($count - 1); $area_square++; $area_circle++ if... ; } (1, 0) (1, 1)(0, 1) (0, 0)

Pi & Random Numbers Perl Programming - Fort Collins, CO Copyright © XTR Systems, LLC Using Lattice Method See Source Code –On Course Web Site

Pi & Random Numbers Perl Programming - Fort Collins, CO Copyright © XTR Systems, LLC Using Lattice Method 4 points9 points16 points25 points 4 * 3 / 4 = * 6 / 9 = * 11 / 16 = * 17 / 25 = 2.72

Pi & Random Numbers Perl Programming - Fort Collins, CO Copyright © XTR Systems, LLC Using Monte Carlo Method We Need To Discuss Random Number Issues (1, 1) (1, 0) (0, 1) (0, 0) while ($area_square < $limit) { $x = some random number $y = some random number $area_square++; $area_circle++ if... ; }

Pi & Random Numbers Perl Programming - Fort Collins, CO Copyright © XTR Systems, LLC Random Numbers Properties –Defined Over a Specific Interval –Equally Distributed - Equal Probability –NO Correlation Between Subsequent Values Consider a Legal Die (One of a Pair of Dice) –Not Loaded –1 <= i <= 6 –P 1 = 1/6, …, P 6 = 1/6 –If 1, 1, 1, 1, 1, 1 then P 1 = 1/6

Pi & Random Numbers Perl Programming - Fort Collins, CO Copyright © XTR Systems, LLC Random Numbers in Perl Use srand Once to “Seed” The rand Function –srand time; Is NOT a Good Seed! –srand time ^ ($$ + $$ ^ 16); Is Better Use rand Function to Get a Random Value –Use TrulyRandom Module for Serious Work $float_value1 = rand $limit; $float_value2 = rand $limit; 0 <= $float_value < $limit

Pi & Random Numbers Perl Programming - Fort Collins, CO Copyright © XTR Systems, LLC Using Monte-Carlo Method See Source Code –On Course Web Site