TVM solve for interest rate, revisited
|
06-15-2024, 12:19 PM
Post: #43
|
|||
|
|||
RE: TVM solve for interest rate, revisited
(06-10-2024 03:27 PM)Albert Chan Wrote: Lets make bottom branch more accurate, with log1p_sub / expm1_sub I figured out why Newton on f does not work well with tiny rate! Say, with non-zero a, we want to solve f(x) = g(x) - a Newton's method: x ← x - f(x)/f'(x) = x - (g(x)-a) / g'(x) With iteration zeroed-in to true root, g(x) ≈ a f(x) will get less and less accurate, due to cancellation errors. It does not matter if g(x) is super-accurate, even if correctly rounded! Cancellation errors may happen for slope too, if a is also a function of x This is normally not an issue. If f(x) only get half-precision, iterated x holds the other half. With final f turns into garbage, more Newton's iteration may make it worse. lua> x = 1 lua> for i=1,6 do f=x*x-2; print(x,f); x=x-f/(2*x) end 1 -1 1.5 0.25 1.4166666666666667 0.006944444444444642 1.4142156862745099 6.007304882871267e-06 1.4142135623746899 4.510614104447086e-12 1.4142135623730951 4.440892098500626e-16 But, that does not hold if X is very close to zero. Iterated x unable to keep its share. This is the reason tiny rate top branch is needed, to keep cancellation errors at bay. The other way is to throw in more-precision to the problem, but that is expensive. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)