Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Joe Riel Newsgroups: comp.soft-sys.math.maple Subject: Re: Differentiating with respect to an expression Date: Tue, 11 Nov 2014 14:35:07 -0800 Organization: A noiseless patient Spider Lines: 48 Message-ID: <87sihpl61w.fsf@san.rr.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="15591ad2607da309a0d1a78a1d632bc7"; logging-data="19311"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/nAZoGmGWfjc/pN6WfDoOR" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:b4sIpLQw8wQNh8ASaRahxsETuQ4= sha1:rBo+NsvUrYi2L9wtVz2eqZnlHMs= Xref: csiph.com comp.soft-sys.math.maple:1011 rouben@shadow.(none) (Rouben Rostamian) writes: > The following issue comes up quite often in the context of > analytical mechanics. I have a clunky solution for it. > I wonder if there is a clever way. > > Let's say we have L = x^2 + x'^2 * x''^2, where x is a function of t, > and in the usual mathematical notation, x' and x'' are the first and > second derivatives of x. > > We want to compute the derivative of L with respect to x'. The > answer should be 2*x'*x''^2. Here is the way I do it in Maple: > > restart; > L := x(t)^2 + diff(x(t),t)^2 * diff(x(t),t,t)^2; > subs(diff(x(t),t,t)=Z2, diff(x(t),t)=Z1, %); > diff(%, Z1); > subs(Z1=diff(x(t),t), Z2=diff(x(t),t,t), %); > > The L shown above is simple enough so that we don't need a > CAS to compute the derivative. The L in a real example will > be the result of a long chain of calculations, will depend on > several functions and their derivatives, and will take up a > couple of screenfuls. > > If there is a clever way to compute that derivative, I would > like to know. A low-level way to do this is with frontend: frontend(diff, [L,diff(x(t),t)]); 2*diff(x(t),t)*diff(diff(x(t),t),t)^2 An alternative method is to use the Physics package: with(Physics): diff(L, diff(x(t),t)); 2*diff(x(t),t)*diff(diff(x(t),t),t)^2 # alternatively, with Physics diff(L, D(x)(t)); 2*D(x)(t)*`@@`(D,2)(x)(t)^2 -- Joe Riel