Post Reply 
PC-1211, PC-1250, etc. TVM
05-29-2024, 09:17 PM
Post: #5
RE: PC-1211, PC-1250, etc. TVM
(03-30-2021 04:58 PM)Dave Britten Wrote:  In light of all the recent Sharp enthusiasm, here's my attempt at a TVM solver for the PC-1211, and compatible models like the PC-1250, and no doubt many others (and their corresponding Tandy/Radio Shack versions).

In light of all the recent exciting discussions about TVM contributions, I looked back at your excellent post of the TVM program for SHARPs as I wanted to play around with it a bit more and compare to HPs etc.

I found an issue with the program where the rate calculation would not converge, which might also affect similar programs on other machines with 10 digit precision. The problem is roundoff. The Newton iteration keeps updating the estimated rate I but Y (the root) never reaches zero for this case:

B=1 (begin mode)
N=40
PMT=-40
PV=900
FV=-1000

The rate should be 4.753367189% but it won't get there because Y (the root) hovers around 0.000000171.

Coming up with an effective and safe convergence criterium can be tricky. A possible workaround is to compare the estimated rate to the previously estimated rate:

25 IF Y<>W AND 100-V/I<>99 GOTO 24

where 100-V/I equals 99 if V is close to I up to 9 digits. It's a bit of a risky move since we could hit a rate plateau that is not close to the root (so perhaps test if we are at least somewhat close to the root also?). Anecdotally, this change appears to work well, though I haven't tried a lot of cases and the accuracy of the estimated rate may be slightly lower, because I get 4.753367191% instead of 4.753367189%.

Perhaps the following is a worthy improvement:

25 IF Y<>W AND 10-V/I<>9 GOTO 24

This check works if V is close to I when V<I but not when V>I. But this might in fact still be alright when the Newton iteration hops back and forth around the root as we would actually expect to observe with Newton.

This version gives the exact rate 4.753367189%. Changing 10-V/I<>9 to 10-I/V<>9 (a forced "hop around the root") converges with 4.753367188%.

I've also slightly improved and compacted your program by computing with DEF-C followed by DEF-N or DEF-J or DEF-V or DEF-M or DEF-F to compute N, I%, PV, PMT or FV, respectively:

Code:
' TVM
' To switch begin mode on/off: DEF-B
' To enter values: DEF-N or DEF-J or DEF-V or DEF-M or DEF-F
' To calculate: press DEF-C (beep) then DEF-N or DEF-J or DEF-V or DEF-M or DEF-F

10 "B" B=B=0 : PRINT "BGN=";MID$("NY",B+1,1) : END
11 "C" C=C=0 : BEEP C : END
12 "N" AREAD N : IF C GOSUB 39 : N=LN((M*K/J-F)/(M*K/J+P))/LN(1+J)
13 PRINT "N=";N : END
14 "J" AREAD I : IF C GOSUB 30
15 PRINT "I%=";I : END
16 "V" AREAD P : IF C GOSUB 39 : P=-K*M*U-F*S
17 PRINT "PV=";P : END
18 "M" AREAD M : IF C GOSUB 39 : M=(-F*S-P)/K/U
19 PRINT "PMT=";M : END
20 "F" AREAD F : IF C GOSUB 39 : F=-(M*K*U+P)/S
21 PRINT "FV=";F : END

30 IF I=0 LET I=.01
31 GOSUB 36 : IF Y=0 RETURN
32 V=I,I=I+.01 : GOSUB 36
33 T=I,I=I-(I-V)*Y/(Y-W),V=T : GOSUB 36
34 IF Y<>W AND 10-V/I<>9 GOTO 33
35 RETURN
36 W=Y : GOSUB 39 : Y=P+K*M*U+F*S : RETURN

39 J=.01*I,S=(1+J)^-N,U=(1-S)/J,K=1+J*B,C=0 : RETURN

I left out the alternative to compute S=(1+J)^-N with the series for LN1(J)=LN(1+J) for small J.

- Rob

"I count on old friends to remain rational"
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
PC-1211, PC-1250, etc. TVM - Dave Britten - 03-30-2021, 04:58 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 03-30-2021, 05:07 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 04-01-2021, 05:50 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 05-29-2024 09:17 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 05-31-2024, 01:11 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-01-2024, 01:07 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-02-2024, 09:46 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-03-2024, 06:44 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-04-2024, 12:26 AM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-04-2024, 11:35 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-05-2024, 07:16 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-05-2024, 10:06 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-06-2024, 11:02 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-08-2024, 06:19 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-08-2024, 09:21 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-09-2024, 12:06 AM
RE: PC-1211, PC-1250, etc. TVM - rprosperi - 06-09-2024, 01:22 PM
RE: PC-1211, PC-1250, etc. TVM - nickapos - 06-12-2024, 05:20 AM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-06-2024, 11:34 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-07-2024, 02:30 AM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-08-2024, 08:38 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-09-2024, 10:12 AM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-11-2024, 07:13 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-11-2024, 10:32 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-12-2024, 12:29 AM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-12-2024, 12:45 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-12-2024, 04:58 PM
RE: PC-1211, PC-1250, etc. TVM - dm319 - 06-22-2024, 12:12 PM
RE: PC-1211, PC-1250, etc. TVM - robve - 06-22-2024, 08:39 PM



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