tilePi - % quadrant 1 % N_cut = 4*N1cut; N % The area of...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
% Eric Young % CS 100 M % Script tilePi.m % Estimates pi by tiling a circle % r = input('Enter the radius of the circle: '); f = input('Enter the fraction, in decimal form, each "cut tile" is of a whole tile: '); ' % Calculates the number of uncut tiles in the first quadrant % Stores value in cariable N1uncut % N1uncut = 0; for i = 1:r-1 s = floor(sqrt(r^2 - i^2)); N1uncut = N1uncut + s; end e % Calculates the number of total tiles in the first quadrant % totalTiles1 = 0; t for j = 0:9 k = 0; while sqrt(j^2+k^2) < r k = k+1; end totalTiles1 = totalTiles1 + k; end e % Number of uncut tiles in circle is four times number of uncut tiles in % quadrant 1 % N_uncut = 4*N1uncut; N % Number of cut tiles in quad 1 is number of total tiles in quadrant 1 - % the number of uncut tiles in quadrant 1 % N1cut = totalTiles1 - N1uncut; N % Number of cut tiles in total is four times the number of cut tiles in
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % quadrant 1 % N_cut = 4*N1cut; N % The area of the circle is approximately the total number of uncut tiles + % the number of cut tiles * fraction each cut tile is of a whole tile % circleArea = N_uncut + (f*N_cut); c % Pi approximation is circle area divided by the radius-squared % piApprox = (circleArea / (r^2)); p disp(sprintf('Via tiling, pi is approximately %5.7f.',piApprox)); d %%%%%%%%%%% Observations %%%%%%%%%%% % % For lower radius values (e.g. r = 2), higher f fractions seem to yield % better approximations for pi. For higher radius values (e.g. r = 50), % lower f fractions seems to yield better values. For mid range r values % (e.g. r = 10), the best fraction is around f = 0.6....
View Full Document

This note was uploaded on 09/12/2009 for the course CS 100 taught by Professor Fan/vanloan during the Fall '07 term at Cornell.

Page1 / 2

tilePi - % quadrant 1 % N_cut = 4*N1cut; N % The area of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online