Math 151-01,02
September 16, 2013

DERIVATIVES

Introduction

Goals: In this worksheet you will learn two different Mathematica procedures for computing derivatives symbolically.

Examples

The first Mathematica command, D, is used to differentiate mathematical expressions such as (x^n) or sin(x).

D[x^n,x]
D[Sin[x],x]

The second way to deal with derivatives in Mathematica is via the Derivative function which usually is used with the well-known prime(') notation. In this case, f' denotes the derivative of the function f.

f[x_]:=x^n; f'[x]
f[x_]:=Sin[x]; f'[x]

Higher-order derivatives (derivatives of derivatives (of derivatives, etc.)) are given, respectively, by

D[x^n, {x,2}]

f[x_]:=Sin[x]; f''[x]

Example 1:

Recall that the volume of a right circular cone of radius r and height h is given by V=((π (r^2)h)/3).

Graphics3D[Cone[],Boxed->False]

We may enter this formula in Mathematica as:

v=Pi*r^2*h/3

In order to determine the instantaneous rate of change of the volume with respect to the radius of the base of the cone, we must compute the derivative (dv/dr). Since v above is given as a mathematical expression representing the volume of the cone in terms of the radius r we can enter the following command to accomplish this:

D[v,r]

Alternatively, we could define the volume as a function of the radius, and then use the prime to obtain the derivative (note that we first need to clear the variable v if we want to use the same letter again as the name of a function - try what happens if you don't use Clear):

Clear[v]
v[r_]:=Pi*r^2*h/3
v'[r]

Example 2:

Both the prime notation and the differential operator D may also be applied when differentiating piecewise defined functions.
Consider the following function M, with the piecewise definition given in Mathematica by:

funcM[x_]:=Piecewise[{{x+2,x≥-2 && x≤-1},
{(x^2),x>-1 && x ≤2},{8-2x, x>2 && x ≤ 4}}]
funcM[x]

Now we differentiate M in the usual way, first using the prime:

m[x_]:= funcM'[x]
m[x]

Next, we plot a graph of M and its derivative m on the same coordinate plane.

Plot[{funcM[x],m[x]},{x,-2,4},PlotStyle -> {{Blue,Thick},{Red,Thick}}]

Alternatively, we use the D operator to differentiate the expression M(x):

m=D[funcM[x],x]

Finally, we again plot the graph of M with its derivative on the same coordinate plane.

Plot[{funcM[x],m},{x,-2,4},PlotStyle -> {{Blue,Thick},{Red,Thick}}]

Exercises

After completing the exercises, delete every else (Introduction, Examples, attempts and bits of code that didn’t pan out), and print the lab.  Hand it in one week from today, on Monday, September 23.

Exercise 1

In the figure below, the graph of the function y=f ( x ) is shown.

Write a piecewise formula in Mathematica for the function f, for -3≤x≤+3.

Plot a Mathematica graph of y=f ( x ) using your definition.

Use Mathematica to find the derivative of f.

Plot a Mathematica graph of  y=f ' ( x ) and verify that it agrees with the figure displayed above.

Exercise 2

The trigonometric "polynomial" F(t)=0.78540-0.63662cos(2t)-0.07074cos(6t)-0.02546cos(10t)-0.01299cos(14t)

gives a good approximation to the sawtooth function s=G(t) shown below, over the interval [-π, π].

How well does the derivative of F approximate the derivative of G at the points where ((dG)/(dt)) is defined? To find out, carry out the following steps.

Graph F and G on the same coordinate plane over [-π, π].

Graph g=((dG)/(dt)) (where defined) over [-π, π].

Find f=((dF)/(dt)).

Graph f and g on the same coordinate plane. Where does the approximation of ((dG)/(dt))by ((dF)/(dt))seem to be best/least good?

To make it easier, here’s G[x] for you to use:

G[x_]:=Piecewise[{{x+Pi,x≥-Pi && x≤-Pi/2},{-x,x≥-Pi/2 && x≤0},{x,x≥0 && x≤Pi/2},{-x+Pi,x≥Pi/2 && x≤Pi}}]