Post Reply 
(11C) TVM for HP-11C
12-05-2020, 03:46 AM (This post was last modified: 06-16-2021 01:22 PM by Albert Chan.)
Post: #12
RE: (11C) TVM for HP-11C
A faster version of guess_i(), replaced sqrt() by its Pade approximation
This is also safer, avoided sqrt of negative number issue.

Code:
function guess_i(n, pv, pmt, fv)    -- cash-flow sign convention
    local a = (fv+pv)/n
    local b = (fv-pv)-a
    local c = (pmt+a)/b
    b = n*n*a*c/b                   -- I coef = [b/c/3, -2, 4c]
    return c * (b-3)/(b-1.5)        -- pade(4c/(1+sqrt(1-4b/3)),b,2,2)
end

lua> guess_i(12, 5000, -500, 0)
0.029199705714052143
lua> guess_i(12, 0, -400, 5000)
0.007391911604953607

Update: formula adjusted so fv+pv=0 will give i = pmt/fv, instead of NaN
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(11C) TVM for HP-11C - Gamo - 05-09-2019, 01:15 AM
RE: (11C) TVM for HP-11C - Gamo - 12-03-2019, 10:12 AM
RE: (11C) TVM for HP-11C - Gamo - 02-13-2020, 06:14 AM
RE: (11C) TVM for HP-11C - bshoring - 12-02-2020, 09:02 PM
RE: (11C) TVM for HP-11C - Gamo - 12-03-2020, 08:23 AM
RE: (11C) TVM for HP-11C - Dave Britten - 12-03-2020, 01:48 PM
RE: (11C) TVM for HP-11C - bshoring - 12-03-2020, 05:53 PM
RE: (11C) TVM for HP-11C - Dave Britten - 12-03-2020, 06:08 PM
RE: (11C) TVM for HP-11C - Albert Chan - 12-03-2020, 08:53 PM
RE: (11C) TVM for HP-11C - Albert Chan - 12-04-2020, 08:01 PM
RE: (11C) TVM for HP-11C - Albert Chan - 12-05-2020, 01:05 AM
RE: (11C) TVM for HP-11C - Albert Chan - 12-05-2020 03:46 AM
RE: (11C) TVM for HP-11C - Albert Chan - 05-10-2022, 09:35 PM
RE: (11C) TVM for HP-11C - Albert Chan - 05-11-2022, 01:07 PM
RE: (11C) TVM for HP-11C - Albert Chan - 12-06-2020, 02:32 PM
RE: (11C) TVM for HP-11C - Albert Chan - 12-06-2020, 04:41 PM
RE: (11C) TVM for HP-11C - Albert Chan - 12-07-2020, 06:55 PM
RE: (11C) TVM for HP-11C - Albert Chan - 12-08-2020, 03:05 PM
RE: (11C) TVM for HP-11C - Albert Chan - 05-14-2022, 12:26 PM



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