How to make this replacement in Mathematica?

I am just getting started with Mathematica, and I have what should be a fairly simple question about substitutions, but I cannot get it to work.

I would like to find the Euler-Lagrange equations for the functional of the function phi [x, y], and then make a replacement for the function phi [x, y]

If I enter the following:

VariationalD[tau*phi[x, y]^2 - 2*phi[x, y]^4 + phi[x, y]^6 + Dot[D[phi[x, y], {{x, y}}], D[phi[x, y, {{x, y}}]]], phi[x, y], {x, y}]

I get

Plus[Times[2,tau,phi[x,y]],Times[-8,Power[phi[x,y],3]],Times[6,Power[phi[x,y],5]],Times[-2,Plus[Derivative[0,2][phi][x,y],Derivative[2,0][phi][x,y]]]]

Now, if I try % /. phi[x,y] -> phi0[x,y] + psi[x,y], it makes a replacement for all polynomial members, but not for derived members.

How to force a substitution in these functions?

+3
source share
2 answers

I agree with everything rcollyer says , but I think his final decision may be a bit opaque.

, ( , rcollyer), -

{phi[x__] :> phi0[x] + psi[x], f_[phi][x__] :> f[phi0][x] + f[psi][x]}

-

{phi[x__] :> phi0[x] + psi[x], Derivative[n__][phi][x__] :> Derivative[n][phi0][x] + Derivative[n][psi][x]}

, Derivative Default ( Default[Times] Default[Derivative]). - Default[Derivative] := Sequence[], , , .

, , , -

VariationalD[expr_, sym_, var_] := Module[{
  vRule = {sym[x__] :> sym[x] + var[x], 
    Derivative[n__][sym][x__] :> Derivative[n][sym][x] + Derivative[n][var][x]}}, 
  (expr /. vRule) - expr]

var sym . , , , , var=0 . , var. .

+5

-, ] , D[phi[x, y], {{x, y}}]] not D[phi[x, y, {{x, y}}]]].

, Mathematica , questions. , , . , phi[x,y] Derivative[2, 0][phi][x, y]. , . -

Derivative[a__][phi][x__]:> Derivative[a][phi0][x] + Derivative[a][psi][x]

. : 1) ReplaceDelayed, , , 2) , , RHS , 3) double underscore a x, .

, , , . , , .

. , .

<result> /. phi -> phi0 + psi /. a_[b__][c__] :> Through[Distribute[a[b]][c]]

Distribute , Plus Through args c. , Head of Derivative[2, 0][phi][x, y] Derivative[2, 0][phi], .

+2

Source: https://habr.com/ru/post/1780287/


All Articles