Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #11493
| From | David Bailey <dave@removedbailey.co.uk> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Getting the Derivative of an HoldForm Expression |
| Date | 2012-08-25 08:27 +0000 |
| Message-ID | <k1a28l$icg$1@smc.vnet.net> (permalink) |
| References | <k16jfv$bep$1@smc.vnet.net> |
| Organization | Time-Warner Telecom |
On 24/08/2012 01:56, nitgun@gmail.com wrote:
> Hi,
> am currently fiddling with some equations. To make it more easy I want to introduce subexpressions which should not be evaluated. For this purpose I found HoldForm. But this creates some weird results when I want to get the derivative of such a term. But let's have a look at an example:
> In1:=T=HoldForm[2*a[t]]
> Out1=2 a[t]
>
> In2:= a[t]=b[t]+c[t]
> Out2=b[t]+c[t]
>
> In3:=T
> Out3=2 a[t]<-- this is what I need HoldForm for, as I do not want 2(b[t]+c[t]) as result
>
> In4:=D[T,t]
> Out4=2 a'[t] HoldForm'[2(b[t]+c[t])]
>
> I would expect 2 a'[t] as result so the term HoldForm'[...] seems to be a bit weird to me. Can anyone explain to me how I can avoid this term?
> Thanks in advance.
>
The simplest answer, is not to use HoldForm for this purpose, and not to
make assignments such as
a[t]=b[t]+c[t]
unless you really want them to be used everywhere! Now you can take your
derivative of T quite easily. Then, if you want to replace a[t] in the
resultant expression, use
expr /. a[t_]->b[t]+c[t]
Note I have used a pattern here, so that an expression like a[2 k] would
also get replaced.
I often find it is convenient to collect replacement rules in a list,
and then just apply the whole set at various points in a calculation.
For example:
constants={c->299792.0,em->9.1*10^-31, etc etc}
expr=expr/.constants
David Bailey
http://www.dbaileyconsultancy.co.uk
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Getting the Derivative of an HoldForm Expression nitgun@gmail.com - 2012-08-24 00:56 +0000
Re: Getting the Derivative of an HoldForm Expression David Bailey <dave@removedbailey.co.uk> - 2012-08-25 08:27 +0000
Re: Getting the Derivative of an HoldForm Expression nitgun@gmail.com - 2012-08-28 08:49 +0000
Re: Getting the Derivative of an HoldForm Expression David Bailey <dave@removedbailey.co.uk> - 2012-08-30 08:09 +0000
Re: Getting the Derivative of an HoldForm Expression nitgun@gmail.com - 2012-08-31 08:01 +0000
Re: Getting the Derivative of an HoldForm Expression David Bailey <dave@removedbailey.co.uk> - 2012-09-02 08:45 +0000
csiph-web