Post Reply 
Automatic differentiation using dual numbers
06-19-2022, 02:40 PM (This post was last modified: 07-11-2022 05:28 PM by Albert Chan.)
Post: #13
RE: Automatic differentiation using dual numbers
(06-18-2022 02:09 PM)Thomas Klemm Wrote:  Find a root of : \(x^x = \pi\)

Code:
00 { 28-Byte Prgm }
01▸LBL "f(x)"
02 RCL "x"
03 XEQ "LN"
04 RCL "x"
05 XEQ "*"
06 XEQ "E↑X"
07 PI
08 -
09 END

Hint: As already mentioned we can not use Y↑X here since the exponent is not a constant.

Removing constant exponent limitation is not hard.

r = f^g
r' = (exp(ln(f)*g))' = r * (ln(f)*g)' = r * (ln(f)*g' + (f'/f)*g)

Code:
function D.__pow(f,g)
    local r = pow(f[1],g[1])
    return D.new(r, r*(log(f[1])*g[2] + f[2]/f[1]*g[1]))
end

We add above pow rule here

lua> x = D.new(2,1)
lua> for k=1,6 do print(D.newton(x, x^x - D.new(pi))) end
1.8732526982494337      0.8584073464102069
1.8544597179031999      0.09913010983767823
1.8541060899613326      0.001798101943065511
1.854105967921041        6.201137425776437e-007
1.8541059679210263      7.416289804496046e-014
1.8541059679210263      -4.440892098500626e-016

Note: outputs are (extrapolated x, f(x)); Shift up 2nd column to get points (x, f(x))
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Automatic differentiation using dual numbers - Albert Chan - 06-19-2022 02:40 PM
Fixed Point Iteration - Thomas Klemm - 06-19-2022, 08:31 PM



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