Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.maple > #1015
| From | Joe Riel <joer@san.rr.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.maple |
| Subject | Re: Differentiating with respect to an expression |
| Date | 2014-11-11 17:45 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <87lhnhkx98.fsf@san.rr.com> (permalink) |
| References | <m3u1gm$7ir$1@news.albasani.net> <87sihpl61w.fsf@san.rr.com> <m3u6n6$kkr$1@news.albasani.net> |
rouben@shadow.(none) (Rouben Rostamian) writes:
> In article <87sihpl61w.fsf@san.rr.com>, Joe Riel <joer@san.rr.com> wrote:
>>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
>>
>
> Thanks much, Joe, this is exactly what I was hoping for.
> I had no idea about frontend() or the Physics package.
>
> This brings up a somewhat related question. Doing
> frontend(int, [x(t)^2, x(t)]);
> we get x(t)^3/3, which is fine. The following, however,
> issues an Error message:
> frontend(int, [x(t)^2, x(t)=a..b]);
>
> Is there a way to get that to work too?
>
> Rouben
The optional third argument of frontend can be used for that.
See the help page. It consists of a list of two sets.
The first set is significant here, it contains the types
that frontend does *not* freeze. By default the `+`, `*`, and `^`
types are not frozen. In this case, you also do *not* want
to freeze `=` and `..`. So the following works:
frontend(int, [x(t)^2, x(t)=a..b], [{`+`,`^`,`*`,`..`,`=`},{}]);
1/3*b^3-1/3*a^3
Frequently one can use the Not type to specify what you do
want frozen. For example,
frontend(int, [x(t)^2, x(t)=a..b], [{Not(identical(x(t)))},{}]);
1/3*b^3-1/3*a^3
--
Joe Riel
Back to comp.soft-sys.math.maple | Previous | Next — Previous in thread | Next in thread | Find similar
Differentiating with respect to an expression rouben@shadow.(none) (Rouben Rostamian) - 2014-11-11 22:10 +0000
Re: Differentiating with respect to an expression Joe Riel <joer@san.rr.com> - 2014-11-11 14:35 -0800
Re: Differentiating with respect to an expression rouben@shadow.(none) (Rouben Rostamian) - 2014-11-11 23:39 +0000
Re: Differentiating with respect to an expression "Nasser M. Abbasi" <nma@12000.org> - 2014-11-11 18:50 -0600
Re: Differentiating with respect to an expression "Nasser M. Abbasi" <nma@12000.org> - 2014-11-11 19:44 -0600
Re: Differentiating with respect to an expression rouben@shadow.(none) (Rouben Rostamian) - 2014-11-12 01:55 +0000
Re: Differentiating with respect to an expression Joe Riel <joer@san.rr.com> - 2014-11-11 18:00 -0800
Re: Differentiating with respect to an expression Joe Riel <joer@san.rr.com> - 2014-11-11 18:03 -0800
Re: Differentiating with respect to an expression rouben@shadow.(none) (Rouben Rostamian) - 2014-11-12 02:44 +0000
Re: Differentiating with respect to an expression Joe Riel <joer@san.rr.com> - 2014-11-11 19:16 -0800
Re: Differentiating with respect to an expression rouben@shadow.(none) (Rouben Rostamian) - 2014-11-12 04:53 +0000
Re: Differentiating with respect to an expression Joe Riel <joer@san.rr.com> - 2014-11-11 17:45 -0800
Re: Differentiating with respect to an expression Joe Riel <joer@san.rr.com> - 2014-11-11 17:52 -0800
Re: Differentiating with respect to an expression rouben@shadow.(none) (Rouben Rostamian) - 2014-11-12 02:03 +0000
csiph-web