Skip to main content
Tweeted twitter.com/StackMma/status/1225479455877074949
Became Hot Network Question

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[\(\[PartialD]\∂\), \(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[\(\[PartialD]\∂\), \(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.

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[\(\[PartialD]\), \(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[\(\[PartialD]\), \(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.

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.

Source Link
Ihor
  • 378
  • 1
  • 8

How to Force Evaluation of Derivative in a Pure Function Definition

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[\(\[PartialD]\), \(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[\(\[PartialD]\), \(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.