HP-20S: TVM Solver (uses built-in root finder)

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.

Description

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....

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:

4 = N, the Number of periods (as a mnemonic, register 4 is also N for statistical
calculations)

0 = I%, the Interest rate per period (the other isolated variable)

1 = PV, the Present Value (and the three variables representing money are
normally found in this row-like sequence)

2 = PMT, the PayMenT

3 = FV, the Future Value

Notes

A TVM solution is obtained in three steps:

Line 63 is used to select the unknown of interest (e.g., the initial
program listing specifies STO 4, and would solve for N, the number of periods).

The values for the other variables are STOred.

An initial guess is loaded into the display, and XEQ A starts the hunt for
the nearest root.

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).

Example

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.