Symbolic Differentiation with Mathematica

by
K. D.  Stroyan
University of Iowa

copyright 1997 by Academic Press, Inc. - All rights reserved.

Notebook Overview

The purpose of this notebook is to show you how to use Mathematica's built in symbolic differentiation.  The built in function is called "D[]" and it knows the rules of calculus.

Mathematica can also find the derivative of a defined function

f[x]

with the command  f'[x].

References to the Text

This NoteBook goes with all of the text after Chapter 6.  It could be especially helpful in checking your work on problems with different variables and parameters, such as the problems in Chapter 7.  Also see the NoteBook HomeWkCk in Chapter 6.

Step-by-step Computations

The product rule:

To differentiate y = Sin[x] Cos[(Sqrt[x])], <Enter> the computation in the next cell:
(You may want to check it by hand.)

\(Clear[x, y]; 
y = Sin[x]\ Cos[\@x]\)\(	D[\ y, \ x\ ]\)

You may want to use a defined function and also define the derivative as a defined function.  Enter this in the form:

\(Clear[f, g, x, u, v]; 
f[x_] := Sin[x]\ Cos[\@x]; 
y = f[x]\)\(g[x_] := Evaluate[D[\ y, \ x\ ]]; 
g[x]\)f[v]g[u]f[3.1]g[3.1]

or simply differentiate a function like this:

\(Clear[f, x]; 
f[x_]\  := \ Log[Cos[\@x]]; 
f[x]\)f'[x]

Differentiation with respect to different variables:

Actually, D[] does partial differentiation, which will be described later in the course.  All this means is that if D[] is given an expression which contains variables other than the variable of differentiation, then it will treat the other variables as  parameters.

Example 1

(x^2) + r Sin[x] + z  is a function of  x  with parameters  r  and  z.  Differentiate with respect to  x  by <Enter>ing the computation.

\(Clear[x, r, z]; 
D[x\^2 + r\ Sin[x] + z, x]\)

Differentiate the same formula with respect to a different independent variable,  z:

D[ (x^2) + r Sin[x] + z,  z ]

If the variable  z  is a dependent variable or unknown function of  x  we can enter the differentiation as:

D[((x^2) + r Sin[x] + z[x]), x]

or if we assign  z  a value in terms of x:

\(z\  = \ E\^\(3  x + 4\); 

    D[\((x\^2 + r\ Sin[x] + z)\), x]\)

Example 2

Notice that in the previous example D[] still regards r as a constant.  This is very useful for differentiating expressions with parameters such as:  a (x^2) + b x + c.  Enter the computations in the next cell.

\(y := a\ x\^2 + b\ x + c; 
D[\ y\ , \ x\ ]\)D[ y ,  a ]D[ y ,  b ]D[ y ,  c ]

The nth derivative:

In some applications it is necessary to differentiate an expression several times.  D[] also lets you do several differentiations at once.  If you want to differentiate the expression

y = Tan[x] Sin[2x]

4 times (that is, take the fourth derivative), you don't need to use D 4 times, D[D[D[D[ Tan[x] Sin[2x]]]]].  You can use D as follows:

y = Tan[x] Sin[2 x] 
D[ y, {x, 4} ]

What do you get if you differentiate a polynomial of degree  4   four times?  For example, differentiate y = a (x^4) + b (x^3) + c (x^2) + d x + e  four times with respect to  x   using Mathematica:

\(y\  = \ \(?? ?
\(D[\ ?? ??\ ,\ ????]\)\)\)

See the Mathematica book (which you can access "on line" from Info/Help) for more information on the D[.] function.

?? D

Exercises

Exercise 7.1.2

Planck's radiation law  in frequency form can be written:

\(Clear[i, a, b, T, ω]; 

    i = \(a\ ω\^3\)\/\(E\^\(b\ ω/T\) - 1\)\)

for constants a and b.  (Note: Mathematica reserves I and i for I = (Sqrt[-1]).)  This expresses the intensity i of radiation at frequency ω  for a body at absolute temperature T.  Suppose T is also fixed.  Express  i as a chain or composition of functions ( of ω with parameters) and products of functions to which the rules of Chapter 6 apply.  What is the formula for   (di/d)ω?

Planck's Formula in Wavelength Form and its Derivative:

The next example is Planck's radiation formula in wavelength form and Mathematica's derivative of it.  This formula arises in the project that shows how Planck's formula implies Wein's law of radiation.

\(Clear[i, a, b, T, λ]; 

    i[λ_] := 
      a\/\(λ\^5\ \((Exp[b\/\(λ\ T\)] - 1)\)\)\)i[λ]

i'[λ]

Together[i'[λ]]