Automatic differentiation using dual numbers
|
06-19-2022, 10:50 AM
(This post was last modified: 07-11-2022 06:00 PM by Albert Chan.)
Post: #11
|
|||
|
|||
RE: Automatic differentiation using dual numbers
Apply f to dual number {g, g'} produce {f(g), (f(g))' = f'(g) * g'}
To emphasize its "symbolic" nature, I use f and g for variables. r = x^(1/n) r' = x^(1/n-1)/n = r / (x*n) Code: D = {} -- note: f1, f2 = f, f' Example, solve (³√x + x² - 3/5*x = 0), guess x = -1 lua> x = D.new(-1,1) lua> for k=1,6 do print(D.newton(x, D.surd(x,3) + x*x - D.new(3/5)*x)) end -0.7352941176470589 0.6 -0.6875931861095272 0.07925115704554603 -0.6858395921931165 0.0027133429258336395 -0.6858371853881947 3.7138631565070135e-006 -0.6858371853836587 6.999345547598068e-012 -0.6858371853836587 0 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: 6 Guest(s)