|Re: Programming Programmable Calculators|
Message #32 Posted by Jeff Kearns on 4 Jan 2008, 6:28 p.m.,
in response to message #30 by Stefan Vorkoetter
I am a mechanical engineer and I have only posted once or twice on this board so please bear with me for making a lengthy post. I have written (and copied/adapted) programs for my 15C and 32sii for all sorts of applications in the past 15 years, including: piping systems design (conduit flow ~50 lines) as a marine engineer, determination of drilling parameters for PCB drilling, pressure vessel design and compressed air dryer sizing. I have often found it more convenient to use the programmable calculator rather than fire up the applicable utility on the PC. Also, prior to acquiring the Advantage module for my 41C (and later the 49G+), I used my 32sII quite a bit for Statistics applications - t-Statistics, ANOVA etc. I still do in fact. These were somewhat longer than 4-liners... I still find entering data for small data sets faster on the calculator compared to Minitab or Excel.
Most of all, I have found the TVM equation to be among the most valuable formulas in my arsenal. There is a great 38-liner TVM program that I often use for each of my Pioneers (32sII, 33s, 35s). I got this program on this site but cannot remember where... It is more accurate than the 'equation'. I am including the listing below.
It is a relatively short program - 38 steps (as compared to a 108 line version for the HP 15C) that literally turns your calculator into an 'accurate' financial calculator on par with any financial calculator like the HP 12C or others. The problem with most TVM programs that just interpret the TVM equation, is that roundoff error - when the calculator rounds to 10 (HP15C) or 12 (HP32s) significant digits - causes inaccuracies when the interest rate per compounding period is quite small and/or the number of compounding periods is very large.
A classic example from the HP 15C Advanced Functions Handbook is where a lady is compensated for her thoughts for one year at $0.01/second at an annual interest rate of 11.25% compounded every second. In this case the number of seconds in a year is simplified to equal n=60*60*24*365. If you simply program the equation into your calculator (or in the case of the 32 sii, enter it as an equation), you get a total of $376,877.67 on the 15C and $334,045.36 on the 32s. The bank account, however, is found to only hold $333,783.35. This program avoids rounding error by using the natural logarithm in such a way as to not discard precious significant digits of i/n.
Here is the code for the 32s/ 32sii/ 33s/ and 35s.
B: present value or "base" value
i: interest rate in %
E: end/begin modes
F: future value
B*(1+i)^n + P*((1+i)^n-1)*(1/i+E) + F = 0
(1+i)^n = e^(n*ln(1+i)) = i'
--> B*i' + P*(i'-1)*(1/i+E) + F = 0
T01 LBL T
T02 INPUT N
T03 INPUT I
T04 INPUT B
T05 INPUT P
T06 INPUT F
T07 INPUT E
T08 RCL I
T16 x<>y !switch x with y
T19 X<>Y? !x not equal to y?
T23 RCL* N
T25 RCL* B
T29 RCL* P
T30 RCL I
T34 RCL+ E
T37 RCL+ F