How to Implement Functional Derivative?

431 views
Skip to first unread message

yueming liu

unread,
Jan 3, 2015, 2:24:09 AM1/3/15
to sy...@googlegroups.com
According to the definition, we need the limit of the function when alpha approaches 0. How to implement this on a Function object?

from sympy import *
from sympy.abc import *
from IPython.display import display

init_printing(use_latex='mathjax')

def func_diff(F, f, df):
alpha = Symbol('alpha')
F = F.subs(f, f+alpha*df)
dF = F.diff(alpha)
return simplify(dF.subs(alpha, 0))

u = Function('u')(x,y,z)
du = Function('\delta u')(x,y,z)
dfun = func_diff(u**2, u, du)
display(dfun)

Francesco Bonazzi

unread,
Jan 7, 2015, 4:32:07 PM1/7/15
to sy...@googlegroups.com
Maybe it's easier to define some if ... elif ... elif ... ... clauses to dispatch on the structure of F.

Francesco Bonazzi

unread,
Jan 7, 2015, 4:40:52 PM1/7/15
to sy...@googlegroups.com
Otherwise try to use multiple dispatch:

http://multiple-dispatch.readthedocs.org/en/latest/

That is, you dispatch on the expression type of F by defining your function many times.

Aaron Meurer

unread,
Jan 29, 2015, 4:35:53 PM1/29/15
to sy...@googlegroups.com
SymPy already supports taking derivatives with respect to functions symbolically, like F(f(x), x).diff(f(x)). Is this different from what you are looking for?

Aaron Meurer

--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/e06c4c35-a779-40af-ad1d-7743e95e2db5%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Francesco Bonazzi

unread,
Jan 30, 2015, 5:59:43 AM1/30/15
to sy...@googlegroups.com


On Thursday, January 29, 2015 at 10:35:53 PM UTC+1, Aaron Meurer wrote:
SymPy already supports taking derivatives with respect to functions symbolically, like F(f(x), x).diff(f(x)). Is this different from what you are looking for?

In [1]: f(x).diff(f(y))
Out[1]: 0


In a functional derivative, this would have yielded DiracDelta(x-y).

https://en.wikipedia.org/wiki/Functional_derivative

 
Reply all
Reply to author
Forward
0 new messages