Copyleft (C) 2003 Glen Kilpatrick
Distributed under GNU General Public License
This program is supplied without representation or warranty of any kind. The author and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.
The HP-20S offers a "Built-in Program Library", six programs each of which may be copied to the 99-step program memory for execution. In particular, program A, also known as "Root Finder", can be used to seek out the zeros of a function (defined in the remaining section of program memory). To quote from the HP-20S Scientific Calculator Owner's Manual (Edition 6, Part Number 00020-90001, page 89):
Root Finder (root)
This program finds a solution for f(x) = 0 using the secant method, which is derived from Newton's method with a numerical approxima- tion for the derivative f'(x). You must define the function f(x) by entering the program lines to calculate f(x), assuming x is in the dis- play. You must also supply an initial guess, x0, for the solution. The closer the initial guess is to the actual solution, the faster the program converges to an answer.
The main program is 62 lines long, and uses registers R5 through R9 and labels A, F, 8, and 9. The remaining program lines, registers, and labels can be used for defining f(x). You can replace the default values of \DELTAx limit (relative error), \EPSILON (f(x) tolerance), and count (number of it- erations) with different values depending on the desired accuracy and solution speed....
Program Instructions:
... 6. Optional: To change \EPSILON, change the default value of 10^-2 at lines 51 through 53. 7. Optional: To change \DELTAx limit , change the default value of 10^-10 at lines 39 through 42. 8. Optional: To change count, change the default value of 100 at lines 09 through 10.
The root finder is used to find the root of a Time Value of Money equation. With only 99-62=37 lines to play with, compromises had to be made. So the program is modified to select for the unknown variable, the known variables are "preloaded" before execution, and the root finder is started with an initial guess. And while the general problem specifies equal-sized payments made at either the beginning or at the end of equal-sized periods, this program only handles end payments.
HP's sign convention for TVM is that money received is positive, money paid out is negative. And the register convention is as follows:
A TVM solution is obtained in three steps:
An I% (register 0) of zero will yield "Error - Func"; other, illogical inputs may yield an error, or even nonsense (there's just not enough program memory to validate inputs, so don't expect reasonable results from unreasonable scenarios).
The Credit Union will loan $12,500.35 to purchase a pre-owned Toyota. The term of the loan is 5 years, interest is 6.25% APR, payment is through payroll deduction, and paychecks are twice a month. What is a reasonable "guess" for a payment amount?
FIX 2 GTO .63 PRGM \<- STO 2 ---> 63- 21 2 (solving for PMT) PRGM 5*12*2=120 STO 4 ---> 120 periods 6.25/24=0.26 STO 0 ---> I% per period (2.60416667E-1 with ALL) 12500.35 STO 1 ---> PV is the money received for the Toyota C STO 3 ---> FV will be zero when it's paid for RCL1/RCL4=104.17 \+/- ---> A reasonable guess to start (note that if the loan received is positive, then the payments must be negative in order to yield a zero solution) XEQ A ---> PMT of $121.43 (SHOW says -121.426920390)
OK, that looks reasonable. Now shift any rounding problems to only one number over the life of the loan, the Future Value. Rounding down PMT will yield a bigger FV, and a bigger last payment, so round up for a smaller one.
GTO .63 PGRM \<- STO 3 ---> 63- 21 3 (solving for FV) PRGM 122 \+/- STO 2 ---> PMT of $122 C ---> initial guess of zero for FV XEQ A ---> FV of 80.61 (SHOW says 80.6051455722)
So that would be 119 payments of $122 paid out, and a final payment of 122-80.61 or $41.39
Enter ... See CLPRGM 00- LOAD A root then 00- \UPARROW (would be 51 8 if it could be recorded) LBL 5 62- 61 41 F (note this is the last line supplied by the LOAD) ... STO {N,I%,PV,PMT,FV} 63- 21 {4,0,1,2,3} C 64- 71 ( 65- 33 ( 66- 33 1 67- 1 + 68- 75 RCL 0 69- 22 0 \/ 70- 45 E 71- 51 32 2 72- 2 ) 73- 34 LN 74- 13 \* 75- 55 RCL 4 76- 22 4 \+/- 77- 32 ) 78- 34 e^x 79- 12 = 80- 74 ( 81- 33 1 82- 1 - 83-65 LAST 84- 51 74 ) 85- 34 \* 86- 55 RCL 2 87- 22 2 \* 88- 55 E 89- 51 32 2 90- 2 \/ 91- 45 RCL 0 92- 22 0 + 93- 75 RCL 1 94- 22 1 + 95- 75 RCL 3 96- 22 3 \* 97- 55 LAST 98- 51 74 = 99- 74 SHOW 975C (with "N" selected, "STO 4 63- 21 4")
LOAD A uses LaBeLs A and F, and registers 5 through 9; f(x) additionally uses all of the remaining registers, 0 through 4, and all of the remaining program space.
A grateful thanks go to Christof for the loan of an HP-20S (otherwise my photocopy of some hand-scrawled 3X5 index cards from 1993-4 might never have made sense).
Go
back to the software library
Go
back to the main exhibit hall