160 likes | 546 Views
Lazzarini, Buffon’s needle, and Pi. Buffon’s needle. From http://mathworld.wolfram.com/BuffonsNeedleProblem.html .
E N D
Buffon’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.
Buffon’s needle • It turns out that if we toss a needle of length ln 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 3.116.
Lazzarini’s estimate(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.
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 • Use an int variable for the numerator. • Initialize it to 1. • Use an int variable for the denominator. • Initialize it to 1. • 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 ); } }