Up to Main Lab Page | Next Lesson - Exponential Functions | Previous Lesson - Plotting Points and Limits |
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.
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);
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
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));
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]);
Up to Main Lab Page | Next Lesson - Exponential Functions | Previous Lesson - Plotting Points and Limits | Top of this Lesson |