Main Content

functionalDerivative

Functional derivative (variational derivative)

Description

G = functionalDerivative(f,y) returns the functional derivative δSδy(x) of the functional S[y]=abf[x,y(x),y'(x),...]dx with respect to the function y = y(x), where x represents one or more independent variables. The functional derivative relates the change in the functional S[y] with respect to a small variation in y(x).The functional derivative is also known as the variational derivative.

If y is a vector of symbolic functions, functionalDerivative returns a vector of functional derivatives with respect to the functions in y, where all functions in y must depend on the same independent variables.

example

Examples

collapse all

Find the functional derivative of the functional S[y]=bay(x)sin(y(x))dx with respect to the function y, where the integrand is f[y(x)]=y(x)sin(y(x)).

Declare y(x) as a symbolic function and define f as the integrand of S. Use f and y as the parameters of functionalDerivative.

syms y(x)
f = y*sin(y);
G = functionalDerivative(f,y)
G(x) = sin(y(x))+cos(y(x))y(x)

Find the functional derivative of the functional S[u,v]=ba(u2(x)dv(x)dx+v(x)d2u(x)dx2)dx with respect to the functions u and v, where the integrand is f[u(x),v(x),u(x),v(x)]=u2dvdx+vd2udx2.

Declare u(x) and v(x) as symbolic functions, and define f as the integrand of S.

syms u(x) v(x)
f = u^2*diff(v,x) + v*diff(u,x,x);

Specify a vector of symbolic functions [u v] as the second input argument in functionalDerivative.

G = functionalDerivative(f,[u v])
G(x) = 

(2x2 v(x)+2u(x)x v(x)2x2 u(x)-2u(x)x u(x))

functionalDerivative returns a vector of symbolic functions containing the functional derivatives of the integrand f with respect to u and v, respectively.

Find the Euler–Lagrange equation of a mass m that is connected to a spring with spring constant k.

Define the kinetic energy T, potential energy V, and Lagrangian L of the system. The Lagrangian is the difference between the kinetic and potential energy.

syms m k x(t)
T = 1/2*m*diff(x,t)^2;
V = 1/2*k*x^2;
L = T - V
L(t) = 

mt x(t)22-kx(t)22

In Lagrangian mechanics, the action functional of the system is equal to the integral of the Lagrangian over time, or S[x]=t1t2L[t,x(t),x˙(t)]dt. The Euler–Lagrange equation describes the motion of the system for which S[x(t)] is stationary.

Find the Euler–Lagrange equation by taking the functional derivative of the integrand L and setting it equal to 0.

eqn = functionalDerivative(L,x) == 0
eqn(t) = 

-m2t2 x(t)-kx(t)=0

eqn is the differential equation that describes mass-spring oscillation.

Solve eqn using dsolve. Assume the mass m and spring constant k are positive. Set the initial conditions for the oscillation amplitude as x(0)=10 and the initial velocity of the mass as x˙(0)=0.

assume(m,'positive')
assume(k,'positive')
Dx(t) = diff(x(t),t);
xSol = dsolve(eqn,[x(0) == 10, Dx(0) == 0])
xSol = 

10cos(ktm)

Clear assumptions for further calculations.

assume([k m],'clear')

The Brachistochrone problem is to find the quickest path of descent of a particle under gravity without friction. The motion is confined to a vertical plane. The time for a body to move along a curve y(x) from point a to b under gravity g is given by

t=ab1+y22gydx.

Find the quickest path by minimizing the change in t with respect to small variations in the path y. The condition for a minimum is δtδy(x)=0.

Compute the functional derivative to obtain the differential equation that describes the Brachistochrone problem. Use simplify to simplify the equation to its expected form.

syms g y(x)
assume(g,'positive')
f = sqrt((1 + diff(y)^2)/(2*g*y));
eqn = functionalDerivative(f,y) == 0;
eqn = simplify(eqn)
eqn(x) = 

2y(x)2x2 y(x)+x y(x)2=-1

This equation is the standard differential equation of the Brachistochrone problem. To find the solutions of the differential equation, use dsolve. Specify the 'Implicit' option to true to return implicit solutions, which have the form F(y(x))=g(x).

sols = dsolve(eqn,'Implicit',true)
sols = 

(y(x)=C5+xiy(x)=C4-xiσ1=C3-xC1+y(x)y(x)=0σ1=C2+x)where  σ1=C1atan(-C1y(x)-1)-y(x)-C1y(x)-1

The symbolic solver dsolve returns general solutions in the complex space. Symbolic Math Toolbox™ does not accept the assumption that the symbolic function y(x) is real.

Depending on the boundary conditions, there are two real-space solutions to the Brachistochrone problem. One of the two solutions below describes a cycloid curve in real space.

solCycloid1 = sols(3)
solCycloid1 = 

C1atan(-C1y(x)-1)-y(x)-C1y(x)-1=C3-x

solCycloid2 = sols(5)
solCycloid2 = 

C1atan(-C1y(x)-1)-y(x)-C1y(x)-1=C2+x

Another solution in real space is a horizontal straight line, where y is a constant.

solStraight = simplify(sols(4))
solStraight = C1+y(x)=0

To illustrate the cycloid solution, consider an example with boundary conditions y(0)=5 and y(4)=1. In this case, the equation that can satisfy the given boundary conditions is solCycloid1. Substitute the two boundary conditions into solCycloid1.

eq1 = subs(solCycloid1,[x y(x)],[0 5]);
eq2 = subs(solCycloid1,[x y(x)],[4 1]);

The two equations, eq1 and eq2, have two unknown coefficients, C1 and C3. Use vpasolve to find numerical solutions for the coefficients. Substitute these solutions into solCycloid1.

coeffs = vpasolve([eq1 eq2]);
eqCycloid = subs(solCycloid1,{'C1','C3'},{coeffs.C1,coeffs.C3})
eqCycloid = 

-6.4199192418473511250705556729108atan(6.4199192418473511250705556729108y(x)-1)-y(x)6.4199192418473511250705556729108y(x)-1=-x-5.8078336827583088482183433150164

The implicit equation eqCycloid describes the cycloid solution of the Brachistochrone problem in terms of x and y(x).

You can then use fimplicit to plot eqCycloid. Since fimplicit only accepts implicit symbolic equations that contain symbolic variables x and y, convert the symbolic function y(x) to a symbolic variable y. Use mapSymType to convert y(x) to y. Plot the cycloid solution within the boundary conditions 0<x<4 and 1<y<5.

funToVar = @(obj) sym('y');
eqPlot = mapSymType(eqCycloid,'symfun',funToVar);
fimplicit(eqPlot,[0 4 1 5])

Figure contains an axes object. The axes object contains an object of type implicitfunctionline.

For a function u(x,y) that describes a surface in 3-D space, the surface area can be determined by the functional

F[u]=y1y2x1x2f[x,y(x),u(x,y),ux,uy]dxdy=y1y2x1x21+ux2+uy2dxdy

where ux and uy are the partial derivatives of u with respect to x and y.

Find the functional derivative of the integrand f with respect to u.

syms u(x,y)
f = sqrt(1 + diff(u,x)^2 + diff(u,y)^2);
G = functionalDerivative(f,u)
G(x, y) = 

-y u(x,y)22x2 u(x,y)+2x2 u(x,y)+σ122y2 u(x,y)-2y σ1y u(x,y)σ1+2y2 u(x,y)σ12+y u(x,y)2+13/2where  σ1=x u(x,y)

The result is the equation G that describes the minimal surface of a 3-D surface defined by u(x,y). The solutions to this equation describe minimal surfaces in 3-D space, such as soap bubbles.

Input Arguments

collapse all

Integrand of a functional, specified as a symbolic variable, function, or expression. The argument f represents the density of the functional.

Differentiation function, specified as an unassigned symbolic function or a vector, matrix, or multidimensional array of unassigned symbolic functions. The argument y can be a function of one or more independent variables. If y is a vector of symbolic functions, functionalDerivative returns a vector of functional derivatives with respect to the functions in y, where all functions in y must depend on the same independent variables.

Example: syms y(x); G = functionalDerivative(y*sin(y),y)

Output Arguments

collapse all

Functional derivative, returned as a symbolic function or a vector of symbolic functions. If input y is a vector, matrix, or an array, then G is a vector.

More About

collapse all

Functional Derivative

Consider a functional

S[y]=abf[x,y(x),y'(x),...,y(n)(x)]dx,

which can take any path from a to b in the x-space.

For a small variation in the path y(x), define the change as δy(x)=εϕ(x) in which ϕ(x) is an arbitrary test function. The change in the functional S is

DS[y]=limε0S[y+εϕ]S[y]ε=abδSδy(x)ϕ(x)dx.

The expression δSδy(x) is the functional derivative of S with respect to y. The linear functional DS[y] is also known as the first variation or the Gateaux differential of the functional S.

One method to calculate the functional derivative is to apply Taylor expansion to the expression S[y + εϕ] with respect to ε. By keeping the first order terms in ε, performing integration by parts, and choosing the boundary conditions ϕ(a) = ϕ(b) = ϕ'(a) = ϕ'(b) = ... = 0, the functional derivative becomes

δSδy(x)=fyddxfy'+d2dx2fy''...+(1)ndndxn(fy(n))=i=0n(1)ididxi(fy(i)).

Version History

Introduced in R2015a