piTiling

piTiling - N_cut = 0; % number of cut tiles xprev = n; %...

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

% Function piTiling % Eric Young / CS 100 M % function piApproximation = piTiling(n,f); f % Estimates the value of pi by tiling a circle of known radius n. % Pi is approximated as the number of cut + uncut tiles in the circle % divided by the radius, n, squared. % n is an integer radius of the circle to be tiled % f is the fraction of a tile assumed for any cut tile % % Tile the first quadrant, later multiply by four % N_uncut = 0; % number of uncut tiles
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: N_cut = 0; % number of cut tiles xprev = n; % x-value (bottom of 1st row) x % Iterate through each row % for k = 1:n xk = sqrt(n^2-k^2); % x-value @ y=k (top of k'th row) s = floor(xk); % # uncut tiles in k'th row c = ceil(xprev)-s; % # cut tiles in k'th row N_uncut = N_uncut + s; N_cut = N_cut + c; xprev = xk; end e % Estimate pi. .. % piApproximation = (4*(N_uncut + N_cut*f))/(n^2); p...
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