[Date Index]
[Thread Index]
[Author Index]
Re: Re: Question about derivatives
*To*: mathgroup at smc.vnet.net
*Subject*: [mg51466] Re: [mg51397] Re: [mg51384] Question about derivatives
*From*: "Ben Whale" <ben.whale at anu.edu.au>
*Date*: Sun, 17 Oct 2004 21:50:08 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
Thanks very much for the prompt reply.
Before I asked this question, I searched, the archives, the FAQ and the
Mathematica Help extensively. If the question has been asked so many times,
I suggest that the answer be easier to find. I would also be interested in
why this behaviour is not built into Mathematica (or why there is no package
with new functions that does the same thing), where can I find the answers
to these questions?
Ben
-----Original Message-----
From: Andrzej Kozlowski [mailto:akoz at mimuw.edu.pl]
To: mathgroup at smc.vnet.net
Subject: [mg51466] [mg51397] Re: [mg51384] Question about derivatives
On 15 Oct 2004, at 15:48, Ben Whale wrote:
> Hi,
> I want to treat a function abstractly, I know that it is a function
> of n
> variables. I wish to take its derivative after addition or
> multiplication
> with another function. However Derivative does not return what I
> expect.
> Derivative[0,1][f+g] gives (f+g)^(0,1) instead of f^(0,1)+g^(0,1) and
> Derivative[0,1][fg] gives (fg)^(0,1) instead of f^(0,1)g+g^(0,1)f.
> Now
> perhaps I'm going about my problem in the wrong way, if I am please
> tell me.
>
> I also have some other questions about Derivative,
> Derivative[0,1][Composition[f,g]] gives f^(0,1)(g)g^(0,1), the correct
> result, why does Derivative know the chain rule and not the product
> rule?
>
> Also, in order to get the correct behaviour for Derivative[0,1][f+g],
> I can
> use the Map function, that is Map[Derivative[0,1],f+g] returns f^(0,1)
> +g^(0,1). Which is fine except that if I have the function 1+f and
> apply
> the same command to it I get 0& + f^(0,1), instead of f^(0,1).
> Clearly
> this is because of the presence of the command Function[0], however I
> have
> been unable to find a function that fixes this problem.
>
> In essence I want to do vector operations of the ring of functions,
> but find
> that doing this in Mathematica is hard. How can I do this easily?
> Surely
> someone else has figured out a convenient way of do this.
>
> Thanks,
> Ben
>
>
>
This question has been asked and answered many times (including quite
recently). The answer I am posting I have also already posted several
times.
For reasons which I do not want to argue about again Mathematica does
not implement the algebra of functions. that is, if f and g are
functions, whether defined using patterns as in f[x_]:= or as pure
functions using Function, f+g, f*g etc. are not is not treated by
Mathematica as functions. If you wan to change this you can always do
so:
Unprotect[Times, Plus, Power];
(a_?NumericQ*f_.)[x__] := a f[x];
(f_ + g_)[x__] := f[x] + g[x];
(f_*g_)[x__] := f[x]*g[x];
(f_^n_?NumericQ)[x__] := f[x]^n
Protect[Times, Plus, Power];
Now you will get:
Derivative[0, 1][f + g]
Derivative[0, 1][f][#1, #2] +
Derivative[0, 1][g][#1, #2] &
Derivative[0, 1][f*g]
g[#1, #2]*Derivative[0, 1][f][#1,
#2] + f[#1, #2]*
Derivative[0, 1][g][#1, #2] &
You have to be aware however that in general it is not a good idea to
modify basic functions such as Times, Plus, Power. They are used by
practically every other Mathematica function and you can never tell if
having additional rules or modifications like those above will not
produce unexpected and unintended behaviour.
Andrzej Kozlowski
Chiba, Japan
http://www.akikoz.net/~andrzej/
http://www.mimuw.edu.pl/~akoz/
Prev by Date:
**Re: table format question**
Next by Date:
**Re: Save graphics**
Previous by thread:
**Re: Question about derivatives**
Next by thread:
**Re: Re: Re: Question about derivatives**
| |