This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / The Mathematica Book / Advanced Mathematics / Calculus  /

3.5.5 Defining Derivatives

You can define the derivative in Mathematica of a function f of one argument simply by an assignment like f'[x_]=fp[x].

  • This defines the derivative of to be . In this case, you could have used = instead of :=

  • In[1]:= f'[x_] := fp[x]

  • The rule for f'[x_] is used to evaluate this derivative.
  • In[2]:= D[f[x^2], x]


  • Differentiating again gives derivatives of

  • In[3]:= D[%, x]


  • This defines a value for the derivative of

    at the origin.
  • In[4]:= g'[0] = g0


  • The value for g'[0] is used.
  • In[5]:= D[g[x]^2, x] /. x->0


  • This defines the second derivative of g, with any argument.
  • In[6]:= g''[x_] = gpp[x]


  • The value defined for the second derivative is used.
  • In[7]:= D[g[x]^2, {x, 2}]


    To define derivatives of functions with several arguments, you have to use the general representation of derivatives in Mathematica.

    Defining derivatives.

  • This defines the second derivative of g with respect to its second argument.
  • In[8]:= Derivative[0, 2][g][x_, y_] := g2p[x, y]

  • This uses the definition just given.
  • In[9]:= D[g[a^2, x^2], x, x]