lazzarini, buffon’s needle, and pi. buffon’s needle from blem.html

13
Lazzarini, Buffon’s Lazzarini, Buffon’s needle, and Pi needle, and Pi

Upload: derrick-griffin

Post on 17-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

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

Lazzarini, Buffon’s needle, Lazzarini, Buffon’s needle, and Piand Pi

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

Buffon’s needleBuffon’s needle

• From http://mathworld.wolfram.com/BuffonsNeedleProblem.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.

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

Buffon’s needleBuffon’s needle

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

Buffon’s needleBuffon’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:

hd

nl

ord

l

n

h

2

2

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

Buffon’s needleBuffon’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 3.116.

11.33107

15002

3

12

500

107

or

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

Lazzarini’s estimateLazzarini’s estimate(from (from http://en.wikipedia.org/wiki/Pi_through_experiment))

Lazzarini's estimate

Mario Lazzarini, an Italian mathematician, performed the Buffon's needle experiment in 1901. 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.

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

Rational approximation to PiRational 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?

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

AlgorithmAlgorithm

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.

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

/* * 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 ); } } }}

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

AlgorithmAlgorithm

• 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.

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

/* * 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 ); }}

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

/* * 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 ); }}

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

/* * 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 ); }}