Post Reply 
Programming Exercise (HP-15C, 15C LE - and others)
04-05-2014, 05:02 PM (This post was last modified: 04-05-2014 05:08 PM by Thomas Klemm.)
Post: #95
RE: Programming Exercise (HP-15C, 15C LE - and others)
Quote:I took your HP-11C program that sums an alternating series ...

Let's go back to Valentin's program. It uses Euler's transform to improve convergence. While Valentin's program handles the general case we can do the same for that specific series.

This leads to the following program for the HP-11C which is shorter, faster and more accurate:
Code:
001 - 42,21,11  LBL A      
002 -    44  1  STO 1      
003 -       34  x<>y       
004 -    44  0  STO 0      
005 -    44 25  STO I      
006 -    43 35  CLx        
007 - 42,21, 0  LBL 0      
008 -    45 25  RCL I      
009 -    42  5  DSE        
010 -    45 25  RCL I      
011 -       20  x          
012 -       15  1/x        
013 -       40  +          
014 -    42  5  DSE        
015 -    22  0  GTO 0      
016 -    44  2  STO 2      
017 -    45  1  RCL 1      
018 -       26  EEX        
019 -       40  +          
020 -    44 25  STO I      
021 -    43 35  CLx        
022 -    22  2  GTO 2      
023 - 42,21, 1  LBL 1      
024 -    45 25  RCL I      
025 -       20  x          
026 - 42,21, 2  LBL 2      
027 -       26  EEX        
028 -       40  +          
029 -    45 25  RCL I      
030 -    45  0  RCL 0      
031 -       40  +          
032 -       10  /          
033 -        2  2          
034 -       10  /          
035 -    42  5  DSE        
036 -    22  1  GTO 1      
037 -    45  2  RCL 2      
038 -       40  +          
039 -    43 32  RTN
As with Valentin's original program you can specify the number of terms to sum initially (M) and the number of differences to compute (N). However make sure M is even.

Example:
12 ENTER
10 GSB A

The result 0.6931471806 is exact to all 10 places and is equal to \(log(2)\) as it should be. It takes about 17 seconds using Nonpareil which will be about the same as with the real calculator.

Now beat that with brute force.

Cheers
Thomas

For those interested here's a Python program:
Code:
M = 12
N = 10

r, n = 0, M
while n > 0:
    r += 1./n/(n - 1)
    n -= 2

s, n = 0, N + 1
while True:
    s = (1. + s)/(M + n)/2
    n -= 1
    if n == 0:
        break
    s *= n

print r + s
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Programming Exercise (HP-15C, 15C LE - and others) - Thomas Klemm - 04-05-2014 05:02 PM



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