Post Reply 
(41C) and (42S) Arithmetic-Geometric Mean
07-26-2020, 07:50 PM
Post: #1
(41C) and (42S) Arithmetic-Geometric Mean
Arithmetic-Geometric Mean

The program AGM calculates the arithmetic-geometric mean of two positive integers x and y. As the graphic above suggests, an iterative process is used to find the AGM, computing both the arithmetic mean and geometric mean until the two means converge.

a0 = x
g0 = y

Repeat:
Arithmetic Mean: a1 = (a0 + g0)/2
Geometric Mean: g1 = √(a0 * g0)
Transfer new to old: a0 = a1, g0 = g1
Until |a1 - g1| < tolerance

You can set the tolerance as low as you want. The programs presented on this blog set tolerance at 10^(-10) (1E-10), to fit the calculator's display.

HP 41C Program: AGM

01 LBL^T AGM
02 STO 01
03 X<>Y
04 STO 02
05 X<>Y
06 LBL 00
07 RCL 02
08 RCL 01
09 ENTER
10 R↑
11 R↑
12 X<>Y
13 R↓
14 ENTER
15 R↑
16 +
17 2
18 /
19 STO 01
20 R↓
21 *
22 SQRT
23 STO 02
24 R↑
25 -
26 ABS
27 1E-10
28 X≤Y?
29 GTO 00
30 CLA
31 ^T AGM =
32 ARCL 01
33 AVIEW
34 END

HP 42S/Swiss Micros DM42/Free42 Program AGM:

00 {53-Byte Prgm}
01 LBL "AGM"
02 STO 01
03 X<>Y
04 STO 02
05 X<>Y
06 LBL 00
07 RCL 02
08 RCL 01
09 ENTER
10 R↑
11 R↑
12 X<>Y
13 R↓
14 ENTER
15 R↑
16 +
17 2
18 /
19 STO 01
20 R↓
21 *
22 SQRT
23 STO 02
24 R↑
25 -
26 ABS
27 1E-10
28 X≤Y?
29 GTO 00
30 CLA
31 "AGM = "
32 ARCL 01
33 AVIEW
34 END

The instructions for both the HP 41C and 42S versions are same: enter X and Y on the respective stacks and XEQ AGM.

Example (ALL/STD mode is applied):

AGM(37, 78):
37, 78, XEQ AGM returns:
Alpha: AGM = 55.5947005279


Blog Post: http://edspi31415.blogspot.com/2020/07/h...metic.html
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(41C) and (42S) Arithmetic-Geometric Mean - Eddie W. Shore - 07-26-2020 07:50 PM



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