2
$\begingroup$

I have been working on a problem which requires the use of Energy Methods which is based on the variational principles. I am finding it hard to replicate my formulated equations in Mathematica.

How can I find the variation of any parameter using the variational operator in Mathematica? I have been trying the following function with 'u' being the dependent variable.

𝛿F(x,u) means the variation in the function with respect to the dependent variable. If F(x,u) can be given as:

F(x,u)= f(x)+x^2*u(x)-2u du/dx + 2x*Sin u 

How can I find the first and second variation of this function w.r.t the dependent variable?

$\endgroup$
2
  • 5
    $\begingroup$ You're also going to have trouble if you don't use proper syntax... $\endgroup$
    – b3m2a1
    Jul 19, 2018 at 8:27
  • $\begingroup$ Yes. I have been working on the syntax. Right now, more than syntax, I am more concerned with the use of this operator to deduce the required result. $\endgroup$ Jul 20, 2018 at 13:05

3 Answers 3

5
$\begingroup$

You can use the the function VariationalD in package VariationalMethods:

Needs["VariationalMethods`"]

VariationalD[u[x] + x^2 u[x] - 2 u[x] u'[x] + 2 x*Sin[u[x]], u[x], x]

1 + x^2 + 2 x Cos[u[x]]

$\endgroup$
4
  • 2
    $\begingroup$ I have been using this package but the results do not match the hand calculations. For example, if we assume this variational operator to work as a differential operator, the term "2 u[x] u'[x]" should be evaluated using the multiplicative rule of differentiation and should not equal zero. $\endgroup$ Jul 19, 2018 at 9:00
  • $\begingroup$ What should the “2 u[x] u’[x]” evaluate to? $\endgroup$
    – QuantumDot
    Jul 19, 2018 at 18:36
  • 1
    $\begingroup$ It should result in 2 u'[x] 𝛿u[x] + 2 u[x] 𝛿u'[x] $\endgroup$ Jul 20, 2018 at 13:06
  • $\begingroup$ @KamranAliAhmed I also need this kind of result form according to the textbook definition. Do you find the right way? $\endgroup$ Feb 17, 2020 at 6:13
5
$\begingroup$

Maybe you are looking for

D[u[x] + x^2 u[x] - 2 u[x] u'[x] + 2 x*Sin[u[x]], {{u[x], u'[x]}, 1}]

$\left\{-2 u'(x)+2 x \cos (u(x))+x^2+1,-2 u(x)\right\}$

or for

integrand[u_] := u[x] + x^2 u[x] - 2 u[x] u'[x] + 2 x*Sin[u[x]]
D[integrand[u + t v], t] /. t -> 0

$-2 v(x) \, u'(x) -2 u(x) \, v'(x)+2 \,x \, v(x) \cos (u(x))+x^2 \, v(x) + v(x)$

I prefer the latter. This variational-$\delta$ hokuspokus is basically what has been called a Gâteaux or Fréchet derivative since the mid of the last century.

PS.: The result of VariationalD[u[x] + x^2 u[x] - 2 u[x] u'[x] + 2 x*Sin[u[x]], {u[x]}, x] is actually correct if the boundary conditions of $u$ are fixed: This can be seen by integration by parts.

$\endgroup$
1
  • $\begingroup$ I am looking for an answer to the following form after applying 𝛿 with respect to the dependent variable which is 'u' in this case: 1+x^2*𝛿u[x] - 2 u'[x] 𝛿u[x] - 2 u[x] 𝛿u'[x] + 2x cos[u[x]] 𝛿u[x] $\endgroup$ Jul 20, 2018 at 13:18
2
$\begingroup$

Perhaps what you're really looking for is the functional derivative, which can be defined as follows, see this answer:

FunctionalD[functional_, f_[y_]] := 
 Assuming[Element[y, Reals], 
  Limit[((functional /. 
        f :> Function[x, f[x] + ε DiracDelta[x - y]]) - functional)/ε, ε -> 0]]

FunctionalD[u[x] + x^2 u[x] - 2 u[x] u'[x] + 2 x*Sin[u[x]], u[y]]

$$-2 \delta (x-y) u'(x)+2 x \delta (x-y) \cos (u(x))+x^2 \delta (x-y)+\delta (x-y)-2 u(x) \delta '(x-y)$$

You get the variational derivative by sticking this into an integral over $y$ which kills the delta functions. This result is different from the VariationalD result in that it is agnostic about whether the integral allows integration by parts. If the latter is allowed, then the (correct) result of Mathematica's VariationalD is recovered because the terms involving derivative of u and of the delta function cancel.

$\endgroup$
3
  • 1
    $\begingroup$ I appreciate you for taking out time to answer this question but I really cannot comprehend what is being said $\endgroup$ Jul 20, 2018 at 13:19
  • $\begingroup$ Well, your question is unclear to me (and to the other answerers, too). Maybe you're looking for something completely different, like a numerical solution in terms of some basis expansion. I cannot make any further guesses unless the question is made more specific. $\endgroup$
    – Jens
    Jul 20, 2018 at 16:16
  • 1
    $\begingroup$ I have my answer. I was trying to apply the delta operator which can be operated just like a differential operator to simplify things. Thank you for your input and time. Appreciated. $\endgroup$ Aug 6, 2018 at 17:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.