Lazzarini, Buffon’s needle, and Pi. Buffon’s needle From blem.html.

Slides:



Advertisements
Similar presentations
Modular Programming With Functions
Advertisements

Craps. /* * file : Craps.java * file : Craps.java * author: george j. grevera, ph.d. * author: george j. grevera, ph.d. * desc. : program to simulate.
Programmer-defined classes Part 2. Topics Returning objects from methods The this keyword Overloading methods Class methods Packaging classes Javadoc.
Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-2: Arrays as Parameters reading: , 3.3 self-checks: Ch. 7 #5, 8,
Program Design. Objectives Students should understand the basic steps in the programming process. Students should understand the need for good design.
HW 4 EECS 110.
BUFFON’S NEEDLE PROBLEM Abby Yinger Probability theory and stochastic processes for additional applications Geometric probability and stochastic geometry.
12.1 Inference for A Population Proportion.  Calculate and analyze a one proportion z-test in order to generalize about an unknown population proportion.
Programming by Example Version 1.0. Objectives Take a small computing problem, and walk through the process of developing a solution. Investigate the.
COMP 110 Introduction to Programming Mr. Joshua Stough October 8, 2007.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs with Scanner.
Writing methods and Java Statements. Java program import package; // comments and /* … */ and /** javadoc here */ public class Name { // instance variables.
Copyright 2006 by Pearson Education 1 reading: 4.1 Cumulative sum.
CS100J 11 September 2003 For more info: The "at" was made famous by Ray Tomlinson, a researcher at BBN in Boston.
Writing methods. Calling Methods nameOfMethod(parameters) if method returns something, use that value Math.pow(2, 3) returns 8 System.out.println(Math.pow(2,
Buffon’s Needle Todd Savage. Buffon's needle problem asks to find the probability that a needle of length ‘l’ will land on a line, given a floor with.
Buffon’s Needle Problem Grant Weller Math 402. Georges-Louis Leclerc, Comte de Buffon French naturalist, mathematician, biologist, cosmologist, and author.
CSE 1301 Lecture 11 Object Oriented Programming Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Chapter 6: Iteration Part 2. Create triangle pattern [] [][] [][][] [][][][] Loop through rows for (int i = 1; i
CS 106 Introduction to Computer Science I 03 / 19 / 2007 Instructor: Michael Eckmann.
Squares, Square Roots, Cube Roots, & Rational vs. Irrational Numbers.
TechConnect Concrete TechConnect Concrete Math. Place Values.
Nesting Loops (That’s loops inside of loops. Why not?)
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Methods (a.k.a. Functions)
Activity 1-10 : Buffon’s Needle
First Programs CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Writing Static Methods Up until now, we have been USING (calling) static methods that other people have written. Now, we will start CREATING our own static.
A Problem in Geometric Probability: Buffon’s Needle Problem
1 Building Java Programs Chapter 3: Introduction to Parameters and Objects These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
12.1 Inference for A Population Proportion.  Calculate and analyze a one proportion z-test in order to generalize about an unknown population proportion.
Power Point on Area - 5 th Grade. What is a Quadrilateral?
A: A: double “4” A: “34” 4.
Prabhas Chongstitvatana1 Numerical probabilistic The answer is always an approximation.
1 Static Variable and Method Lecture 9 by Dr. Norazah Yusof.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
Methods II Material from Chapters 5 & 6. Note on the Slides  We have started to learn how to write non- program Java files  classes with functions/methods,
Simple Console Output. What we will briefly discuss System.out.println( … ) System.out.print( … ) System.out.printf( … )
Simple Console Output CS 21a. What we will briefly discuss System.out.println( … ) System.out.print( … ) System.out.printf( … )
CS305j Introduction to Computing Parameters and Methods 1 Topic 8 Parameters and Methods "We're flooding people with information. We need to feed it through.
Chapter 5 – Part 3 Conditionals and Loops. © 2004 Pearson Addison-Wesley. All rights reserved2/19 Outline The if Statement and Conditions Other Conditional.
Chapter 7 Iteration. Chapter Goals To be able to program loops with the while, for, and do statements To avoid infinite loops and off-by-one errors To.
SOLVING ALGEBRAIC EXPRESSIONS
Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
Buffon’s Needle and Probability Birthdays What is the chance that at least two people in this room have the same birthday?
Buffon's needle problem
8.NS.2 The Number System Part 2.
AKA the birth, life, and death of variables.
Proportions.
Method Mark and Lyubo.
Control Statement Examples
Object Oriented Programming
מבוא למדעי המחשב, סמסטר א', תשע"א תרגול מס' 2
Notes Over 11.4 Simplifying a Rational Expression
Numerical probabilistic
Writing Methods AP Computer Science A.
Data Analysis/ Probability
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
בתרגול הקודם אתר הקורס (הודעות, פרטי סגל הקורס, עבודות, פורום, מערכת הגשת תרגילים וכו') שימוש בחלון ה-command, פקודות בסיסות קוד Java: הידור (= קומפילציה)
12.4 p 471 a) double[] number = {1.05, 2.05, 3.05, 4.05, 5.05};
Scope of variables class scopeofvars {
CSE 142 Lecture Notes Global Constants, Parameters, Return Values
Area of triangle.
Power Point on Area- 5th Grade
Building Java Programs
Visibilities and Static-ness
CS 1054 Introduction to Programming in Java
Chapter 11 Classes.
Presentation transcript:

Lazzarini, Buffon’s needle, and Pi

Buffon’s needle From blem.html. blem.html Buffon's needle problem asks to find the probability that a needle of length l will land on a line, given a floor with equally spaced parallel lines a distance d apart. The problem was first posed by the French naturalist Buffon in 1733, and reproduced with solution by Buffon in 1777.

Buffon’s needle

It turns out that if we toss a needle of length l n times and count the h number of times that it touches a line, we find that this is related to Pi as follows:

Buffon’s needle This figure shows the result of 500 tosses of a needle of length parameter x=1/3, where needles crossing a line are shown in red and those missing are shown in green. 107 of the tosses cross a line, giving an estimate for Pi of

Lazzarini’s estimate (from Lazzarini's estimate Mario Lazzarini, an Italian mathematician, performed the Buffon's needle experiment in Tossing a needle 3408 times, he attained the well- known estimate 355/113 for π, which is a very accurate value, differing from π by no more than 3×10−7. This is an impressive result, but is something of a cheat. Lazzarini chose needles whose length was 5/6 of the width of the strips of wood. In this case, the probability that the needles will cross the lines is 5/3π. Thus if one were to drop n needles and get x crossings, one would estimate π as π ≈ 5/3 · n/x π is very nearly 355/113; in fact, there is no better rational approximation with fewer than 5 digits in the numerator and denominator.

Rational approximation to Pi π is very nearly 355/113; in fact, there is no better rational approximation with fewer than 5 digits in the numerator and denominator. Given the above, how can we demonstrate that 355/113 is the best?

Algorithm 1.Use an int variable for the numerator. Initialize it to 1. 2.Use an int variable for the denominator. Initialize it to 1. 3.Calculate 1/1, 1/2, 1/3, …, 1/N 2/1, 2/2, 2/3, …, 2/N … N/1, N/2, N/3, …, N/N While doing the above, remember the best.

/* * file : Lazzarini.java * author: george j. grevera, ph.d. * desc. : program to determine best rational * approximation to Pi. */ public class Lazzarini { public static void main ( String[] s ) { //declare variables final int N = 9999; for (int num=1; num<=N; num++) { for (int denom=1; denom<=N; denom++) { double temp = (double)num / denom; double diff = Math.abs( Math.PI-temp ); }

Algorithm We need a way to remember the best numerator and denominator so far. When we find something better, we need to update the best so far. At the end, we need to report the best that we found.

/* * file : Lazzarini.java * author: george j. grevera, ph.d. * desc. : program to determine best rational approximation to Pi. */ public class Lazzarini { public static void main ( String[] s ) { //declare variables final int N = 9999; int bestNum = 1; int bestDenom = 1; double best = Math.abs( Math.PI - (double)bestNum / bestDenom ); for (int num=1; num<=N; num++) { for (int denom=1; denom<=N; denom++) { double temp = (double)num / denom; double diff = Math.abs( Math.PI-temp ); } System.out.println( "best = " + bestNum + "/" + bestDenom ); }

/* * file : Lazzarini.java * author: george j. grevera, ph.d. * desc. : program to determine best rational approximation to Pi. */ public class Lazzarini { public static void main ( String[] s ) { //declare variables final int N = 9999; int bestNum = 1; int bestDenom = 1; double best = Math.abs( Math.PI - (double)bestNum / bestDenom ); for (int num=1; num<=N; num++) { for (int denom=1; denom<=N; denom++) { double temp = (double)num / denom; double diff = Math.abs( Math.PI-temp ); //we need to do the update of best so far here } System.out.println( "best = " + bestNum + "/" + bestDenom ); }

/* * file : Lazzarini.java * author: george j. grevera, ph.d. * desc. : program to determine best rational approximation to Pi. */ public class Lazzarini { public static void main ( String[] s ) { //declare variables final int N = 9999; int bestNum = 1; int bestDenom = 1; double best = Math.abs( Math.PI - (double)bestNum / bestDenom ); for (int num=1; num<=N; num++) { for (int denom=1; denom<=N; denom++) { double temp = (double)num / denom; double diff = Math.abs( Math.PI-temp ); if (diff < best) { best = diff; bestNum = num; bestDenom = denom; } System.out.println( "best = " + bestNum + "/" + bestDenom ); }