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 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" |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 15 Guest(s)