Post Reply 
PC-1211, PC-1250, etc. TVM
06-08-2024, 08:38 PM
Post: #31
RE: PC-1211, PC-1250, etc. TVM
(06-06-2024 12:27 AM)Albert Chan Wrote:  If you have good EXP, LN, you can build accurate EXPM1 LNP1

To follow up on my reply on Albert's suggestion to use this method, I found out that this causes errors in some cases such as when the interest rate is very small and N is large. The problem is that for larger negative S=-N*L we get R=0 and LN(R) quits with an error (or NaN):
Code:
40 J=.01*I,K=1+J*B,C=0,L=1+J,L=LN L-(L-1-J)/L,S=-N*L,R=EXP S,R=R-1-(LN R-S)*R,S=R+1 : RETURN
With the EXPM1 and LNP1 series in the previous code lines 40 to 43, there is no problem.

I made one other minor change to my code. With this change I am now able to accurately compute interest rates on the SHARPs with only 10 digits BCD and limited range (1E-99 to 9.999999999E+99), even for the more challenging cases:

1) unchanged, is exact
2) unchanged, is exact
3) I%=3.170979194E-07 is almost exact 3.170979198E-07
4) I%=1.902587519E-05 is exact
5) I%=3.170979051E-07 is very close to exact 3.170979198E-07
6) I%=3.125027014E-06 is very close to exact 3.125E-06, but HP-12C also gives an inexact result 3.125004736E-06
7) I%=4.980365842E-01 is exact

The change is to replace I=.02 with I=1 on line 30:
Code:
30 G=9,I=1 : GOSUB 38

The number of secant method iterations is about the same as before. The number of iterations for the examples are: 6, 5, 4, 14, 12, 10, 3, 7. With secant, the number of function evaluations is just the number of iterations, which is nice.

Note that I use a loop on line 32 that finds a suitable starting rate and this may take a few iterations in the worst case. But this is usually not necessary and only happens for cases 3, 4 and 5 that return very low interest rates with very large values of N which is a challenging combination.

I will update my previous post to include the updated code and improved results.

- 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: 15 Guest(s)