Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Functional derivative

`D = functionalDerivative(f,y)`

returns
the Functional Derivative of the
functional $$F={\displaystyle \int f\left(x,y\left(x\right),y\text{'}\left(x\right)\mathrm{...}\right)dx}$$ with respect to the function `D`

= functionalDerivative(`f`

,`y`

)*y* = *y*(*x*),
where *x* represents 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.

Find the functional derivative of the function
given by $$f\left(y\right)=y\left(x\right)\mathrm{sin}\left(y\left(x\right)\right)$$ with respect to the function `y`

.

syms y(x) f = y*sin(y); D = functionalDerivative(f,y)

D(x) = sin(y(x)) + cos(y(x))*y(x)

Find the functional derivative of the function
given by $$H\left(u,v\right)={u}^{2}\frac{dv}{dx}+v\frac{{d}^{2}u}{d{x}^{2}}$$ with respect to the functions `u`

and `v`

.

syms u(x) v(x) H = u^2*diff(v,x)+v*diff(u,x,x); D = functionalDerivative(H,[u v])

D(x) = 2*u(x)*diff(v(x), x) + diff(v(x), x, x) diff(u(x), x, x) - 2*u(x)*diff(u(x), x)

`functionalDerivative`

returns a vector of
symbolic functions containing the functional derivatives of `H`

with
respect to `u`

and `v`

, respectively.

First find the Lagrangian for a spring with
mass `m`

and spring constant `k`

,
and then derive the Euler-Lagrange equation. The Lagrangian is the
difference of kinetic energy `T`

and potential energy `V`

which
are functions of the displacement `x(t)`

.

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

L(t) = (m*diff(x(t), t)^2)/2 - (k*x(t)^2)/2

Find the Euler-Lagrange equation by finding the functional derivative
of `L`

with respect to `x`

, and
equate it to `0`

.

eqn = functionalDerivative(L,x) == 0

eqn(t) = - m*diff(x(t), t, t) - k*x(t) == 0

`diff(x(t), t, t)`

is the acceleration. The
equation `eqn`

represents the expected differential
equation that describes spring motion.

Solve `eqn`

using `dsolve`

.
Obtain the expected form of the solution by assuming mass `m`

and
spring constant `k`

are positive.

assume(m,'positive') assume(k,'positive') xSol = dsolve(eqn,x(0) == 0)

xSol = -C3*sin((k^(1/2)*t)/m^(1/2))

Clear assumptions for further calculations.

assume([k m],'clear')

The Brachistochrone problem is to find the
quickest path of descent under gravity. The time for a body to move
along a curve `y(x)`

under gravity is given by

$$f=\sqrt{\frac{1+y{\text{'}}^{2}}{2gy}},$$

where *g* is the acceleration due to gravity.

Find the quickest path by minimizing `f`

with
respect to the path `y`

. The condition for a minimum
is

$$\frac{\delta f}{\delta y}=0.$$

Compute this condition to obtain the differential equation that
describes the Brachistochrone problem. Use `simplify`

to
simplify the solution 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) = diff(y(x), x)^2 + 2*y(x)*diff(y(x), x, x) == -1

This equation is the standard differential equation for the Brachistochrone problem.

If the function *u*(*x*,*y*) describes
a surface in 3-D space, then the surface area is found by the functional

$$F\left(u\right)={\displaystyle \iint f\left(x,y,u,{u}_{x},{u}_{y}\right)dxdy}={\displaystyle \iint \sqrt{1+{u}_{x}^{2}+{u}_{y}^{2}}dxdy},$$

where *u*_{x} and *u*_{y} are
the partial derivatives of *u* with respect to *x* and *y*.

Find the equation that describes the minimal surface for a 3-D
surface described by the function `u(x,y)`

by finding
the functional derivative of `f`

with respect to `u`

.

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

D(x, y) = -(diff(u(x, y), y)^2*diff(u(x, y), x, x)... + diff(u(x, y), x)^2*diff(u(x, y), y, y)... - 2*diff(u(x, y), x)*diff(u(x, y), y)*diff(u(x, y), x, y)... + diff(u(x, y), x, x)... + diff(u(x, y), y, y))/(diff(u(x, y), x)^2... + diff(u(x, y), y)^2 + 1)^(3/2)

The solutions to this equation `D`

describe
minimal surfaces in 3-D space such as soap bubbles.