Post Reply 
PPC Journal V2N6 - TVM i% unknown on HP-65
10-18-2015, 08:11 PM (This post was last modified: 10-19-2015 05:05 PM by Dieter.)
Post: #22
RE: PPC Journal V2N6 - TVM i% unknown on HP-65
(10-18-2015 08:08 AM)AndiGer Wrote:  Tried just now - it works great! End mode 4 iterations, Beg mode 3.
(of course used y^x code 05)

Fine. Once we get rid of the LBL A ... LBL E part there is room for some improvements. The following version quits if the relative error is below 1E–6. It also checks whether the first guess for the interest rate is exactly zero. In this case that's already the result and the program exits. This also avoids a division by i=0 in the first iteration.

Code:
01   LBL     23       Start calculation
02   B       12  
03   RCL 1   34 01    n
04   RCL 3   34 03    PMT
05   x       71  
06   RCL 4   34 04    PV
07   +       61  
08   RCL 5   34 05    FV
09   +       61  
10   RCL 5   34 05   
11   RCL 4   34 04   
12   -       51  
13   RCL 1   34 01   
14   x       71  
15   ÷       81  
16   2       02  
17   x       71       = initial guess for i
18   STO 2   33 02    store i in R2
19   0       44  
20   g x=y?  35 23    i = 0 ?
21   GTO     22       then exit program
22   2       02  
23   LBL     23       start iteration
24   1       01  
25   RCL 2   34 02   
26   1       01  
27   +       61  
28   STO 6   33 06    store q=1+i in R6
29   RCL 1   34 01   
30   CHS     42  
31   g       35  
32   y^x     05  
33   STO 7   33 07    store q^-n in R7
34   RCL 5   34 05   
35   x       71  
36   1       01  
37   RCL 7   34 07   
38   -       51  
39   RCL 3   34 03   
40   x       71  
41   RCL 2   34 02   
42   ÷       81  
43   STO 8   33 08    store pmt·(1-q^-n) / i in R8
44   f       31  
45   TF 1    61       if "begin" mode is set
46   RCL 6   34 06    multiply by (1+i)
47   x       71  
48   +       61  
49   RCL 4   34 04   
50   +       61       = TVM (i, n, PMT, PV, FV)
51   RCL 8   34 08
52   RCL 2   34 02   
53   ÷       81  
54   RCL 3   34 03   
55   RCL 2   34 02   
56   ÷       81  
57   f       31  
58   TF 1    61       if "begin" mode is set
59   RCL 3   34 03    add PMT
60   +       61  
61   RCL 5   34 05   
62   -       51  
63   RCL 7   34 07   
64   x       71  
65   RCL 1   34 01   
66   x       71  
67   RCL 6   34 06   
68   ÷       81  
69   -       51       = -TVM' (i, n, PMT, PV, FV)
70   ÷       81       Δi = -TVM / TVM'
71   STO     33       add Δi to i
72   +       61  
73   2       02  
74   RCL 2   34 02   
75   ÷       81       relative error = Δi / i
76   g       35  
77   ABS     06  
78   EEX     43  
79   CHS     42  
80   6       06  
81   g x≤y?  35 22    is |relative error| ≥ 1E-6 ?
82   GTO     22       then do another iteration
83   1       01
84   LBL     23       exit routine
85   2       02  
86   RCL 2   34 02    recall i
87   EEX     43  
88   2       02  
89   x       71       return i% = i · 100%
90   RTN     24       and quit

I could not check this code on a real HP65, so I hope it does what it is supposed to. ;-)
I also hope I got the key codes right.

EDIT: the original version I posted included a loop counter but had an error. The code above is a corrected version.

BTW, what does the HP65 do if the last command is not a RTN or R/S? Does it simply stop like later calculators? Or does it behave differently? In other words: if the 101st step would be a RTN, can it be omitted so that the code fits?

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: PPC Journal V2N6 - TVM i% unknown on HP-65 - Dieter - 10-18-2015 08:11 PM



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