Approximation of Π by Numerical Methods Mathematics Coursework (NM)
Total Page:16
File Type:pdf, Size:1020Kb
Approximation of π by Numerical Methods Mathematics Coursework (NM) Alvin Sipragaˇ Magdalen College School, Brackley April 2010 1 Introduction There exist many ways to approximate1 π, usually employed in computer systems. Numerical methods may be the basis for some of these approximations. In this coursework, we investigate the application of numerical methods { specifically numerical integration methods { to the evaluation of a particular definite integral. In this investigation we will use the function defined as follows: 16x − 16 f(x) = (1) x4 − 2x3 + 4x − 4 As mentioned, numerical integration will be employed to approximate π. The integral and its rela- tionship is defined as follows: Z 1 Z 1 16x − 16 π = f(x) dx = 4 3 dx (2) 0 0 x − 2x + 4x − 4 Which we shall proceed to investigate. 8 6 4 y 2 O -4 -2 -2 1 2 4 -4 x 16x−16 Figure 1: f(x) = x4−2x3+4x−4 The following sum was discovered by Bailey, Borwein and Plouffe (BBP) and is discussed in a paper from 1996 by them. The above integral (2) is derived from and is equal to it.[1, 2] 1 X 1 4 2 1 1 π = − − − (3) 16n 8n + 1 8n + 4 8n + 5 8n + 6 n=0 1Approximate rather than calculate is used in this context, since π is irrational and any evaluation will always be an approximation { never equal { although the original expression may well be equal to π. 1 1.1 Strategy 2 SOLUTION BY SIMPSON'S RULE The integral itself is appropriate because it is difficult to integrate by conventional means. The normal approach to integration by analysis is as follows: Z 1 16x − 16 4 3 dx from (2) 0 x − 2x + 4x − 4 Z 1 x − 1 = 16 4 3 dx 0 x − 2x + 4x − 4 Z 1 x − 1 = 16 2 2 dx 0 (x − 2)(x − 2x + 2) At which point we can not proceed.2 Since there is no analytical solution within our means, our only means of solving it is by numerical methods. A brief discussion of the numerical methods we employ is also in order. 1.1 Strategy The numerical integration method we shall use is Simpson's rule. It is appropriate because it is an efficient and easy-to-apply numerical method for finding the area beneath a curve within a limit. Of interest is the error in the results obtained. Although it is not possible to integrate the expression analytically, we have the benefit of comparing the results to π, which is known to sufficiently many decimal places to never worry about it in the scope of this coursework. As such, we may calculate errors directly, and on that basis improve our solution. Simpson's rule is appropriate for the problem because it is an easy numerical method to apply, and converges relatively quickly to a desirable degree of accuracy. The Trapezium rule and Midpoint rule could also be used, but their use is superfluous because Simpson's rule directly improves on both, and so we can get better solutions using it. The rule is based on dividing the area to be integrated into equally sized `strips'. For an integral R b a f(x) dx to be divided into 2n strips of width h, the rule is as follows: h S = ff + f + 4(f + f + f + ··· + f ) + 2(f + f + f + ··· + f )g (4) n 3 0 2n 1 3 5 2n−1 2 4 6 2n−2 Where f0 = f(a), f1 = f(a + h), and so on such that f2n = f(a + 2nh) = f(b). The procedure will be to apply the rule to the above integral to approximate π. Adjusting the number of strips taken (and hence width of strips) will affect the accuracy of the solution to the integral. We shall take a few of these such changes and investigate the error in their results. Given this, a more informed change to the number of strips can be made to achieve the kind of accuracy we want. Because numerical methods are rather tedious and prone to error, use of computer spreadsheet software is in order. A spreadsheet layout with formulae can be found in Appendix A. 2 Solution by Simpson's rule Using the formula (4), we can split the region to be integrated into a set of strips for our desired degree of accuracy. The convergence of the method will be relative, so a reasonable number of strips to start with should be picked. Since we are integrating between 0 and 1, we shall begin by using 10 strips. For reference, π to 20 decimal places is as follows: π = 3:14159265358979323846 ::: (5) 2It is worth pointing out that given the nature of the function, were we to be able to integrate it (for example, by some more advanced partial fractions splitting) we would get an inverse trigonomic function of some kind (arctan, arcsin, etc.). However, computing π by use of trigonomic functions is paradoxical and can not give a better approximation of π without x3 x5 x7 use of some further numerical method (e.g. Gregory's series, arctan x = x − 3 + 5 − 7 + ··· ). This would somewhat defeat the point of investigating by means of numerical integration. 2 2.1 10 strips 2 SOLUTION BY SIMPSON'S RULE 2.1 10 strips In this case, we put n = 5, hence the number of strips is 2n = 10 and the width, h = 0:1. Below is the table of values for the points on the function that we will use in (4). x f(x) 0.0 4 0.1 3.99789000249868 0.2 3.98208063713290 0.3 3.93548613795284 0.4 3.83631713554987 0.5 3.65714285714286 0.6 3.36417157275021 0.7 2.91633756607327 0.8 2.26244343891403 0.9 1.33122555953074 1.0 0 They are then substituted into the Simpson's rule formula (4): 0:1 S = f4 + 0 + 4(3:99789000249868 + 3:93548613795284 5 3 + 3:65714285714286 + 2:91633756607327 + 1:33122555953074) (6) + 2(3:98208063713290 + 3:83631713554987 + 3:36417157275021 + 2:26244343891403)g = 3:14141180204959 Which is correct to 3 significant figures. This is not particularly impressive, but Simpson's rule begins to converge very quickly. We shall double the number of strips (doubling n) to 20 and then do some error analysis on the two results such that we can make an informed improvement on our solutions. 2.2 20 strips We put n = 10 =) h = 0:05 and number of strips = 20. Our values of f(x) are as follows: x f(x) x f(x) 0.00 4 0.55 3.52726125922002 0.05 3.99974343750976 0.60 3.36417157275021 0.10 3.99789000249868 0.65 3.16251292712455 0.15 3.99266787645482 0.70 2.91633756607327 0.20 3.98208063713290 0.75 2.61892583120205 0.25 3.96387096774194 0.80 2.26244343891403 0.30 3.93548613795284 0.85 1.83732936521227 0.35 3.89404636816992 0.90 1.33122555953074 0.40 3.83631713554987 0.95 0.72711160595095 0.45 3.75868595484772 1.00 0 0.50 3.65714285714286 Into (4): 0:05 S = f4 + 0 + 4(3:99974343750976 + 3:99266787645482 10 3 + 3:96387096774194 + 3:89404636816992 + 3:75868595484772 + 3:52726125922002 + 3:16251292712455 + 2:61892583120205 + 1:83732936521227 + 0:72711160595095) + 2(3:99789000249868 + 3:98208063713290 + 3:93548613795284 + 3:83631713554987 (7) + 3:65714285714286 + 3:36417157275021 + 2:91633756607327 + 2:26244343891403 + 1:33122555953074)g = 3:14158020314711 3 3 ERROR ANALYSIS Which is correct to 5 significant figures. An improvement, but we can do better. We shall analyse the errors in our results and use the properties of Simpson's rule to find a better approximation. The spreadsheet software has a limit of 15 significant figures, so it seems reasonable3 to try and achieve this by numerical methods. 3 Error analysis From (5), (6) and (7), we have π = 3:14159265358979 ::: S5 = 3:14141180204959 S10 = 3:14158020314711 Which, naturally, we shall refer to as π, S5 and S10 henceforth. Our desired accuracy is 15 significant figures, or thereabouts. Anything above 6 will be sufficient to demonstrate the merits or issues with numerical integration methods for approximation of π. We must do a little analysis given the error in the approximations we have computed. We know that for Simpson's rule, the absolute error is proportional to h4 { that is, fourth order. Using this property, it is possible to find without trial and error an n value for Sn where the accuracy is roughly4 15 significant figures. Consider the absolute errors (which we henceforth denote by ∆x) in our approximations: ∆Sn −4 S5 1:80851540202642 × 10 −5 S10 1:24504426795014 × 10 4 It follows that ∆S10 ≈ (1=16) × ∆S5, since h changes by a factor of 1/2, and (1=2) = 1=16. To verify: (1=16) × 1:80851540202642 × 10−4 = 1:13032212628594 × 10−5 ≈ 1:24504426795014 × 10−5, so indeed the property holds to a tolerable degree. Our aim is 15 significant figures, so an absolute error of approximately 5 × 10−15. Consider the following: ) 0:0045 = 0:005 ± 5 × 10−4 0:0055 So generally we can say for n significant figures, we have an error of ±5×10−n. Obviously 0:0055 6= 0:005 to 4 significant figures, but the absolute error in any case will be 5 × 10−4 for an approximation to 4 significant figures. By what we know about the rule, given a desired error we can find by what power { let it be m { −15 of 1/16 we multiply ∆S5 by to get 5 × 10 . Given that the method is fourth order, it means that our m m old h would have to be multiplied by (1=2) to get the new h (h = hold × (1=2) ), and it follows that −15 h = 1=2n =) n = 1=2h, so we can find the new n of Sn such that ∆Sn = 5 × 10 .