41C/CV root finders
05-29-2015, 06:15 PM (This post was last modified: 05-29-2015 06:27 PM by Dieter.)
Post: #41
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: 41C/CV root finders
(05-29-2015 08:04 AM)Ángel Martin Wrote:  The formulas are posted below, but this is certainly strange - I need to revise the implementation, it might be something goofed up in the way I program them...

That's probably true. See below.

(05-29-2015 08:04 AM)Ángel Martin Wrote:  f(i) = PV + (1+ip) PMT [ (1- (1+i)^-n) / i] + FV (1+i)^-n
f ’ (i) = (PMT / i^2 ) * [ (1+i)^(-n) - 1 ] + n * [PMT (1 + ip)/i – FV ] * (1+i)^-(n+1)

where p=1 in Begin mode or 0 in End mode.

The formulas look a bit complicated, and I hope they are implemented efficiently, but anyway: they seem to be correct. So I tried Newton's method based on your formulas, and now look what happens even with a less-than-optimal initial guess like the one you posted. The calculations were done in Excel, so the results may slighty differ, but the essential point should be clear:

Code:
#          i                       f(i)                     f'(i)                   f(i)/f'(i)               new i --------------------------------------------------------------------------------------------------------------------------- 0   1,6504 75667 020 E-02   1,1512 56813 905 E+02   -1,8922 05978 309 E+03   -6,0842 04505 758 E-02   7,7346 80172 779 E-02 1   7,7346 80172 779 E-02   3,6157 27302 052 E+01   -8,3765 28811 450 E+02   -4,3164 98377 119 E-02   1,2051 17854 990 E-01 2   1,2051 17854 990 E-01   9,0500 96755 600 E+00   -4,5257 59747 816 E+02   -1,9996 85635 095 E-02   1,4050 86418 499 E-01 3   1,4050 86418 499 E-01   1,2439 53188 362 E+00   -3,3307 99490 524 E+02   -3,7346 98506 773 E-03   1,4424 33403 567 E-01 4   1,4424 33403 567 E-01   3,6176 85118 950 E-02   -3,1385 44999 486 E+02   -1,1526 63135 160 E-04   1,4435 86066 702 E-01 5   1,4435 86066 702 E-01   3,3398 41367 733 E-05   -3,1327 51375 488 E+02   -1,0661 04828 447 E-07   1,4435 87132 807 E-01 6   1,4435 87132 807 E-01   2,8876 45678 129 E-11   -3,1327 46020 753 E+02   -9,2176 18214 181 E-14   1,4435 87132 808 E-01

With the estimate I suggested things look like this:

Code:
#          i                       f(i)                     f'(i)                   f(i)/f'(i)               new i --------------------------------------------------------------------------------------------------------------------------- 0   8,5714 28571 429 E-02   2,9538 18144 886 E+01   -7,4603 90801 804 E+02   -3,9593 34334 298 E-02   1,2530 76290 573 E-01 1   1,2530 76290 573 E-01   6,9556 69566 821 E+00   -4,2116 88482 615 E+02   -1,6515 15679 646 E-02   1,4182 27858 537 E-01 2   1,4182 27858 537 E-01   8,1076 20873 942 E-01   -3,2621 35750 476 E+02   -2,4853 72005 981 E-03   1,4430 81578 597 E-01 3   1,4430 81578 597 E-01   1,5844 14941 007 E-02   -3,1352 86065 219 E+02   -5,0534 94029 090 E-05   1,4435 86928 000 E-01 4   1,4435 86928 000 E-01   6,4161 18566 221 E-06   -3,1327 47049 439 E+02   -2,0480 80634 972 E-08   1,4435 87132 808 E-01 5   1,4435 87132 808 E-01   1,0231 81539 495 E-12   -3,1327 46020 748 E+02   -3,2660 85194 006 E-15   1,4435 87132 808 E-01 6   1,4435 87132 808 E-01   0,0000 00000 000 E+00   -3,1327 46020 748 E+02    0,0000 00000 000 E+00   1,4435 87132 808 E-01

And here are the results for BEGIN mode with the better estimate:

Code:
#          i                       f(i)                     f'(i)                   f(i)/f'(i)               new i --------------------------------------------------------------------------------------------------------------------------- 0   8,5714 28571 429 E-02   1,2719 70870 681 E+01   -8,6744 78838 720 E+02   -1,4663 36934 276 E-02   1,0037 76550 570 E-01 1   1,0037 76550 570 E-01   1,1771 83138 188 E+00   -7,1156 23484 535 E+02   -1,6543 64007 239 E-03   1,0203 20190 643 E-01 2   1,0203 20190 643 E-01   1,3189 32492 805 E-02   -6,9567 11221 997 E+02   -1,8959 13817 199 E-05   1,0205 09782 025 E-01 3   1,0205 09782 025 E-01   1,7088 07900 513 E-06   -6,9549 08670 105 E+02   -2,4569 81078 499 E-09   1,0205 09806 594 E-01 4   1,0205 09806 594 E-01  -3,9790 39320 257 E-13   -6,9549 08436 533 E+02    5,7211 95838 259 E-16   1,0205 09806 594 E-01 5   1,0205 09806 594 E-01   0,0000 00000 000 E+00   -6,9549 08436 533 E+02    0,0000 00000 000 E+00   1,0205 09806 594 E-01 6   1,0205 09806 594 E-01   0,0000 00000 000 E+00   -6,9549 08436 533 E+02    0,0000 00000 000 E+00   1,0205 09806 594 E-01

So in all cases 4 – 6 iterations will do, depending on the initial estimate.

That's why I wonder why 7 to 13 iterations are required before the solver in the TVM ROM converges. This sounds like an error in the implementation. Maybe you can compare the results of every iteration step with the ones in the tables above.

By the way, here are the results for an initial estimate of 0,0001:

Code:
END mode: #          i                       f(i)                     f'(i)                   f(i)/f'(i)               new i --------------------------------------------------------------------------------------------------------------------------- 0   1,0000 00000 000 E-04   1,4976 51539 336 E+02   -2,3469 21996 559 E+03   -6,3813 43485 345 E-02   6,3913 43485 345 E-02 1   6,3913 43485 345 E-02   4,8510 92508 382 E+01   -1,0063 21939 891 E+03   -4,8206 16858 364 E-02   1,1211 96034 371 E-01 2   1,1211 96034 371 E-01   1,3094 15813 711 E+01   -5,1222 53398 655 E+02   -2,5563 27678 077 E-02   1,3768 28802 179 E-01 3   1,3768 28802 179 E-01   2,2064 35164 358 E+00   -3,4822 77391 105 E+02   -6,3361 84388 970 E-03   1,4401 90646 068 E-01 4   1,4401 90646 068 E-01   1,0669 34219 175 E-01   -3,1498 41444 676 E+02   -3,3872 63257 263 E-04   1,4435 77909 326 E-01 5   1,4435 77909 326 E-01   2,8895 04148 129 E-04   -3,1327 92347 864 E+02   -9,2234 14217 349 E-07   1,4435 87132 740 E-01 6   1,4435 87132 740 E-01   2,1364 88319 593 E-09   -3,1327 46021 090 E+02   -6,8198 58058 105 E-12   1,4435 87132 808 E-01 7   1,4435 87132 808 E-01  -1,1368 68377 216 E-13   -3,1327 46020 748 E+02    3,6289 83548 895 E-16   1,4435 87132 808 E-01 BEGIN mode: #          i                       f(i)                     f'(i)                   f(i)/f'(i)               new i --------------------------------------------------------------------------------------------------------------------------- 0   1,0000 00000 000 E-04   1,4973 51704 270 E+02   -2,6465 92194 474 E+03   -5,6576 59337 907 E-02   5,6676 59337 907 E-02 1   5,6676 59337 907 E-02   4,3448 06469 682 E+01   -1,2732 67705 318 E+03   -3,4123 27550 236 E-02   9,0799 86888 143 E-02 2   9,0799 86888 143 E-02   8,4553 78795 595 E+00   -8,1017 60264 595 E+02   -1,0436 47123 520 E-02   1,0123 63401 166 E-01 3   1,0123 63401 166 E-01   5,6973 99825 850 E-01   -7,0327 39452 499 E+02   -8,1012 52526 604 E-04   1,0204 64653 693 E-01 4   1,0204 64653 693 E-01   3,1404 39865 149 E-03   -6,9553 37692 589 E+02   -4,5151 50815 028 E-06   1,0205 09805 201 E-01 5   1,0205 09805 201 E-01   9,6905 58044 895 E-08   -6,9549 08449 779 E+02   -1,3933 40849 110 E-10   1,0205 09806 594 E-01 6   1,0205 09806 594 E-01   0,0000 00000 000 E+00   -6,9549 08436 533 E+02    0,0000 00000 000 E+00   1,0205 09806 594 E-01

So in fact just one more iteration is required.

(05-29-2015 08:04 AM)Ángel Martin Wrote:  PS.- You don't need the Library#4 for the TVM\$ module - althought it doesn't hurt to have it always configured on V41 of course. You'll need it for the SandMath, SandMatrix and 41Z if you decide to venture there.

OK, good to know. I now am looking a bit into the functions of the Sandmath ROM.

Dieter
 « Next Oldest | Next Newest »

 Messages In This Thread 41C/CV root finders - Dave Britten - 05-20-2015, 07:07 PM RE: 41C/CV root finders - Thomas Klemm - 05-20-2015, 07:36 PM RE: 41C/CV root finders - Dieter - 05-20-2015, 07:44 PM RE: 41C/CV root finders - Dave Britten - 05-20-2015, 08:08 PM RE: 41C/CV root finders - Massimo Gnerucci - 05-20-2015, 08:40 PM RE: 41C/CV root finders - Dave Britten - 05-20-2015, 08:49 PM RE: 41C/CV root finders - Didier Lachieze - 05-21-2015, 11:12 AM RE: 41C/CV root finders - Dieter - 05-21-2015, 11:40 AM RE: 41C/CV root finders - Dave Britten - 05-21-2015, 12:51 PM RE: 41C/CV root finders - Dieter - 05-21-2015, 07:36 PM RE: 41C/CV root finders - Dieter - 05-22-2015, 08:34 AM RE: 41C/CV root finders - bshoring - 05-27-2015, 10:09 PM RE: 41C/CV root finders - Dieter - 05-27-2015, 11:16 PM RE: 41C/CV root finders - Ángel Martin - 05-28-2015, 06:19 AM RE: 41C/CV root finders - Dieter - 05-28-2015, 08:42 AM RE: 41C/CV root finders - bshoring - 05-28-2015, 09:37 PM RE: 41C/CV root finders - Ángel Martin - 05-22-2015, 01:14 PM RE: 41C/CV root finders - Dieter - 05-22-2015, 07:07 PM RE: 41C/CV root finders - Dieter - 05-24-2015, 07:10 PM RE: 41C/CV root finders - Ángel Martin - 05-25-2015, 05:35 AM RE: 41C/CV root finders - Dieter - 05-25-2015, 07:19 PM RE: 41C/CV root finders - Ángel Martin - 05-26-2015, 05:06 AM RE: 41C/CV root finders - Dieter - 05-26-2015, 05:39 PM RE: 41C/CV root finders - Ángel Martin - 05-26-2015, 09:26 PM RE: 41C/CV root finders - Dieter - 05-26-2015, 10:08 PM RE: 41C/CV root finders - rprosperi - 05-27-2015, 12:30 AM RE: 41C/CV root finders - Dieter - 05-27-2015, 11:08 PM RE: 41C/CV root finders - Ángel Martin - 05-28-2015, 05:44 AM RE: 41C/CV root finders - Dieter - 05-28-2015, 09:50 PM RE: 41C/CV root finders - Ángel Martin - 05-29-2015, 07:58 AM RE: 41C/CV root finders - Ángel Martin - 05-27-2015, 05:17 AM RE: 41C/CV root finders - Dieter - 05-27-2015, 01:50 PM RE: 41C/CV root finders - Ángel Martin - 05-27-2015, 03:03 PM RE: 41C/CV root finders - Dieter - 05-27-2015, 07:15 PM RE: 41C/CV root finders - Dieter - 05-28-2015, 09:59 AM RE: 41C/CV root finders - Ángel Martin - 05-28-2015, 11:27 AM RE: 41C/CV root finders - Ángel Martin - 05-28-2015, 01:54 PM RE: 41C/CV root finders - Dieter - 05-28-2015, 06:33 PM RE: 41C/CV root finders - Ángel Martin - 05-29-2015, 08:04 AM RE: 41C/CV root finders - Ángel Martin - 05-29-2015, 05:54 PM RE: 41C/CV root finders - Dieter - 05-29-2015 06:15 PM RE: 41C/CV root finders - Ángel Martin - 05-29-2015, 06:44 PM RE: 41C/CV root finders - Dieter - 05-29-2015, 07:19 PM RE: 41C/CV root finders - Dieter - 05-30-2015, 12:37 PM RE: 41C/CV root finders - Ángel Martin - 05-30-2015, 02:04 PM RE: 41C/CV root finders - Dieter - 05-29-2015, 08:00 PM