From 4b4f50352d061c569fe448e72aaa47ee54d138bc Mon Sep 17 00:00:00 2001 From: wukong Date: Sun, 14 Oct 2018 16:00:25 -0700 Subject: restructured conditional prints in diff, added parabolic focus solution to quad_reg output --- sterling_approx.awk | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 sterling_approx.awk (limited to 'sterling_approx.awk') diff --git a/sterling_approx.awk b/sterling_approx.awk new file mode 100644 index 0000000..5abe41d --- /dev/null +++ b/sterling_approx.awk @@ -0,0 +1,17 @@ +#!/usr/bin/awk -f + +### sterling_approx.awk +# https://en.wikipedia.org/wiki/Stirling%27s_approximation + +BEGIN { + ARGV[1] ? n = ARGV[1] : n = 0 + pi = 4*atan2(1,1) + p = 0 + if (n > 0) { + p = 1 + for (m=n; m>0; m--) + p *= n*exp(-1) + p = sqrt(2*pi*n)*p*(1 + 1/(12*n) + 1/(288*n*n) - 139/(51840*n*n*n) - 571/(2488320*n*n*n*n)) + } + printf(OFMT ORS, p) +} -- cgit v1.2.3