Automatic differentiation using dual numbers
|
06-20-2022, 12:52 PM
(This post was last modified: 07-11-2022 05:43 PM by Albert Chan.)
Post: #15
|
|||
|
|||
RE: Automatic differentiation using dual numbers
(05-17-2022 01:31 PM)Albert Chan Wrote: lua> n, pv, pmt, fv = 10, 50, -30, 100 Perhaps we can extend idea of automatic differentiation to higher derivatives? Let's check if we can repeat above Halley's method rate iterations. Since we need 3 numbers, lets call it T (for triple) number. Code: T = {} -- note: f1, f2, f3 = f, f', f'' It work ! lua> n, pv, pmt, fv = T.new(10), T.new(50), T.new(-30), T.new(100) lua> function f(x) return ((pv+fv)/T.expm1(T.log1p(x)*n) + pv)*x + pmt end lua> x = T.new(pmt[1]/fv[1], 1) -- small edge lua> for k=1,3 do print(T.halley(x, f(x))) end -0.2844446981069045 1.3080888941077191 -0.28443599888025756 0.0007214129592014729 -0.28443599888025595 1.3500311979441904e-013 Note: outputs are (extrapolated x, f(x)); Shift up 2nd column to get points (x, f(x)) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)