Ask Your Question

Revision history [back]

Computing Variational Derivatives

Allow me to start with a definition. Given a function $u = u(x)$, a function $L$ of $x, u$, and all derivatives of $u$; and

$I = \int L(x,u,u_x u_{xx}, \ldots)dx$

the variational derivative of $I$ is defined as

$\frac{\delta I}{\delta u} := \frac{\partial L}{\partial u} - \frac{d}{dx} \frac{\partial L}{\partial u_x} + \frac{d^2}{dx^2} \frac{\partial L}{\partial u_{xx}} - \cdots$

For example, with $L=u^3 + u_x^2/2$ we have $\frac{\delta I}{\delta u} = 3u^2 - u_{xx}$.

From my poking around I suspect that Sage doesn't have the option of computing the variational derivative of an integral operator. However, I'd like to write some code that does this. Does anyone have any suggestions on how to go about doing this?

One issue is that if you define a function

sage: u = function('u', x)

you can take derivatives of u with respect to x, of course, but not with respect to u.

sage: u.derivative(u)   # this should be equal to 1
Traceback (click to the left of this block for traceback)
...
TypeError: argument symb must be a symbol
sage: u_x = u.derivative(x)
sage: L = u_x^2/2
sage: L.derivative(u_x)    # this should be equal to u_x
Traceback (click to the left of this block for traceback)
...
TypeError: argument symb must be a symbol

My thoughts include doing some string parsing so I can take the necessary derivatives with respect to $u,u_x,u_{xx},\ldots$ but that's starting to sound a bit messy. Any suggestions on how to cleanly go about doing this in Sage would be greatly appreciated!