TransWikia.com

How to take derivative of a expression with respect to a function?

Mathematica Asked by Gabriel Sandoval on August 5, 2021

I want to program the Euler-Lagrange equations for continuous systems.
But in this formulation I have to compute the derivative of the Lagrangian with respect to all the derivatives of the generalized coordinate.
$$partial_ileft(dfrac{partial mathcal{L}}{partial (partial_iphi) } right) = dfrac{partial mathcal L}{partial phi }$$
For example, for a field $phi=phi(x,t)$
$$dfrac{partial }{partial t}dfrac{partial mathcal L}{partial dotphi}+dfrac{partial }{partial x}dfrac{partial mathcal L}{partial phi’}=dfrac{partialmathcal L}{partial phi}$$
Where $dotphi=dfrac{partialphi}{partial t }$ and $phi’=dfrac{partial phi}{partial x }$

I have tried with something like this

D[L, D[ϕ, t]] + D[L, D[ϕ, x]] = D[L,ϕ]

But of course, it returns an error because of the variable with respect the derivative is taken.

One Answer

It is straightforward. Let us take a Lagrangian

L = 1/2 D[y[x, t], t]^2 - 1/(2 c^2) D[y[x, t], x]^2 + 1/2 y[x, t]^2;

We need to load the package:

Needs["VariationalMethods`"]

Now, this gives the variational derivative:

VariationalD[L, y[x, t], {x, t}]

enter image description here

and this yields the Euler equation:

EulerEquations[L, y[x, t], {x, t}]

enter image description here

Have fun!

Correct answer by Alexei Boulbitch on August 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP