Calculating Derivatives with Mathematica

D

Mathematica contains the function D which will allow you to differentiate a given equation with respect to some variable. In fact, D will allow you to differentiate whole list of equations at once.

The use of D is very straightforward. The first argument to D is the equation or list of equations the are to be differentiated. The second argument is the variable these equations are to differentiated with respect to.

Examples:


In[1]:= D[3x^4, x]

            3
Out[1]= 12 x

In[2]:= D[Sin[x]+Cos[2x], x]

Out[2]= Cos[x] - 2 Sin[2 x]

In[3]:= D[Log[5x], x]

        1
Out[3]= -
        x

In[4]:= D[{a x^2 + b x + c, a x^n + b x^(n-1) + c}, x]      

                                -2 + n        -1 + n
Out[4]= {b + 2 a x, b (-1 + n) x       + a n x      }


In the examples above you should be able to see how D was passed the equations and a variable and returns the derivative. In the last example, In[4], two equations were passed to D. These equations were inclosed in brackets so that they would both be seen as part of the first argument. D returns the two derivatives of the equations.

The D function can also be used to differentiate an equation any number of times you desire, not just once. This is done by adding a number to the second argument which is how many times to differentiate.

Example:

In[1]:= D[3 x^5, {x, 2}]

            3
Out[1]= 60 x

In the example above, the second arument to D is enclosed in brackets and has two parts. The first part is the variable to differentiate to while the second part is the number of times to differentiate the given equation. More examples are shown below.

Examples:

In[2]:= D[5 Sin[x] + Cos[3x], {x, 2}]                

Out[2]= -9 Cos[3 x] - 5 Sin[x]

In[3]:= D[a x^n + b x^(n-1) + c, {x, 3}]

                                      -4 + n                          -3 + n
Out[3]= b (-3 + n) (-2 + n) (-1 + n) x       + a (-2 + n) (-1 + n) n x

In[4]:= D[a x^2 + b x + c, {x, 2}]

Out[4]= 2 a

Integrate

Mathematica also contains the function Integrate that will allow you to integrate an equation. Like the function D above, Integrate is called using two arguments. The first argument is the equation to be integrated while the second is the variable that the integration is to be in respect to.

Examples:

In[1]:= Integrate[2x^3*y, y]

         3  2
Out[1]= x  y

In[2]:= Integrate[1/(1-x^3), x]

               1 + 2 x
        ArcTan[-------]                             2
               Sqrt[3]    Log[1 - x]   Log[1 + x + x ]
Out[2]= --------------- - ---------- + ---------------
            Sqrt[3]           3               6

In[3]:= Integrate[1/x, x]

Out[3]= Log[x]

In[4]:= Integrate[n*x^(-1+n), x]

         n
Out[4]= x

References

[ST94] Applied Mathematica
William T. Shaw and Jason Tigg
Addison-Wesley, Menlo Park CA (1994).

[Rob95] Engineering Mathematics with Mathematica
John S. Robertson
McGraw-Hill, New York NY (1995).

[GG91] Exploring Mathematics with Mathematica
Theodore W. Gray and Jerry Glynn
Addison-Wesley, Menlo Park CA (1991).

Last Modified: 97.08.19 Michael Carreno <mcarreno@cs.princeton.edu>