Post Reply 
[VA] SRC #010 - Pi Day 2022 Special
03-16-2022, 08:49 PM (This post was last modified: 03-17-2022 12:58 PM by Albert Chan.)
Post: #9
RE: [VA] SRC #010 - Pi Day 2022 Special
(03-15-2022 10:04 PM)Albert Chan Wrote:  \(\displaystyle \ln(\pi) =
\int_0^1 \left(\frac{1}{1-x} + \frac{\pi\sqrt{x}}{2\;\tan(\pi\sqrt{x})}\right) dx\)

Note that integrand is inaccurate when x approach 1. P cannot be set too small.

To improve accuracy, lets remove square roots, x = y^2, dx = 2y dy

g(y) = (1/(1-y^2) + pi*y/2/tan(pi*y)) * 2y
       = -1/(y+1) - 1/(y-1) + pi*y^2/tan(pi*y)

Since tan(pi*(1-y)) = -tan(pi*y), we might as well fold the area.

∫(g(y), y=0..1) = ∫(g(y) + g(1-y), y=0..1/2)

\(\displaystyle \ln(\pi) = \int_0^{1/2} \left(
\frac{-1}{y+1} + \frac{1}{y-2}
+ \frac{-1}{y-1} + \frac{1}{y}
+ \frac{\pi (2y-1)}{\tan(\pi y)}
\right) dy\)

H(y) = ∫(-1/(y+1) + 1/(y-2) - 1/(y-1) dy = -ln|y+1| + ln|y-2| - ln|y-1|

H(1/2) = -ln(3/2) + ln(3/2) - ln(1/2) = ln(2)
H(0) = -ln(1) + ln(2) - ln(1) = ln(2)

With H(1/2) - H(0) = 0, we can remove integrand first 3 terms. Smile

\(\displaystyle \ln(\pi) = \int_0^{1/2} \left(
\frac{1}{y} + \frac{\pi (2y-1)}{\tan(\pi y)}
\right) dy\)

Let's compare the 2 versions.

10 P=1E-6
20 DEF FNF(X,Y)=1/(1-X)+.5*Y/TAN(Y)
30 DISP INTEGRAL(0,1,P,FNF(IVAR,PI*SQRT(IVAR))),EXP(RES)
40 DEF FNG(Y)=1/Y+PI*(2*Y-1)/TAN(PI*Y)
50 DISP INTEGRAL(0,.5,P,FNG(IVAR)),EXP(RES)
>
>RUN
1.14472988295       3.14159264448
1.14472988584       3.14159265356
>
>LOG(PI), PI
1.14472988585       3.14159265359
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] SRC #010 - Pi Day 2022 Special - Albert Chan - 03-16-2022 08:49 PM



User(s) browsing this thread: 1 Guest(s)