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