Post Reply 
Programming Exercise (HP-15C, 15C LE - and others)
04-06-2014, 03:37 AM (This post was last modified: 04-06-2014 03:59 AM by Gerson W. Barbosa.)
Post: #97
RE: Programming Exercise (HP-15C, 15C LE - and others)
(04-05-2014 05:02 PM)Thomas Klemm Wrote:  
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.

Looks like my HP-11C is a bit slower: 18.7 seconds.

(04-05-2014 05:02 PM)Thomas Klemm Wrote:  Now beat that with brute force.

What about another non brute force program?

Code:

01 LBL A
02 STO I
03 STO 0
04 CLx
05 LBL 0
06 RCL I
07 DSE I
08 RCL I
09 *
10 1/x
11 +
12 DSE I
13 GTO 0
14 RCL 0   
15 STO I  
16 2
17 *
18 1
19 +
20 STO 0
21 CLx
22 LBL 1
23 RCL 0
24 +
25 RCL I
26 x^2
27 x<>y
28 /
29 DSE
30 GTO 1
31 RCL 0
32 +
33 1/x
34 +
35 RTN

4 10 GSB A --> 0.6931471805 ( 13.4 s )

5 8 GSB A --> 0.6931471806 ( 11 s )

7 6 GSB A --> 0.6931471807 ( 8.5 s )

The first parameter is the number of terms in the continued fraction, minus one. The second parameter, always even, is the number of computed terms in the series. I have assumed the continued fraction terms follow a pattern, but this has yet to be checked.

Cheers,

Gerson.

Edited to correct line 21 (CLx, not 0).
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) - Gerson W. Barbosa - 04-06-2014 03:37 AM



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