Overview
1°) Series
a) Program#1
b) Program#2
2°) Approximations
a) Ramanujan#1
b) Ramanujan#2
x2 / a2 + y2 / b2 = 1
1°) Series
a) Program#1
Formula:
With e2 = 1 - b2 / a2 Perimeter = 2.Pi.a [ 1 - ( 1/2 )2 e2 / 1 - ( 1x3 / ( 2x4 ) )2 e4 / 3 - ( 1x3x5 / ( 2x4x6 ) )2 e6 / 5 - ........ ]
Data Registers: R00 & R03 ... R05: temp
R01 = a R02 = b
Flags: /
Subroutines: /
01 LBL "EPM" 02 STO 02 03 X<>Y 04 STO 01 05 / 06 X^2 07 1 08 STO 00 |
09 STO 04 10 X<>Y 11 - 12 STO 03 13 RCL 00 14 LBL 01 15 RCL 04 16 RCL 00 |
17 ST+ X 18 1 19 ST+ 00 20 X<>Y 21 - 22 STO 05 23 LASTX 24 / |
25 X^2 26 * 27 RCL 03 28 * 29 STO 04 30 RCL 05 31 / 32 + |
33 X#Y? 34 GTO 01 35 RCL 01 36 ST+ X 37 * 38 PI 39 * 40 END |
( 52 bytes / SIZE 006 )
STACK | INPUTS | OUTPUTS |
Y |
a |
/ |
X | b | perimeter |
Example: a = 7 b = 5
7 ENTER^5 XEQ "EPM" >>>> 37.96136896 ---Execution time = 17s---
b) Program#2
-We can use a faster formula:
Formula: with h = ( a-b ) / ( a+b )
Perimeter = Pi ( a+b ) F ( -1/2 , -1/2 ; +1 ; h2 ) where F = hypergeometric function.
Data Registers: R00 ... R06: temp
R04 = a R05 = b
Flags: /
Subroutine: "HGF" ( cf "Hypergeometric
Functions for the HP41" )
01 LBL "EPM" 02 STO 05 03 X<>Y 04 STO 04 05 ST- Y |
06 RCL 05 07 + 08 STO 06 09 / 10 X^2 |
11 2 12 1/X 13 CHS 14 STO 01 15 STO 02 |
16 SIGN 17 CHS 18 STO 03 19 X<>Y 20 XEQ "HGF" |
21 RCL 06 22 * 23 PI 24 * 25 END |
( 38 bytes / SIZE 007 )
STACK | INPUTS | OUTPUTS |
Y |
a |
/ |
X | b | perimeter |
Example1: a = 7 b = 5
7 ENTER^5 XEQ "EPM" >>>> 37.96136892 ---Execution time = 5s---
Example2: a = 41 b = 16
41 ENTER^16 XEQ "EPM" >>>> 187.7915357 ---Execution time = 7s---
2°) Approximations
a) Ramanujan#1
Formula: Perimeter ~ Pi [ 3 ( a+b ) - sqrt ( (3a+b) (a+3b) ) ]
Data Registers:
R00 = a R01 = b
Flags: /
Subroutines: /
01 LBL "EPM" 02 STO 01 03 X<>Y 04 STO 00 |
05 + 06 RCL 01 07 3 08 ST* Z |
09 * 10 RCL 00 11 ST+ Y 12 LASTX |
13 * 14 RCL 01 15 + 16 * |
17 SQRT 18 - 19 PI 20 * 21 END |
( 31 bytes / SIZE 002 )
STACK | INPUTS | OUTPUTS |
Y |
a |
/ |
X | b | perimeter |
Example: a = 7 b = 5
7 ENTER^
5 XEQ "EPM" >>>> 37.96136732 ---Execution time = 1s---
b) Ramanujan#2
Formula: with h = ( a-b ) / ( a+b )
Perimeter ~ Pi ( a+b ) [ 1 + 3 h2 / ( 10 + sqrt ( 4 - 3 h2 ) ]
Data Registers:
R00 = a+b R01 = a R02 = b
Flags: /
Subroutines: /
01 LBL "EPM" 02 STO 02 03 X<>Y 04 STO 01 05 ST- Y |
06 RCL 02 07 + 08 STO 00 09 / 10 X^2 |
11 3 12 * 13 4 14 RCL Y 15 - |
16 SQRT 17 10 18 + 19 / 20 RCL 00 |
21 ST* Y 22 + 23 PI 24 * 25 END |
( 37 bytes / SIZE 003 )
STACK | INPUTS | OUTPUTS |
Y |
a |
/ |
X | b | perimeter |
Example1: a = 7 b = 5
7 ENTER^
5 XEQ "EPM" >>>> 37.96136896 ---Execution time = 1s---
Example2: a = 41 b = 16
41 ENTER^16 XEQ "EPM" >>>> 187.7915342 ---Execution time = 1s---
Note:
-This formula is often very accurate !