Created
January 25, 2022 17:34
-
-
Save airicbear/ca13303932922da2f0ba8d83991fd7f9 to your computer and use it in GitHub Desktop.
Derivatives and Taylor series in Julia using ForwardDiff.jl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using FowardDiff | |
# Derivative of f | |
D(f) = x -> FowardDiff.derivative(f, x) | |
# nth Derivative of f | |
D(f, n) = let | |
F = f | |
while n > 0 | |
F = D(F) | |
n -= 1 | |
end | |
F | |
end | |
# Taylor Series approximation of f at x0 with n terms | |
T(f, x0, N) = x -> sum([D(f, n)(x0) * (x - x0)^n / factorial(n) for n ∈ 0:N]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment