Matlab Chapter II

# Matlab Chapter II - Chapter 2 Limits Error Approximation...

This preview shows pages 1–4. Sign up to view the full content.

Chapter 2 Limits, Error, Approximation § 2.1 Summation Pi Via Tiling § 2.1 Keeping an Eye on Convergence Pi Via Polygons § 2.3 Rational Approximation* 22/7-ths and Other Fractions The constant π is a neverending decimal: 3.14159265358979323846264338327950288419716939937510582097494459230781 64062862089986280348253421170679821480865132823066470938446095505822 31725359408128481117450284102701938521105559644622948954930381964428 81097566593344612847564823378678316527120190914564856692346034861045 43266482133936072602491412737245870066063155881748815209209628292540... In this chapter we compute some more modest approximations. Our fi rst approach is to cover the circle x 2 + y 2 = n 2 with 1-by-1 “tiles”. If N is the number of tiles that are completely within the circle, then from the approximation π n 2 N we conclude that π N/n 2 . In this case the problem of estimating π reduces to a count- the-tiles problem. We will see that the error goes to zero as n → ∞ . Another approach is to approximate the unit circle with a polygon and regard the polygon area as an approximation to π . For a given n , a good approximating polygon is the regular n -gon whose vertices are on the unit circle. This area will underestimate π . If we use the regular n -gon whose edges are tangent to the unit circle, then its area will be an overestimate of π . In either case the error goes to zero as n → ∞ . Finally, we look to see how close we can get to π with a fraction p/q subject to the constraint that both p and q are less than some prescribed value M . The quotient 22/7 is a well known approximation in this regard. These π -approximation examples point to how we can cope with “in fi nities” when we compute. There isn’t enough time to compute a neverending decimal. And no computer has enough memory to store π exactly. Nevertheless, we are able to compensate for these shortfalls through intelligent approximation. 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example 2.1 Pi Via Tiling % Script Eg2_1 % Estimate Pi by tiling a circle. % Enter the circle radius... clc n = input(’Enter n:’) % Tile just the first quadrant, then multiply by four. N1 = 0; for k = 1:n-1 % The number of uncut tiles in row k... s = floor(sqrt(n^2 - k^2)); N1 = N1 + s; end % Estimate pi... rho_n = 4*N1/n^2; clc disp(sprintf(’n = %1d’,n)) disp(sprintf(’rho_n = %12.8f’,rho_n)) disp(sprintf(’Error = %12.8f’,abs(pi-rho_n))) Sample Output: h = 0.00000100 MyPi = 3.14158865 Error = 0.00000400 2
2.1. Summation 3 2.1 Summation Problem Suppose n is a positive integer and we trace the circle x 2 + y 2 = n 2 onto graph paper. For the case n = 10, Figure 2.1 is what we would obtain with the help of some scissors. Note that the area of the disk is π n 2 and that each “uncut” tile has unit area. If there are Figure 2.1: Tiling the Circle x 2 + y 2 = n 2 , ( n = 10) N uncut tiles, then we conclude that π n 2 N since the uncut tiles almost cover the disk. Write a script that inputs n and displays the π -approximation ρ n = N n 2 together with the error | ρ n π | . Program Development The fi rst thing to observe is that by symmetry, each quadrant has exactly the same number of uncut tiles. Thus, we need only count the number uncut tiles in the fi rst quadrant as displayed by Figure 2.2. If N 1 is the number of uncut tiles in the fi rst quadrant, then ρ n = 4 N 1 /n 2 .

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern