Ryerson Crest Ryerson Header

MTH 207 Lab Lesson 10

Secants, Tangents and Derivatives


Up to Main Lab Page Next Lesson - Exponential Functions Previous Lesson - Plotting Points and Limits

Secant Lines

Given a function f(x), and two points on the curve (a, f(a)) and (b, f(b)) the line joining these two points is called a secant line of f. (Not to be confused with the trigonometric secant (sec) funtion.) The following example plots the secant of y = x2 from 0 to 1.
> f := x -> x^2;
> a := 1: b:= 0:
> m := (f(b) - f(a))/(b - a);
> g := x -> m*(x - a) + f(a);
> plot([f(x), g(x)], x = -1..2);

The slope of the secant line is (f(b) - f(a))/(b - a). As b approaches a this tends to the tangent line. Using b = 1 - 1/n and a = 1 + 1/n:
> f := x -> x^2;
> secs := ((f(1 - 1/n) - f(1 + 1/n))/((1 - 1/n) - (1 + 1/n)))*(x - (1 + 1/n)) + f(1 + 1/n) $ n = 1..5;
> plot([f(x), secs], x = -.1..1.3);

The slope of the tangent is the derivative of the function.
slope of tangent = limx -> a(f(x) - f(a))/(x - a) = f '(x). The limit of the slopes of the secant lines.

  1. Plot secant lines of the follwing functions about the given point:
    1. sin(x), Pi/4.
    2. sin(3x), Pi/4.
    3. tan(x2), Pi/4.

Differentiation

Maple can do differentiation, however it must distinguish between functions and expressions. It is important to understand the difference between the two when using differentiation in Maple.

The syntax for functions is

D(function name)

The syntax for expressions is

diff(expression, variable)

The reason for this distinction is that a function has an implicit variable, x in f(x). Thus, this is similar to writing f '(x), it is understood that the derivative is with respect to x.

On the other hand in an expression there is no obvious indication of which variable is the one to differentiate with respect to. This is more akin to writing df/dx.

For example:
> f := x -> x^2;
> D(f);
> y := x^3;
> diff(y, x);

We can translate a function name f into an expression by f(x).
We can translate an expression into a function by using unapply.

What happens if we give an expression to D?
> y := x^3;
> D(y);

2 D(x) x

Since Maple didn't know which variable y was to be differentiated with respect to it generated an implicit derivative, with D(x) representing the derivative of x with resprect to the unknown differentiating variable.

Note that passing a function name, f to diff is an error. Maple will return 0 since it thinks that a function name like f is a constant.
> f := x -> x^3;
> diff(f, x); # WRONG - gives 0
> diff(f(x), x); # Works OK

In fact D is an operator from functions to functions. That is the result of D(f ) is itself a function.
This means we can use D(f) like a function, and give it an argument: D(f)(x).
For example if f(x) = sin(x) then f = sin, and so D(f) = cos, and D(f)(x) = cos(x).
This is important since in many cases Maple expects an expression and so passing D(f) will generate an error.
> f := x -> sin(x);
> D(f);
> D(f)(u);
> D(f)(1);
> simplify(D(f)); # Generates an error (simplify(expression))
> simplify(D(f)(x)); # OK
> plot(D(f), x=-Pi..Pi); # Empty plot
> plot(D(f)(x), x=-Pi..Pi); # OK

  1. Copy and paste the following definitions into Maple, and for each one find its derivative. In each case plot the function on the same graph with its derivative.
    1. f := sin(x);
    2. f := x -> tan(x);
    3. f := x^2 - x
    4. f := 2*x^4 + 3*x^3 - 17*x^2 - 12*x + 36;
    5. f := x -> (x-2)/((x-1)*(x+1)*(x+2));

Higher Derivatives

We can use Maple to find higher derivatives of functions and expressions.

D Syntax

If f is a function name then (D@@n)(f) will find the nth derivative of f.
> f := x -> (x - 2)/((x - 1)*(x + 1));
> (D@@2)(f);
> simplify((D@@2)(f)(x));
> (D@@3)(f);
> simplify((D@@3)(f)(x));

diff Syntax

If y is an expression
diff(y, x, x) will find the second derivative of y with respect to x,
diff(y, x, x, x) will find the third derivative of y with respect to x,
diff(y, x, x, x, x) will find the fourth derivative of y with respect to x,
and so on.

We can use the iteration operator ($) to simplify this syntax to diff(y, x$n) for the nth derivative.
> y := (x - 2)/((x - 1)*(x + 1));
> diff(y, x);
> diff(y, x, x);
> simplify(");
> diff(y, x$3);
> simplify(diff(y, x$3));

  1. For each of the following find the first, second, third and fourth derivatives, simplify your answer in each case.
    1. f := tan(x^2);
    2. f := x -> 1/((x-1)*(x-2));
    3. f := x -> sin(exp(cos(x)));
    4. f := (x+1)/(x-1);

Properties

We can see some of the salient points of derivatives by plotting the first and second derivatives of a function on the same graph.
> f := x -> (x - 2)/((x - 1)*(x + 1));
> plot([f(x), D(f)(x), (D@@2)(f)(x)], x = -5..5, -10..10, discont=true, color=[red,green,blue]);

  1. In each case plot the function together with its first and second derivatives, and consider the relations between them.
    1. f := x^3;
    2. f := x -> x^4 - 5*x^2;
    3. f := 1/x;
    4. f := (x+1)/((x-1)*x);
    5. f := x -> (x-2)/((x-1)*(x+1)*(x+2));
    6. f := cos(x)
    7. f := cos(2*x);
    8. f := x -> sec(x);


Up to Main Lab Page Next Lesson - Exponential Functions Previous Lesson - Plotting Points and Limits Top of this Lesson


Maintained by: P. Danziger, Febuary 1998