Post Reply 
Looking for TVM contributions
06-18-2024, 06:15 PM (This post was last modified: 06-18-2024 11:47 PM by Albert Chan.)
Post: #63
RE: Looking for TVM contributions
Hi, robve

I was looking at your test samples pdf. #23 just quit, returned NaN

Fix is simple, have Secant's initial 2 points guaranteed one-sided convergence.
Bonus: this allowed for simple no solution test, just like Newton's method.

1st point = edge (X = -PV or FV)  --> edge rate = PMT/X

I recently showed edge rate is really result of Newton's from *extreme* rates, -1 or ∞
Turns out, whatever edge X we pick, slope (from extreme) is -X !

2nd point = PMT/X + f(PMT/X) / X      // not as good as Newton on PMT/X, but good enough

Just as Newton's final half-correction, we do the same for Secants.

10 INPUT "B,N,P,M,F? ";B,N,P,M,F
20 IF B THEN P=P+M @ F=F-M ! end mode
30 IF ABS(P)>ABS(F) THEN X=F @ F=-P @ P=-X @ N=-N ! time reversed
40 DEF FNF(I) @ IF N*I*I+1-1 THEN FNF=((P+F)/EXPM1(LOGP1(I)*N)+P)*I+M @ END
50 Z=P+F @ FNF=(Z+N*M+I*((Z+N*(P-F))/2+I*Z*(N*N-1)/12))/N @ END DEF
60 X=F @ IF M/X<=-1 THEN X=-P ! guess = edge X
70 I0=M/X @ Y0=FNF(I0) @ I=I0+Y0/X @ Y=FNF(I) @ DISP 100*I0,Y0
80 DISP 100*I,Y @ Z=I-I0 @ I0=I @ I=I-Y*Z/(Y-Y0) @ Y0=Y @ Y=FNF(I)
90 IF SGN(Y)=SGN(Y0) AND ABS(Y)<ABS(Y0) THEN 80
100 DISP 100*I,Y @ IF Y-Y0 THEN J=I-Y*(I-I0)/(Y-Y0)/2 @ DISP 100*J

Code use small edge (LINE 60), but we can use the other, as long as edge rate is valid.

>run ! sample #23
B,N,P,M,F? 0,10,50,-30,80
-37.5                      .4474481846
-36.9406897692      .0348105026
-36.8935058326      .0000999938
-36.8933699054      .0000000229
-36.8933698743      .0000000002
-36.893369874        0
-36.893369874
>X=-P @ run 70 ! small P, big edge
 60                         .7159170954
 58.5681658092      .0493058621
 58.4622602744      .0001415644
 58.4619553284      .0000000289
 58.4619552661      -.0000000001
 58.4619552662

Although -X slope proof assumed positive N, time-symmetry make it valid for negative N too
Example, if we swap (P, F), code will do time-reversal to keep size of P small.

>run
B,N,P,M,F? 0,10,80,-30,50
37.5                      2.1052759718
34.8684050352      .291631744
34.4452478265      .0037390629
34.4397519889      .0000071623
34.4397414412      0
34.4397414412
>X=-P @ run 70 ! small P, big edge
-60                       .0081797505
-59.983640499      .0000312799
-59.983577699      .0000000002
-59.9835776986     0
-59.9835776986

Lets test tiny rate branch (LINE 50)

>run ! sample #21
B,N,P,M,F? 0,480,100000,-208.333333,0
 .208333333             121.444894064
 .086888438936        46.544537395
 1.14202213657E-2   5.774169845
 7.319118817E-4      .366932959
 6.607422444E-6      .003310945
 3.19310587E-9        1.93321242436E-6
-6.652600197E-10    1.03444729167E-11
-6.65280665633E-10 -0
-6.65280665633E-10

What about no solution case?
Y get worse no sign change, and I not converging.

B,N,P,M,F? 0,10,1000,-287,2000
-14.35                    116.137711015
-8.54311444925      61.534445887
-1.99911961932      20.995382798
 1.39004791475      8.609614417
 3.74593127745      3.290957549
 5.20365121116      1.292347407
 6.14624653622      .507826981
 6.75639679154      .207532994
 7.17807126641      .093719606
 7.52529900771      .056815067
 8.05986109467      .099136777
 6.80767250381

Update: I made a stupid mistake, using X for everything.
Now X refer only to edge, and I use Z for temp variable.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Looking for TVM contributions - dm319 - 05-12-2024, 06:58 PM
RE: Looking for TVM contributions - dm319 - 05-12-2024, 08:48 PM
RE: Looking for TVM contributions - dm319 - 05-12-2024, 08:49 PM
RE: Looking for TVM contributions - dm319 - 05-12-2024, 08:00 PM
RE: Looking for TVM contributions - dm319 - 05-14-2024, 11:04 AM
RE: Looking for TVM contributions - dm319 - 05-14-2024, 05:58 PM
RE: Looking for TVM contributions - dm319 - 05-14-2024, 05:59 PM
RE: Looking for TVM contributions - dm319 - 05-14-2024, 08:34 PM
RE: Looking for TVM contributions - dm319 - 05-14-2024, 08:31 PM
RE: Looking for TVM contributions - dm319 - 05-15-2024, 01:00 PM
RE: Looking for TVM contributions - dm319 - 05-15-2024, 12:57 PM
RE: Looking for TVM contributions - dm319 - 05-24-2024, 10:05 PM
RE: Looking for TVM contributions - dm319 - 05-25-2024, 01:43 PM
RE: Looking for TVM contributions - dm319 - 05-25-2024, 08:40 PM
RE: Looking for TVM contributions - dm319 - 05-24-2024, 11:22 AM
RE: Looking for TVM contributions - dm319 - 05-24-2024, 02:58 PM
RE: Looking for TVM contributions - dm319 - 05-24-2024, 09:22 PM
RE: Looking for TVM contributions - dm319 - 06-02-2024, 02:46 PM
RE: Looking for TVM contributions - robve - 06-09-2024, 02:04 AM
RE: Looking for TVM contributions - dm319 - 06-09-2024, 12:15 PM
RE: Looking for TVM contributions - robve - 06-09-2024, 03:29 PM
RE: Looking for TVM contributions - dm319 - 06-09-2024, 06:05 PM
RE: Looking for TVM contributions - dm319 - 06-09-2024, 10:00 PM
RE: Looking for TVM contributions - robve - 06-12-2024, 08:48 PM
RE: Looking for TVM contributions - robve - 06-14-2024, 03:23 PM
RE: Looking for TVM contributions - robve - 06-14-2024, 10:11 PM
RE: Looking for TVM contributions - robve - 06-15-2024, 03:54 AM
RE: Looking for TVM contributions - dm319 - 06-12-2024, 11:56 PM
RE: Looking for TVM contributions - robve - 06-15-2024, 03:05 AM
RE: Looking for TVM contributions - robve - 06-15-2024, 05:48 PM
RE: Looking for TVM contributions - robve - 06-15-2024, 09:52 PM
RE: Looking for TVM contributions - robve - 06-15-2024, 01:38 PM
RE: Looking for TVM contributions - robve - 06-16-2024, 05:18 PM
RE: Looking for TVM contributions - Werner - 06-17-2024, 05:11 PM
RE: Looking for TVM contributions - robve - 06-16-2024, 08:26 PM
RE: Looking for TVM contributions - dm319 - 06-16-2024, 11:55 PM
RE: Looking for TVM contributions - robve - 06-17-2024, 09:03 PM
RE: Looking for TVM contributions - robve - 06-18-2024, 03:27 AM
RE: Looking for TVM contributions - Albert Chan - 06-18-2024 06:15 PM
RE: Looking for TVM contributions - robve - 06-19-2024, 12:57 AM
RE: Looking for TVM contributions - robve - 06-19-2024, 02:01 AM
RE: Looking for TVM contributions - robve - 06-19-2024, 03:47 PM
RE: Looking for TVM contributions - robve - 06-20-2024, 04:03 AM
RE: Looking for TVM contributions - robve - 06-20-2024, 05:07 PM
RE: Looking for TVM contributions - robve - 06-20-2024, 04:30 PM
RE: Looking for TVM contributions - robve - 06-20-2024, 06:27 PM
RE: Looking for TVM contributions - robve - 06-20-2024, 02:33 AM
RE: Looking for TVM contributions - robve - 06-21-2024, 09:04 PM
RE: Looking for TVM contributions - robve - 06-22-2024, 08:00 PM
RE: Looking for TVM contributions - robve - 06-23-2024, 06:03 PM
RE: Looking for TVM contributions - dm319 - 07-05-2024, 09:39 PM
RE: Looking for TVM contributions - dm319 - 07-05-2024, 09:44 PM



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