# How to find the variation of this functional according to the definition of Lagrange

The functional is : $$J(y)=y^{2}(x_{0})+\int_{x_{0}}^{x_{1}}(xy+y'^{2}) dx$$ In the textbook, the result of finding the functional variation according to the functional variation defined by Lagrange is :

The variation sign δ has the following basic operational properties :

How to use MMA to define a correlation function and find the variation of this function according to the definition of Lagrange?

You should notice that $$y$$ is a function, and $$J$$ is a function with function as argument, then things become clearly

ClearAll[\[Delta], J]
J[y_] := y[x0]^2 + Integrate[x y[x] + y'[x]^2, {x, x0, x1}]
\[Delta][F_ /; Module[{y}, FreeQ[Level[F[y], {-1}], y]]] :=
Function[y,
Evaluate[D[
F[y[#] + \[Epsilon] \[Delta][
y][#] &], \[Epsilon]] /. \[Epsilon] -> 0]]
\[Delta][J][y]


This code gives the result you want