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

Updated differentiate.jl to be make finite differences based on a symbolic expression #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jckt
Copy link

@jckt jckt commented May 26, 2013

Does doing this make more sense than putting it into finite_difference and having it called by derivative()?

julia> differentiate(:(e^x),:(x))
:(*(^(e,x),log(e)))

julia> using Calculus

julia> differentiate(:(e^x),:(x),1.0)
2.718281828459045

julia> differentiate(:(e^x),:(x),0.0)
1.0

Admittedly, in its current form it messes with global variables.

@johnmyleswhite
Copy link
Collaborator

We should definitely call this differentiate for now to stick with the distinction that's been drawn between symbolic and numeric differentation. I wonder whether we should provide a macro as well as a function.

@jckt
Copy link
Author

jckt commented May 27, 2013

I just updated the proposed function to use local vars, and what I think is a safer use of eval, given the assertions, though I'm no expert -- what do you think?

julia> using Calculus

julia> differentiate(:(e^x),:x,1.0)
2.718281828459045

julia> differentiate(:(e^x),:x,2.0)
7.3890560989306495

julia> x
ERROR: x not defined

How do you think a macro can help?

Also, what do you think about the hessian and jacobian matrix functions? Should there be a symbolic and numeric version, should they be kept to one or the other type of differentiation, or should the user be able to specify which to use? Like:

julia> derivative(x->x^2, 1.0, :central)
1.9999999999829379

julia> derivative(x->x^2, 1.0, :forward)
2.000000014901161

julia> derivative(x->x^2, 1.0, :symbolic)
2.0

(The same applying to hessian/jacobians as well).

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

Successfully merging this pull request may close these issues.

2 participants