next up previous
Next: About this document ... Up: Labs and Projects for Previous: Labs and Projects for

Subsections


Derivatives

Purpose

The purpose of this lab is to teach you how to use Maple commands for computing derivatives.

Background

Maple has several commands for computing derivatives. The most common ones are the diff command for differentiating expressions and the D operator for differentiating expressions. These are the commands we will consider here.

Functions and Expressions in Maple

Before introducing the commands for differentiation, we need to review the concepts of expression and function in Maple. An expression is a collection of mathematical symbols, for example $x^2+\sin(3x)$ and x2-y2 are both expressions. A function, on the other hand, is a rule for associating an output value with an input value.

The connection is that expressions are often used to define a function. That is, we could let $f(x)=x^2+\sin(3x)$, which defines a function f. The rule for this function is to substitute a value for x into the expression $x^2+\sin(3x)$ to obtain the output value. Not all expressions can be used to define functions, however, and not all functions are defined by expressions so these really are distinct mathematical objects.

Maple mimics this mathematical distinction between expression and function. You can define expressions in Maple and even label them for later use with commands like the one below.

  > p := x^2+sin(3*x);

\begin{maplelatex}
\begin{displaymath}
{p} := {x}^{2} + {\rm sin}(\,3\,{x}\,)\end{displaymath}\end{maplelatex}
This is an expression not a function, which means there is no rule associated with it. Thus evaluating the expression at a specific value of x requires the subs command, as in the following example.
  > subs(x=2,p);

\begin{maplelatex}
\begin{displaymath}
4 + {\rm sin}(\,6\,)\end{displaymath}\end{maplelatex}
The syntax for defining a function in Maple uses an arrow to make the idea of a function as a process explicit. For example, we can define a function f in Maple using the expression $x^2+\sin(3x)$ with the following command.
  > f := x -> x^2+sin(3*x);

\begin{maplelatex}
\begin{displaymath}
{f} := {x} \rightarrow {x}^{2} + {\rm sin}(\,3\,{x}\,)\end{displaymath}\end{maplelatex}
Evaluating our function at a specific value of x is now easy.
  > f(2);

\begin{maplelatex}
\begin{displaymath}
4 + {\rm sin}(\,6\,)\end{displaymath}\end{maplelatex}
One final thing to note is that Maple will use f to denote the function we have defined, but will use f(x) to denote the expression used to define the function.

Something you should never do

Students often want to define a function with a command like the following.
  > F(x) := x^2+3;

\begin{maplelatex}
\begin{displaymath}
{\rm F}(\,{x}\,) := {x}^{2} + 3\end{displaymath}\end{maplelatex}
Since Maple doesn't complain, students often think that what they've done is correct. The output from the following commands, however, shows that the object we've defined doesn't behave like a function.
  > F(x);

\begin{maplelatex}
\begin{displaymath}
{x}^{2} + 3\end{displaymath}\end{maplelatex}
  > F(1);

\begin{maplelatex}
\begin{displaymath}
{\rm F}(\,1\,)\end{displaymath}\end{maplelatex}
  > F(t);

\begin{maplelatex}
\begin{displaymath}
{\rm F}(\,{t}\,)\end{displaymath}\end{maplelatex}
  > F(2*x);

\begin{maplelatex}
\begin{displaymath}
{\rm F}(\,2\,{x}\,)\end{displaymath}\end{maplelatex}
What is happening here is that we've defined something called a table in Maple. For the input x it gives the output x2+3, but it doesn't behave like a function and doesn't give the value we wanted for any other input.

The Maple D and diff commands

These commands can be summarized as follows.

When you use the D operator to compute the derivative of a function, the result is also a function, as shown below.

  > D(f);

\begin{maplelatex}
\begin{displaymath}
{x} \rightarrow 2\,{x} + 3\,{\rm cos}(\,3\,{x}\,)\end{displaymath}\end{maplelatex}
If you provide a label, then you get a function you can use later in the session,
  > df := D(f);

\begin{maplelatex}
\begin{displaymath}
{\it df} := {x} \rightarrow 2\,{x} + 3\,{\rm cos}(\,3\,{x}\,)\end{displaymath}\end{maplelatex}
However, this is usually not necessary. See the examples below.

If you want to evaluate the derivative at a specific value of x or just get the expression for the derivative, you can use the following forms of the D operator.

  > D(f)(2);

\begin{maplelatex}
\begin{displaymath}
4 + 3\,{\rm cos}(\,6\,)\end{displaymath}\end{maplelatex}
  > D(f)(x);

\begin{maplelatex}
\begin{displaymath}
2\,{x} + 3\,{\rm cos}(\,3\,{x}\,)\end{displaymath}\end{maplelatex}
This last form is the one to use for plotting, as shown below.
  > plot(D(f)(x),x=-2..2);

The D operator cannot be used on expressions, for example trying to use it to differentiate the expresssion we defined above results in an error.

  > D(p);
Error, (in D) univariate operand expected

If you recall that Maple uses f(x) to refer to the expresssion that is used to define f, then the following error shouldn't surprise you.
  > D(f(x));
Error, (in D) univariate operand expected

To differentiate expressions, you need to use the diff command. Here is an example.

  > diff(p,x);

\begin{maplelatex}
\begin{displaymath}
2\,{x} + 3\,{\rm cos}(\,3\,{x}\,)\end{displaymath}\end{maplelatex}
The diff command can also be applied to functions as shown below.
  > diff(f(x),x);

\begin{maplelatex}
\begin{displaymath}
2\,{x} + 3\,{\rm cos}(\,3\,{x}\,)\end{displaymath}\end{maplelatex}
Note, however, that the result of the diff command is an expression, not a function. This means that computing the value of the derivative at a specific value of x requires you to use the subs command.

Tangent Lines

In this subsection, we compute the tangent line at $x=\frac{3}{2}$ to our function f using first the D operator and then the diff command. This gives one example where the D operator is probably easier to use than the diff command.

To find the tangent line at $x=\frac{3}{2}$ to our function f, we need two pieces of information. One is the slope of the tangent line, which is given by $f'(\frac{3}{2})$, and the other is a point on the line, which is $(\frac{3}{2}),f(\frac{3}{2}))$. Then, using the point-slope formula, the equation for the tangent line is

\begin{displaymath}
y = f'(\frac{3}{2}) (x-\frac{3}{2}) +f(\frac{3}{2}) \end{displaymath}

Implementing this using the D operator is relatively simple, as shown below.
  > tf := x -> D(f)(3/2)*(x-3/2)+f(3/2);

\begin{maplelatex}
\begin{displaymath}
{\it tf} := {x} \rightarrow {\rm D}(\,{f}...
 ...! 
\,{\displaystyle \frac {3}{2}}\, \! \right) \end{displaymath}\end{maplelatex}
  > plot({f(x),tf(x)},x=0..3);

Using the diff command to compute the tangent line is a little harder, because the subs command must be used.

  > tf2  := x -> subs(x=3/2,diff(f(x),x))*(x-3/2)+f(3/2);

\begin{maplelatex}
\begin{displaymath}
{\it tf2} := {x} \rightarrow {\rm subs} \...
 ...! \,{\displaystyle \frac {3}{
2}}\, \! \right) \end{displaymath}\end{maplelatex}
  > plot({f(x),tf2(x)},x=0..2);

Exercises

1.
Give an example of a situations where the D operator would be easier to use than the diff command. Then give an example where the diff command would be better. In each case, make sure you justify your choice.
2.
Use either the D or diff commands to find the derivative of the following function. Plot the graph of the derivative over the given range and evaluate the derivative at the indicated point.

\begin{displaymath}
f(x) = \sqrt{x^2+3} \sin(3x)\end{displaymath}

Graph for $0 \leq
x \leq 2 \pi$. Evaluate at $x=\pi$.

3.
Consider the function

\begin{displaymath}
g(x) = \frac{x^4-2.75x^3-4.625x^2+5.5x+5.25}{x^2+1} \end{displaymath}

Find all of the points where the derivative of g is equal to 1.

4.
The tangent line to a function at a particular value of x intersects the graph of the function at least once, at the point of tangency. However, the tangent line may intersect the graph at other points. In this problem, we investigate whether the tangent line at one point can also be tangent to the graph at another point. For example, consider the function

g(x) = (x2-1)2

Show that the tangent line at x=-1 is also tangent to the graph at x=1.

Next, suppose we change the function slightly.

h(x) = (x2-1)2 +x/2

Is it still possible to find two different values of x such that the tangent lines coincide? The answer is yes. Find them.


next up previous
Next: About this document ... Up: Labs and Projects for Previous: Labs and Projects for

Jane E Bouchard
2/1/2000