BBS: Inland Empire Archive Date: 05-08-92 (19:28) Number: 190 From: ROB FLOR Refer#: NONE To: ANDY KIDLE Recvd: NO Subj: Programming Pi Conf: (2) Quik_Bas
AK>I need some help with a simple computer program (or what should be >simple for a semi-experienced programmer.) I need to program two >infinite mathematical series for finding pi. I have access to BASIC and >QUICKC for programming. Here are the two series, >so if you can help, let me know: AK>pi = 4(1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 +......) I made a suggestion to calculate each irrational number but that would give poor accuracy since irrational numbers cannot be calculated precisely. Lets see if we can avoid this by finding the old fashion Common Denominator: A/B - C/D = (A*D / B*D) - (C*B / D*B) = 1/1 - 1/3 = (1*3 / 1*3) - (1*1 / 3*1) = 3/3 - 1/3 = (3-1) / 3 = 2/3 A now = 2 'no imprecision B now = 3 'no division, no floating point '=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= DEFINT A - Z A=1 :B=1 :C=1 :Sign=0 N = 15 'lets say FOR D = 3 TO N STEP 2 Sign = NOT Sign 'Find common denominator, A*D/B*D, C*B/D*B C = B * Sign 'c is always + or - 1 B = B * D 'D*B = B*D so we already have common denominator A = A * D 'multiply top and bottom by same amount A = A + C 'calculate dividend, A + [+|-]C PRINT "Intermediate calculation of pi = 4 divided by ( "A"/"B" )" NEXT K pi# = 4# / (A / B) 'our only division print "pi to "N" calculations ="pi# ' Rob * OLX 2.2 * pi of the day --- WM v2.01/91-0156 * Origin: BEAR HEAVEN BBS (914) 677-6948 MILLBROOK NY (1:272/53)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET