# Computing a functional derivative using the VariationalMethods package

To test the VariationalMethods toolbox, I tried to compute $$\frac{\delta I[y]}{\delta y(x)}$$ for the following functional, assuming $$w(x)$$ is some well-behaved function:

$$\qquad I[y(x)]=\int y(x) g\left(\int w(t) y(t-x)dt\right)dx$$

$$\qquad \frac{\delta I[y]}{\delta y(x)}= g\left(\int w(t) y(t-x)dt\right) + \int w(x)y(x)g'\left(\int w(t) y(t-x)dt\right)dx$$,

where $$g'(x)$$ is the derivative of $$g(x)$$.

Mathematica did not find the above result.

These are the commands I run:

<< VariationalMethods
VariationalD[y[x]*g[Integrate[w[t]*y[t - x], t]], y[x], x]


The the above code gives only the first term of the exact answer. What am I doing wrong? Is it even possible to compute such variations with Mathematica?

• Please note that the answer below (after resolving Dirac Deltas), which in my eyes is correct, differs from yours, posted above. Concerning the toolbox you have mentioned, it seems that it is restricted to local functionals, i.e., whose integrand involves function values and their derivatives at the same point, thus my assumption would be that due to the fact you variate y[x] the value of y[t-x] is not variated. Anyway, I am also disappointed with the capabilities of the package you mentioned.
– MK.
Mar 4, 2019 at 17:30

You could use FunctionalD from my answer to Non-trivial functional derivatives, which I repeat here:

FunctionalD[expr_, v:(f_[_]|{f_[_],_Integer}) .., OptionsPattern[]] := InternalInheritedBlock[{f},
f /: D[f[x_], f[y_], NonConstants->{f}] := DiracDelta[x-y];
f /: D[f, f[y_], NonConstants->{f}] := DiracDelta[#-y]&;

D[expr, v, NonConstants->{f}]
]


Then, for your example, we have:

Assuming[
(s|x) ∈ Reals,
FunctionalD[
Integrate[y[x] g[Integrate[w[t] y[t-x], {t, -∞, ∞}]], {x, -∞, ∞}],
y[s]
]
] //TeXForm
`

$$\int_{-\infty }^{\infty } \left(\delta (x-s) g\left(\int_{-\infty }^{\infty } w(t) y(t-x) \, dt\right)+y(x) w(s+x) g'\left(\int_{-\infty }^{\infty } w(t) y(t-x) \, dt\right)\right) \, dx$$

You still need to distribute integrand, and resolve the Dirac delta function, but both terms are there.