[Date Index]
[Thread Index]
[Author Index]
Re: How to use "Apply" to do differentiation ?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg114538] Re: How to use "Apply" to do differentiation ?
*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>
*Date*: Tue, 7 Dec 2010 06:45:43 -0500 (EST)
This is an "illusion" just as the fact that Apply[D[#, x] &, {x^1000}] works is based on an "illusion". In fact, any head that doe not evaluate will work:
Apply[D[#, x] &, F[x^1000]]
1000 x^999
Apply[D[#, x] &, HoldForm[x^1000]]
1000 x^999
Apply[D[#, x] &, InputForm[x^1000]]
1000 x^999
Apply[D[#, x] &, String[x^1000]]
000 x^999
and so on...
Andrzej Kozlowski
On 6 Dec 2010, at 03:51, Chenguang Zhang wrote:
> I tried different forms, the following three work:
> Apply[D[#, x] &, FullForm[x^1000]]
> Apply[D[#, x] &, HoldForm[x^1000]]
> Apply[D[#, x] &, Hold[x^1000]]
>
> Even the reason is clear, it is still a little unnatural to me
> because Apply[D[#, x] &, x^1000] is closer to mathematical language. Anyway,
> people generally use D[f[x], x] instead of the Apply command, and I tried
> that command because I wanted to use Nest command to do recursive
> differentiation to a function (Nest did work even Apply got me confused for
> a while)
>
> Cheers.
>
> On Sat, Dec 4, 2010 at 9:02 AM, Achilleas Lazarides <
> achilleas.lazarides at gmx.com> wrote:
>
>> Trace does show you what happened: Apply replaces the head of its second
>> argument by the first. In this case, it replaces Power in Power[x,5] by
>>
>> D[#, x] &
>>
>> (the second step in the trace). So if instead of D[#,x]& you had eg
>> Print[#1,#2]&, it would have printed
>> x5
>> because that is what Print[x,5] does.
>>
>> The point is that it does not give you a message to the effect that your
>> anonymous function has too many arguments in the second step in the trace;
>> it just silently drops the second argument. This is what anonymous functions
>> in Mathematica seem to do: silently drop extra arguments (I have no idea if
>> this is good, bad, neutral, accidental etc).
>>
>> So basically you are evaluating
>> (D[#1, x] & )[x, 5]
>> which drops the second argument and differentiates x.
>>
>> On Dec4, 2010, at 1:16 PM, Mayasky wrote:
>>
>>
>> Something simple yet unbelievable occurred when I use:
>>
>>
>> Apply[D[#, x] &, x^5]
>>
>>
>> The output is invariably 1 whether I use x^5 or x^100.
>>
>> Also I suggest you to try "Trace" command to see
>>
>> the weirdness -- the output is messy if pasted as
>>
>> text here.
>>
>>
>> Finally I have to take a detour and use:
>>
>> Nest[D[#, x] &, x^5, 1]
>>
>>
>> I have been using Mathematica for several years and
>>
>> never found that. I myself is wordless, but can anyone
>> explain that?
>>
>>
>>
Prev by Date:
**Foo /: Plus[b_Foo] := b**
Next by Date:
**Re: Counting number of numbers in a large list between two valus**
Previous by thread:
**Re: How to use "Apply" to do differentiation ?**
Next by thread:
**How to get the Inverse matrix in symbolic way?**
| |