Bernoulli Numbers
12-18-2013, 12:52 AM (This post was last modified: 01-30-2014 09:24 PM by Namir.)
Post: #1
 Namir Senior Member Posts: 1,077 Joined: Dec 2013
Bernoulli Numbers
Bernoulli Numbers using Series Approximations

Algorithm

Given integer n and tolerance toler

Code:
IF n=1 THEN Return -0.5 IF n Mod 2 = 1 THEN Return 0  sum=1  i=2  term=2*toler  WHILE term>toler DO   term=1/i^n    sum=sum+term    i=i+1  END  IF n MOD 4 == 0 THEN chs=-1 ELSE chs=1 t=chs*(n!)/pi^n/2^(n-1)  Return t*sum

HP-41C Implementation

Memory Map

R00 = n
R01 = toler
R02 = i
R03 = Sum
R04 = term

Implementation

Code:
1 LBL "BERSER" 2 LBL A 3 CF 22 4 "TOLER?" 5 PROMPT 6 FS? 22 7 STO 01 8 "N?" 9 PROMPT 10 STO 00 11 1 12 X<>Y 13 X=Y? 14 GTO 11 15 2 16 MOD 17 1 18 X=Y? 19 GTO 10 20 1 21 STO 03      # sum = 1 22 STO 02      # i = 1 23 LBL 01      # Start summation loop 24 1 25 STO+ 02     # i=i+1 26 RCL 02 27 RCL 00 28 Y^X        29 1/X         # Calculate 1/i^n 30 STO+ 03     # sum = sum + 1/i^n 31 RCL 01 32 X<=Y?       # toler <= term? 33 GTO 01      # resume to the next iteration 34 CF 00       # start calculating other factor 35 RCL 00 36 4 37 MOD 38 X=0? 39 SF 00 40 RCL 00 41 FACT        # n! 42 PI 43 RCL 00 44 Y^X         # pi^n 45 / 46 2 47 RCL 00 48 1 49 - 50 Y^X          # 2^(n-1) 51 / 52 RCL 03 53 * 54 FS?C 00     # change sign? 55 CHS 56 RTN 57 LBL 10 58 0 59 RTN 60 LBL 11 61 -0.5 62 RTN
 « Next Oldest | Next Newest »

 Messages In This Thread Bernoulli Numbers - Namir - 12-18-2013 12:52 AM RE: Bernoulli Numbers - Dieter - 01-28-2014, 09:21 PM RE: Bernoulli Numbers - Dieter - 01-30-2014, 02:37 PM RE: Bernoulli Numbers - Namir - 01-30-2014, 09:34 PM

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