Subject: Euler-Lagrange equations and partial derivatives
From: Leo Butler
Date: Thu, 22 Apr 2010 21:35:31 +0100 (BST)
On Thu, 22 Apr 2010, dlakelan wrote:
< On 04/22/2010 12:22 PM, dlakelan wrote:
<
< > In Euler-Lagrange equations we need to mix these things.
< >
< > diff(partdiff(foo, bardot),t) - partdiff(foo,bar) = 0
< >
< > where only the "diff" should take total derivatives, and the
< > non-existent partdiff should do partials only. Unfortunately it is not
< > easily possible (or at least not obvious how) to mix partials and total
< > derivatives in maxima. Does anyone have any suggestions about how to go
< > about it?
<
< Here is my attempt to solve this problem. I first save the dependencies, then
< remove all dependencies, calculate the partials (via diff) and then replace
< the dependencies and calculate the total derivative with respect to the time
< variable. Is there anything that can go wrong in removing and replacing the
< dependencies? Is this function referentially transparent? (ie. has no
< externally apparent side effects?)
<
< EuLagEquations(expr,var,vardot,t) :=
< block([deps:copylist(dependencies), term1, term2],
< print(deps),
< remove(all,dependency),
< term1: diff(expr,vardot), term2: -diff(expr,var),
< for i in deps do (print(i),depends(op(i),args(i))),
< diff(term1,t)+term2=0);
Here is a pretty transparent function which works for multiple
variables. I add a dependency in the function itself, but
otherwise I don't mess with things.
el(L,x,v,[t]):=block([Lv,Lx],
t:if t=[] then 't elseif symbolp(part(t,1)) then
part(t,1) else merror("el(L,x,v,[t]): t must be an unbound symbol."),
x:if listp(x) then x elseif symbolp(x) then [x] else
merror("el(L,x,v,[t]): x, v must be scalars or lists."),
v:if listp(v) then v elseif symbolp(v) then [v] else
merror("el(L,x,v,[t]): x, v must be scalars or lists."),
Lx:map(lambda([tau],diff(L,tau,1)),x),
Lv:map(lambda([tau],diff(L,tau,1)),v),
depends(v,t),
flatten([map("=",diff(Lv,t),Lx),map(lambda([xi,eta],eta=diff(xi,t)),x,v)]));
depends(L,[a,b,u,v],[a,b,u,v],t,V,w,[w,z],s);
el(L,[a,b],[u,v]);
W : z^2/2 - V;
EL_W : el(W,w,z,s);
E : W + 2*V;
diff(E,s);
subst(EL_W,%); <--conservation of energy
Leo
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.