Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

higher-order derivatives #916

Open
ohno opened this issue Jun 11, 2023 · 0 comments
Open

higher-order derivatives #916

ohno opened this issue Jun 11, 2023 · 0 comments

Comments

@ohno
Copy link

ohno commented Jun 11, 2023

Are there any functions or issues related to higher derivatives?

I extended derivative() to support higher derivatives in preparation for the implementation of Taylor series (#59). I replaced

Symbolics.jl/src/diff.jl

Lines 420 to 426 in c0966fb

function derivative(O, v; simplify=false)
if O isa AbstractArray
Num[Num(expand_derivatives(Differential(v)(value(o)), simplify)) for o in O]
else
Num(expand_derivatives(Differential(v)(value(O)), simplify))
end
end

with

function derivative(O, v; simplify=false, n=1)
    D = n==0 ? v->v : Differential(v)^n
    if O isa AbstractArray
        Num[Num(expand_derivatives(D(Symbolics.value(o)), simplify)) for o in O]
    else
        Num(expand_derivatives(D(Symbolics.value(O)), simplify))
    end
end

to support $n$ th-order derivatives. For example, first-order derivatives are following.

julia> derivative([sin(x), cos(x)], x)
2-element Vector{Num}:
  cos(x)
 -sin(x)

Also, second-order derivatives are following.

julia> derivative([sin(x), cos(x)], x, n=2)
2-element Vector{Num}:
 -sin(x)
 -cos(x)

If you like this I will send a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant