Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!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 19:16:21 -0800 Organization: A noiseless patient Spider Lines: 112 Message-ID: <87wq71jegq.fsf@san.rr.com> References: <87a93xkwix.fsf@san.rr.com> <8761elkwf3.fsf@san.rr.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="15591ad2607da309a0d1a78a1d632bc7"; logging-data="30460"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+b/0wZb/JjQ4hmC4SpxzgD" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:urG25nwge58owxJptiCVzntwf2M= sha1:EBiiGVm6TTHupWRUUf5Z1aArl0A= Xref: csiph.com comp.soft-sys.math.maple:1022 rouben@shadow.(none) (Rouben Rostamian) writes: > In article <8761elkwf3.fsf@san.rr.com>, Joe Riel wrote: >>Joe Riel writes: >> >>> rouben@shadow.(none) (Rouben Rostamian) writes: >>> >>>> In article , >>>> Nasser M. Abbasi wrote: >>>>>On 11/11/2014 5:39 PM, none Rouben Rostamian wrote: >>>>> >>>>>> 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 >>>>>> >>>>> >>>>>I do not use frontend() either. But if all else fails, you >>>>>can simply use calculus >>>>> >>>>>------------------------------ >>>>>restart; >>>>>f := frontend(int,[x(t)^2, x(t)]); >>>>>f := unapply(f,t); >>>>>limit(f(t),t=b)-limit(f(t),t=a); >>>>>------------------------- >>>>> >>>>> (1/3)*x(b)^3-(1/3)*x(a)^3 >>>> >>>> Hi Nasser, that's good but it's not exactly what >>>> I had asked. Your result integrates over t=a..b. >>>> I wanted x(t)=a..b, but that's easy to fix: >>>> f := frontend(int,[x(t)^2, x(t)]); >>>> eval(f, x(t)=b) - eval(f, x(t)=a); >>>> >>>> This technique, however, does not work in a more complex case. >>>> For instance, let's write x' and x'' for the first and second >>>> derivatives of x. We want to integrate x'' * x' * x^2 with >>>> respect to x. So we do: >>>> >>>> frontend(int, [diff(x(t),t,t)*diff(x(t),t)*x(t)^2, x(t)]); >>>> >>>> and we get the expected 1/3 * x'' * x' * x^3. >>>> >>>> Now, how do we do the corresponding definite integral >>>> where x(t)=a..b ? The expected answer is >>>> 1/3 * x''(t) * x'(t) * (b^3 - a^3). >>> >>> frontend(int, [diff(x(t),t,t)*diff(x(t),t)*x(t)^2, x(t)=a..b], >>[{`+`,`*`,`^`,`=`,`..`},{}]); >>> 1/3*diff(x(t),`$`(t,2))*diff(x(t),t)*(-a^3+b^3) >> >>In this case, we could also do >> frontend(int, [diff(x(t),t,t)*diff(x(t),t)*x(t)^2, x(t)=a..b], >>[{Not(function)},{}]); >> 1/3*diff(x(t),`$`(t,2))*diff(x(t),t)*(-a^3+b^3) > > Thank you, Joe, for your many very informative responses. > I have not quite grasped the workings of frontend() yet > since the next thing I tried, I got stuck again. > > Suppose we replace the x(t)^2 in the above with cos(x(t)), > and change the limits to x(t)=0..Pi/2, as in: > > frontend(int, [diff(x(t),t,t)*diff(x(t),t)*cos(x(t)), x(t)=0..Pi/2], > [{`+`,`*`,`^`,`=`,`..`},{}]); > > Neither of the suggested methods works. > I expect the answer to be x''(t) * x'(t), > but I get x''(t) * x'(t) * cos(x(t)) * Pi/2. > > I tried adding `cos` in frontend's first set > but Maple says "Error, type `cos` does not exist". > > Can you help, please? Using the print trick helps here. The O's it shows are frozen expressions, however, separate O's may or may not correspond to the same subexpression. In this case, the problem is that the cos(x(t)) is being frozen. You want it to appear as cos(O), where just the x(t) is frozen. So one solution is to add specfunc(cos) to the set of types not to freeze (you'll need to look up help on type,structured to better understand the specfunc type). So frontend(int, [diff(x(t),t,t)*diff(x(t),t)*cos(x(t)), x(t)=0..Pi/2], [{`+`,`*`,`^`,`=`,`..`,specfunc(cos)},{}]); diff(x(t),`$`(t,2))*diff(x(t),t)*sin(1/2*Pi) That can be further simplified with eval (the Pi got frozen, which is why it didn't simplify): eval(%); diff(x(t),`$`(t,2))*diff(x(t),t) Alternatively, one could use [{Not(specfunc({diff,x}))},{}] for the third argument. That causes the derivatives and x(t) to be temporarily frozen. -- Joe Riel