2

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?

3 Answers3

5

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]]

kglr
  • 394,356
  • 18
  • 477
  • 896
5

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.

Henrik Schumacher
  • 106,770
  • 7
  • 179
  • 309
  • 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]
    
    – Kamran Ali Ahmed Jul 20 '18 at 13:18
2

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.

Jens
  • 97,245
  • 7
  • 213
  • 499
  • 1
    I appreciate you for taking out time to answer this question but I really cannot comprehend what is being said – Kamran Ali Ahmed Jul 20 '18 at 13:19
  • 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. – Jens Jul 20 '18 at 16:16
  • 1
    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. – Kamran Ali Ahmed Aug 06 '18 at 17:53