Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The formula comes from the evaluation of tg(pi/4) which is equal to 1. The inverse:</p> <pre><code>pi/4 = arctg(1) so pi = 4* arctg(1). using the technique of the Taylor series: arctg (x) = x - x^3/3 + ... + (-1)^n x^(2n+1)/(2n+1) + o(x^(2n+1)) so when x = 1 you get your formula: pi = 4 * (1 – 1/3 + 1/5 – 1/7 + …) </code></pre> <p>the problem is to find an approximation of pi with an accuracy of 0.00001 (5 decimal). Lookinq at the formula, you can notice that at each step (1/3, 1/5,...) the new term to add:</p> <ul> <li>is smaller than the previous one,</li> <li>has the opposite sign.</li> </ul> <p>This means that each term is an upper estimation of the error (the term o(x^(2n+1))) between the real value of pi and the evaluation up to this term. So it can be use to stop the recursion at a level where it is guaranty that the approximation is better than this term. To be correct, the program you propose multiply the final result of the recursion by 4, so the error is no more guaranteed to be smaller than term.</p> <p>looking at the code:</p> <pre><code>pi() -&gt; 4 * pi(0,1,1). % T = 0 is the initial estimation % M = 1 is the sign % D = 1 initial value of the term's index in the Taylor serie pi(T,M,D) -&gt; A = 1 / D, % evaluate the term value if A &gt; 0.00001 -&gt; pi(T+(M*A), M*-1, D+2); % if the precision is not reach call the pi function with, % new serie's evaluation (the previous one + sign * term): T+(M*A) % new inverted sign: M*-1 % new index: D+2 true -&gt; T % if the precision is reached, give the result T end. </code></pre> <p>To be sure that you have reached the right accuracy, I propose to replace <code>A &gt; 0.00001</code> by <code>A &gt; 0.0000025</code> (<code>= 0.00001/4</code>)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload