Message Boards Message Boards

0
|
3749 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How assign a function which is a derivative of another function

Posted 9 years ago

I am trying to assign a function which is a derivative of a previous on:

f[x_] := x^2;
D[f[x], x]

I would like j to be the derivative of f, so it would be also a function of x (namely, 2x)

How do I do that?

Trying to use do it with the following line gives an error

j[x_] := D[f[x], x]
j[1]
Attachments:
POSTED BY: Omer Tzuk
3 Replies
Posted 9 years ago

Hi Omer,

f[x_] := x^2;
j[x_] := D[f[x], x]

In the above, the definition of j uses SetDelayed ( := ). This means it will not evaluate the right side until the definition is used.

In[3]:= j[1]

During evaluation of In[3]:= General::ivar: 1 is not a valid variable. >>

So when we evaluate j[1], x is replaced by 1 in D[f[x],x] before the derivative is attempted, which does not work.

Below, Set rather than SetDelayed is used in the definition.

In[4]:= jj[x_] = D[f[x], x]

Out[4]= 2 x

In[5]:= jj[1]

Out[5]= 2

By using Set ( = ) rather than SetDelayed, the symbolic derivative is evaluated immediately and used as the definition.

POSTED BY: David Keith
Posted 9 years ago

Excellent! Thanks for the explanation

POSTED BY: Omer Tzuk

works on my computer. maybe you previously used f or j.

POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract