Let's say I have a function
f1 = #^2 &;
I want to calculate its derivative, perform some manipulations and make the result a pure function. I try
D[f1[x], x] (*Function[{x}, \!\(
\*SubscriptBox[\(∂\), \(x\)]\(f1[x]\)\)]*)
So the derivative didn't evaluate. I try forcing it
Function[{x}, Evaluate@D[f1[x], x]] (*Function[{x}, 2 x]*)
And it works. But let's say I want to additionally manipulate the derivative inside the function so I try
Function[{x}, N@Evaluate@D[f1[x], x]] (*Function[{x}, N[Evaluate[\!\(
\*SubscriptBox[\(∂\), \(x\)]\(f1[x]\)\)]]]*)
And this doesn't work anymore. Any suggestions on how to fix this problem? I also obviously lack understanding of the evaluation logic of such cases, so I will be grateful for explanations or references.
D[f1[x], x]does give2x(version 11.3.0 - Windows 10) (maybe you need to useClearAll[f1]before line that definesf1) and 2. UsingEvaluate @ N @ D[f1[x],x]instead ofN @ Evaluate @ D[f1[x],x]works (This has to do with theHoldAllattribute ofFunction; it does not evaluate its arguments unless it seesEvaluateas the head of the argument) – kglr Feb 06 '20 at 10:59