title: Calculate pi with MATLAB, bad results
body: <p>I'm using this .m file to calculate pi with MATLAB       </p>
  
  <pre><code>function calpi(n)
      S = 0;
      for i=1:n
          if mod(i,2) == 0
              S=S-1/(2*i-1)*(4*((1/5)^(2*i-1))-(1/239)^(2*i-1));
          else
              S=S+1/(2*i-1)*(4*((1/5)^(2*i-1))-(1/239)^(2*i-1));
          end    
      end
      S = 4*S;
      S=vpa(S,50)
  </code></pre>
  
  <p>When <code>n &lt;= 8</code>, it's alright.
  But when <code>n &gt;= 9</code>, the result turns exactly into the actual pi.
  All I want is to get the actual result to analyse this method.</p>
  
  <pre><code>&gt;&gt; calpi(9)
  S =
  3.1415926535897932384626433832795028841971693993751
  
  &gt;&gt; vpa(pi,50)
  ans =
  3.1415926535897932384626433832795028841971693993751
  </code></pre>
  
  <p>What's wrong with MATLAB?</p>