Derivatives

Basics

There are several different ways to take a derivative in Mathematica. If we begin with a third order polynomial,

f[x_]:= (x^3) -2(x^2) -5x+1

then the derivative can be found easily enough by hand.

Df[x_] := 3(x^2) -4 x -5

The quick way of arriving at this is to use the same f'(x) notation discussed in class. This has the upside of being simple and memorable, but lacks some of the finer tools we may want later in the class.

f'[x]

Df[x]==f'[x]

An alternative method is to use the D[] function.

D[f[x],x]

This will work even when the function hasn’t been previously defined, and can handle functions of more than one variable.

D[(x^2)(y^3),x] (*In this case y is treated as a constant.*)

D[(x^2)(y^3),y] (*In this case x is treated as a constant.*)

This can be useful both to check your own work on complicated problems, as well as taking the derivative for functions we haven’t covered in class.

D[BesselJ[0,x],x] (* This is the derivative of the Bessel function from the previous notebook.*)

Plot[{BesselJ[0,x],-BesselJ[1,x]},{x,0,6}] (*This is an alternative method for putting to curves on the same plot.*)

Here’s an interactive illustration of the function f(x) (and its tangent line) verses the derivative.

fplot = Plot[f[x],{x,-3,4},PlotStyle->{Bold, Red},PlotRange->{-15,17}];

Dfplot = Plot[Df[x], {x,-2.7,4}, PlotStyle->{Bold, Blue},PlotRange->{-15,17}];

Manipulate[Show[fplot,Dfplot,
ListPlot[{{x,f[x]}}, PlotStyle->{PointSize[0.03],Purple}],
Plot[f'[x](y-x)+f[x],{y,x-0.75,x+0.75},PlotStyle->{Dotted, Purple}],
ListPlot[{{x,Df[x]}}, PlotStyle->{PointSize[0.03],Blue}]],{x,-2.14,3.42}]

Higher Derivatives

Higher derivatives can be found by repeatedly applying the derivative operator. For instance the derivative of

Df[x_] := 3(x^2) -4 x -5 (*Same as above.*)

can be found by hand as

DDf[x_]:= 6 x-4

This pairing shares the same relationship as the original function and the derivative.

DDfplot = Plot[DDf[x], {x,-2.7,4}, PlotStyle->{Bold, Green}];
Manipulate[Show[Dfplot,DDfplot,
ListPlot[{{x,Df[x]}}, PlotStyle->{PointSize[0.03],Purple}],
Plot[Df'[x](y-x)+Df[x],{y,x-0.75,x+0.75},PlotStyle->{Dotted, Purple}],
ListPlot[{{x,DDf[x]}}, PlotStyle->{PointSize[0.03],Green}]],{x,-1.85,3.42}]

This is called the second derivative. Using Mathematica, this can be obtained directly, using the prime notation, as

f''[x]

DDf[x]==f''[x]

or, using the D[] function, as

D[f[x],{x,2}]

The second derivative gives information about the curvature of f(x).

Manipulate[Show[fplot,DDfplot,
ListPlot[{{x,f[x]}}, PlotStyle->{PointSize[0.03],Purple}],
Plot[((f''[x])/2)(((y-x))^2)+f'[x](y-x)+f[x],{y,x-1,x+1},PlotStyle->{Thick,Dotted, Purple}],
ListPlot[{{x,DDf[x]}}, PlotStyle->{PointSize[0.03],Green}]],{x,-2.14,3.42}]

Derivative Rules

As an example of Mathematica’s symbolic algebra, the derivative rules from class can all be obtained directly.

The Product Rule

D[F[x]G[x],x]

The Quotient Rule

Simplify[D[((F[x])/(G[x])),x]]

The Chain Rule

D[F[G[x]],x]

Recognizing Patterns

What if we want to extend the Product Rule?

Many Products

First we can try to extend the product rule to the product of more than two functions. Begining with three functions, we can get Mathematica to work out the derivative rule for this special case.

D[f1[x]f2[x]f3[x],x]

Notice that there are three terms, each with the derivative of one of the three functions. 
Doing the same thing for the product of four functions, we find four terms each with the derivative of one of the four functions.

D[f1[x]f2[x]f3[x]f4[x],x]

From here we can make a prediction about the derivative for any number of functions multiplied together.

Many Derivatives

Next we can try to extend the product rule to more than one derivative being taken. Begining with the second derivative, we can get Mathematica to work out the derivative rule for this special case.

D[F[x]G[x],{x,2}]

We have 3 terms, each with 2 total derivatives being taken (distributed over the two functions).

D[F[x]G[x],{x,3}]

We have 4 terms, each with 3 total derivatives being taken (distributed over the two functions).

D[F[x]G[x],{x,4}]

We have 5 terms, each with 4 total derivatives being taken (distributed over the two functions).