tilePi - rho_n= 4*N1/n^2 my pi counting uncut tiles tau_n=...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
% Script tilePi % Estimate Pi by tiling a circle. % % clc disp('Estimate pi by tiling a circle of radius n.') disp('Count each cut tile as fraction f of a whole tile.') n= input('Enter n: '); f= input('Enter f: '); % Tile just the first quadrant, then multiply by four. % N1= 0; % number of uncut tiles (so far) B1= 0; % number of cut tiles (so far) xprev= n; % x value at bottom of first row for k= 1:n xk= sqrt(n^2 - k^2); % x value at y=k (top of row k) s= floor(xk); % number of uncut tiles in row k c= ceil(xprev)-s; % number of cut tiles in row k N1= N1 + s; B1= B1 + c; xprev= xk; end % Estimate pi.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: .. rho_n= 4*N1/n^2; % my pi counting uncut tiles tau_n= 4*(N1 + B1*f)/n^2; % my pi counting uncut and cut tiles % Output disp(sprintf('n = %d',n)) disp(sprintf('f = %d',f)) disp(sprintf('There are %d uncut tiles and %d cut tiles.',N1,B1)) disp(sprintf('MyPi = %12.8f (counting uncut tiles only)',rho_n)) disp(sprintf(' Error = %12.8f',abs(pi-rho_n))) disp(sprintf('MyPi = %12.8f (counting uncut and cut tiles)',tau_n)) disp(sprintf(' Error = %12.8f',abs(pi-tau_n))) % For values of n>1000, 1/2 is a reasonable fraction representing a cut % tile....
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.

Ask a homework question - tutors are online