I was wondering if it is possible to numerically compute $$\frac{\delta L}{\delta f}$$ where $L$ is a functional of the function $f$ known only in a discrete number of point by numerical computation of $L(f)$. Looking online I found few resources among which, this answer on SE. Following the ideas in that answer I tried a numerical test.
- I have a discrete function $f_i$ and functional $L(f_i)$ known in every point $i$ of my mesh.
- So I brutally apply first order finite difference to compute $$\left.\frac{\delta L}{\delta f}\right|_i=\frac{L(f_{i+1})-L(f_{i})}{f_{i+1}-f_{i}}$$
For simple test case ($f=\cos(x),\log(x),\exp(x)$ and $F=\cos(f),\sin(f),\log(f)$), the algorithm seems to work fine. Now the question, is this only a coincidence or this kind of computation for the functional derivative is consistent for every case ?
If $L$ depends only on $f$ at the point, i.e., $L(f)=\int_I F(f(x))\,\mathrm{d}x$ then its functional derivative is $F'(f(x))$ so your method works. For more complicated $L$ your method breaks down, e.g., $L(f)=\int_{-1}^1 f(x)f(-x)\,\mathrm{d}x$ or $L(f)=\int_I f'^2$.