   Next: About this document ... Up: lab_template Previous: lab_template

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 functions. These are the commands we will consider here.

### Functions and Expressions in Maple

Before describing 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 and 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 functions. That is, we could let , which defines a function . The rule for this function is to substitute a value for into the expression 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);

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 requires the subs command, as in the following example.
> subs(x=2,p);

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 in Maple using the expression with the following command.
> f := x -> x^2+sin(3*x);

Evaluating our function at a specific value of is now easy.
> f(2);

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;

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);
> F(1);
> F(t);
> F(2*x);

What is happening here is that we've defined something called a table in Maple. For the input it gives the output , 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.
• The D operator acts on a function to produce the derivative of that function.
• The diff command acts on an expression and differentiates that expression with respect to a variable specified by the user.

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

> D(f);

If you provide a label, then you get a function you can use later in the session,
> df := D(f);

However, this is usually not necessary. See the examples below.

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

> D(f)(2);
> D(f)(x);

This last form is the one to use for plotting, as shown below.
> plot(D(f)(x),x=-2..2);


Suppose you want to find the equaton of the line tangent to the graph of at the point . This can be done in Maple using the point slope form of a line as shown below.

> tanline := D(f)(5)*(x-5)+f(5);


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);

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


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

> diff(p,x);

The diff command can also be applied to functions as shown below.
> diff(f(x),x);

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 requires you to use the subs command.

## Exercises

1. Compute the derivatives of the following functions using both the diff command and D operator for each function.
1. 2. 2. Find the equation of the line tangent to the graph of the function at . Include a plot of the function and the tangent line on the same graph over the interval .

3. For the function in exercise 2, find all points where the slope of is equal to . Include a plot of the derivative and the line on the same graph. Remember that a point has an and a value.   Next: About this document ... Up: lab_template Previous: lab_template
William W. Farr
2002-11-12