# Natural boundary conditions variational methods

I am working on a problem of the calculus of variations. From the Variational Methods package, I can very conveniently use EulerEquations to get stationarity conditions in the form of Euler-Lagrange equations for my problem. Is there also a way to obtain expressions for the natural boundary conditions that are involved in making the functional stationary?

• I don't have an answer, but I would note this would be very useful for me too. – SPPearce Oct 22 '15 at 12:35

As far as I know there is no function currently in the Variational Methods package that does that. This function however should do the trick:

VariationalDBoundaries[f_,(y_)[x_,r___],boundary_]:=
Module[{varY,Dfuncs,Dtimes,dummyfunc,natural,essential,w},
w={x,r};
Dfuncs=Union[Cases[{f},Derivative[__][y][__],Infinity]];
GenerateBoundaryEqn[Dfun_]:=
Module[{Dtime,DrevList,out},
DrevList = Transpose[{w,Dtime}];
Reverse[Table[(-1)^(i+1),{i,Times@@Dtime}]];
out=Flatten[#,1]&@Table[ReplaceAll[#,w[[j]]->boundary[[j]]]&/@
{D[D[f,Dfun],Sequence@@ReplacePart[DrevList[[j;;]],{1,2}->Dtime[[j]]-i]],
D[varY[Sequence@@w],Sequence@@ReplacePart[DrevList[[1;;j]],
{j,2}->i-1]]},{j,Length[w]},{i,Dtime[[j]]}];
out[[;;,1]]=out[[;;,1]]*Reverse[Table[(-1)^(i+1),{i,Plus@@Dtime}]];
out];
natural=GenerateBoundaryEqn[#]& /@Dfuncs;
essential=Union[Flatten[natural,1][[;;,2]]];
natural = Apply[Times,#,{1}]&/@natural/.List->Plus;
natural=Coefficient[natural,#]&/@essential;
Transpose[{natural, essential}] /. varY -> y
]


It could be used with single variable fucntionals VariationalDBoundaries[f, u[x],{x1}] or multi-variable functionals VariationalDBoundaries[f, u[x,y,...],{xo,yo,...}].It returns the first variational boundary conditions of the functional defined by the integrand f which is a function of u, its derivatives, and x,y,.... The boundary conditions are evaluated at a single boundary location given by {xo,yo,..} for each variable x,y,...

The function generates a list of ordered pairs where the first element is the natural boundary condition at the given location indicated by {xo,yo,..} and the second one is the associated essential boundary condition. Usually either the natural or the essential boundary condition should be equal to zero.

For example:

L=x*y*u[x,y]*D[u[x,y],x]+x*y*u[x,y]*D[u[x,y],y];
VariationalDBoundaries[L,u[x,y],{xo,yo}]


Output: