Post Reply 
Can you calculate Pi using a Solver?
12-10-2019, 09:35 PM (This post was last modified: 04-15-2023 02:21 PM by Albert Chan.)
Post: #11
RE: Can you calculate Pi using a Solver?
Pi via AGM, Emu71 HP-71B basic

Code:
10 A=1 @ B=SQRT(.5) @ S=1 @ P=1
20 C=A-B @ B=SQRT(A*B) @ A=A-C/2 @ S=S-P*C*C @ P=P+P
30 DISP A*B/(.25*S)
40 IF A<>B THEN 20

>RUN
3.14040401902
3.1415926456
3.1415926536
3.14159265359


Comment: Apr 14, 2023

Above code started with S=1, and lowered it bit by bit.
It may be more accurate to avoid this cancellation errors.
Just click the green arrow for Free42 AGM code.

(06-20-2020 04:23 PM)Albert Chan Wrote:  To improve agm2 accuracy, I redefined agm2 returns:

x, y = agm2(a, b)
→ x = converged GM of agm(a, b)
→ y = -Σ(2k (½gapk)² , k = 1 .. n), n = number of iterations to converge GM

With this new setup, ellipse_perimeter(a,b) = 4 a E(1-(b/a)²) = pi (y + b² + a²)/x

With above setup, x, y = agm2(1, sqrt(0.5)) --> S = 1+2*y --> pi = 2*x^2 / (y+1/2)

.5 SQRT 1 XEQ "AGM"

X = 8.472130847939790866064991234821916e-1
Y = -4.305341895553637462503337745231669e-2

X^2 2 * SWAP .5 + /

3.141592653589793238462643383279503

Or, less keystrokes, x, y = agm2(1, sqrt(2)) --> pi = 2*x^2 / (y+1)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Can you calculate Pi using a Solver? - Albert Chan - 12-10-2019 09:35 PM



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