Lecture 6 Notes

pbest 1 best numerator qbest 1 best denominator

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

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

Unformatted text preview: 3.14285.. –  Used polygons, n=96 –  3- digits correct |x- p*/q*|<En Rational approximation of •  Babylon, 1600 BC % Check all possible denominators Get M from user Calculate quotient p/q for all combinations of p and q Pick "best" quotient à༎ smallest error Lecture 8 4 5 2/11/14 % Rational approximation of pi % Rational approximation of pi M = input(‘Enter M: ’); M = input(‘Enter M: ’); % Check all possible denominators for q = 1:M % Check all possible denominators for q = 1:M end For current q find best numerator p (Need to check all possible numerators…) end Lecture 8 6 % Rational approximation of pi % Rational approximation of pi M = input(‘Enter M: ’); M = input(‘Enter M: ’); % Best q, p, and error so far qBest=1; pBest=1; err_pq = abs(pBest/qBest - pi); % Check all possible denominators for q = 1:M % At this q, check all possible numerators for p = 1:M % Check all possible denominators for q = 1:M % At this q, check all possible numerators for p = 1:M end end end end myPi = pBest/qBest; % Rational approximation of pi M = input(‘Enter M: ’); % Best q, p, and error so far qBest=1; pBest=1; err_pq = abs(pBest/qBest - pi); % Check all possible denominators for q = 1:M % At this q, check all possible numerators for p = 1:M if abs(p/q - pi) &l...
View Full Document

This document was uploaded on 03/11/2014 for the course CSCI 004 at Brown.

Ask a homework question - tutors are online