# Problems with the VariationalD (VariationalMethods package)

I'm facing the following problem: The VariationalD function doens't commute with the series expasion. Physically this means that if I compute the equation of motion starting with an Hamiltonian with a small correction and then I expand it, the result will be different from the one I obtain computing the equation of motion starting with the leading order of the Hamiltonian.

lets take the function

$$f(x+af(x))$$

1. First differentiate and then expand

VariationalD[f[x + a f[x]], f[x], x] = a f'[x+af[x]]


or, rewritted in a friendly way $$\frac{\delta f(x + a f(x))}{\delta f(x)} = a f'(x+a f(x))$$ then I need to expand the previous result

Series[a f'[x + a f[x]], {a,0,1}] = a f'[x] + O(a^2)


So finally I get $$af'(x)+O(a^2)$$

First expand and then differentiate

Now I follow the opposite way

Series[f[x+a f[x]], {a,0,1}] = f[x] + a f[x]f'[x] + O(a^2)


Then I take the functional derivative of the previous equation

VariationalD[f[x] + a f[x]f'[x] + O(a^2), f[x], x] = 1 + O(a^2)


namely, $$\frac{\delta}{\delta f(x)} \left( f(x) + a f(x) f'(x) + O(a^2) \right) = 1 + O(a^2)$$

• Your code has numerous syntax problems. Brackets don't match and af[x] should be a f[x] (with a space) because otherwise you end up with a completely different function called af instead of multiplying a with f[x]. – Sjoerd Smit Sep 26 '19 at 9:34
• @SjoerdSmit Sorry about that, but don't worry: they are just typo in the question, not in the code I really used. I edited the text. – ACA Sep 26 '19 at 9:41