ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 07 Feb 2011 11:26:47 +0100Computing Variational Derivativeshttps://ask.sagemath.org/question/7929/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
<p align="center">
$I = \int L(x,u,u_x u_{xx}, \ldots)dx$
</p>
the *variational derivative* of $I$ is defined as
<p align="center">
$\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$
</p>
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!cswierczMon, 07 Feb 2011 11:26:47 +0100https://ask.sagemath.org/question/7929/