octave_test.m 293 B

1234567891011121314
  1. function main()
  2. fprintf("%.15f\n", approx_pi(1));
  3. fprintf("%.15f\n", approx_pi(3));
  4. fprintf("%.15f\n", approx_pi(5));
  5. fprintf("%.15f\n", approx_pi(10));
  6. end
  7. function r = approx_pi(steps)
  8. total = 0;
  9. for k = 0:steps
  10. total = total + ((-1)^k) / ((2*k+1)*3^k);
  11. end
  12. r = 2 * sqrt(3) * total;
  13. end