Post Reply 
Viète's Formula for PI
06-23-2020, 10:52 PM (This post was last modified: 07-15-2020 05:07 PM by Gerson W. Barbosa.)
Post: #9
RE: Viète's Formula for PI
(06-23-2020 06:39 PM)Gerson W. Barbosa Wrote:  ...
For faster convergence, you might want to try this algorithm:
...

The following appears to be better (more tests required) . Only one line has been changed. Anyway, here is it again:

Code:
Program  Viete;                                                                                 
                                                                                                                    
Uses Crt;                                                                                                            
                                                                                                                    
var         k: Byte;                                                                                                
            n: LongInt;                                                                                             
            c: Char;                                                                                                
   d, p, t, v: Extended;                                                                                             
                                                                                                                     
begin                                                                                                               
  ClrScr;                                                                                                           
  WriteLn('+---+----------------------+----------------------+');                                                    
  WriteLn('| k |         2*v          |         ~ pi         |');                                                    
  WriteLn('+---+----------------------+----------------------+');                                                    
  v := 1;                                                                                                            
  n := 1;                                                                                                           
  d := 0;                                                                                                           
  for k := 1 to 15 do                                                                                                
    begin                                                                                                           
      n := n + n;                                                                                                   
      d := Sqrt(d + 2);                                                                                             
      v := v*d;                                                                                                      
      t := 6*v*v - 27/10 - 1/(n*n);                                                                                            
      p := 2*n/v*(t + 1)/t;                                                                                         
      WriteLn('|',k:2,' |',2*n/v:21:18,' |',p:21:18,' |')
    end;                                                                                                             
  WriteLn('+---+----------------------+----------------------+');                                                   
  c := ReadKey                                                                                                       
end.

+---+----------------------+----------------------+
| k |         2*v          |         ~ pi         |
+---+----------------------+----------------------+
| 1 | 2.828427124746190098 | 3.140960508696045357 |
| 2 | 3.061467458920718174 | 3.141593674140638978 |
| 3 | 3.121445152258052286 | 3.141592707164788547 |
| 4 | 3.136548490545939264 | 3.141592654569488290 |
| 5 | 3.140331156954752913 | 3.141592653605653769 |
| 6 | 3.141277250932772868 | 3.141592653590043215 |
| 7 | 3.141513801144301077 | 3.141592653589797153 |
| 8 | 3.141572940367091385 | 3.141592653589793300 |
| 9 | 3.141587725277159701 | 3.141592653589793240 |
|10 | 3.141591421511199975 | 3.141592653589793239 |
+---+----------------------+----------------------+



P.S.:

This yields 1.8 digits per iteration, three times as much when compared to the plain Viète's formula.

P.P.S.:

This new formula is easier to program and will yield slightly more than two digits per term:

\(\pi \approx 2\left ( \frac{4}{3} \times \frac{16}{15}\times \frac{36}{35}\times\frac{64}{63} \times \cdots \times \frac{ 4n ^{2}}{ 4n ^{2}-1}\right )\cdot \left ( 1+\frac{2}{8n+3+\frac{3}{8n+4+\frac{15}{8n+4+ \frac{35}{8n+4 + \frac{63}{\dots\frac{\ddots }{8n+4+\frac{4n^{2}-1}{8n+4}}} }}} } \right )\)

TurboBCD program:

Code:

Program Wallis_Wasicki;

var d, n, i: Byte;
          t: Integer;
       c, w: Real;

begin
  ClrScr;
  WriteLn('+---+---------------------+---------------------+');
  WriteLn('| N |         2*W         |     2*W*C/(C-2)     |');
  WriteLn('+---+---------------------+---------------------+');
  for n := 1 to 8 do
    begin
      c := 0;
      d := 8*n + 4;
      w := 1;
      for i := n downto 1 do
        begin
          t := 4*i*i;
          w := w*t/(t - 1);
          c := (t - 1)/(c + d)
        end;
      c := c + d + 1;
      WriteLn('|',n:2,' |',2*w:20:17,' |',2*c*w/(c - 2):20:17,' |')
    end;
    WriteLn('+---+---------------------+---------------------+')
end.

+---+---------------------+---------------------+
| N |         2*W         |     2*W*C/(C-2)     |
+---+---------------------+---------------------+
| 1 | 2.66666666666666666 | 3.14074074074074073 |
| 2 | 2.84444444444444446 | 3.14159848961611078 |
| 3 | 2.92571428571428570 | 3.14159260997123044 |
| 4 | 2.97215419501133786 | 3.14159265392705764 |
| 5 | 3.00217595455690690 | 3.14159265358714120 |
| 6 | 3.02317019200136082 | 3.14159265358981426 |
| 7 | 3.03867362888341912 | 3.14159265358979309 |
| 8 | 3.05058999605551094 | 3.14159265358979325 |
+---+---------------------+---------------------+


In this table N is the number of terms, W is the Wallis Product evaluated to N terms and C/(C - 2) is the correction factor.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Viète's Formula for PI - pinkman - 06-17-2020, 05:06 PM
RE: Viète's Formula for PI - ramon_ea1gth - 06-17-2020, 09:37 PM
RE: Viète's Formula for PI - pinkman - 06-18-2020, 12:51 PM
RE: Viète's Formula for PI - pinkman - 06-23-2020, 10:04 PM
RE: Viète's Formula for PI - Gerson W. Barbosa - 06-23-2020 10:52 PM
RE: Viète's Formula for PI - cdmackay - 06-19-2020, 09:00 PM
RE: Viète's Formula for PI - pinkman - 06-23-2020, 09:58 PM
RE: Viète's Formula for PI - pinkman - 07-16-2020, 04:42 PM
RE: Viète's Formula for PI - pinkman - 06-24-2020, 01:15 PM
RE: Viète's Formula for PI - CyberAngel - 06-29-2020, 05:52 AM
RE: Viète's Formula for PI - pinkman - 06-29-2020, 10:54 PM
RE: Viète's Formula for PI - compsystems - 06-30-2020, 03:05 PM



User(s) browsing this thread: