Differentiation and its uses.
In the previous chapter, we looked at some tangent line problems which we solved by finding the limit of a ratio. For the function
, we found that the slope of the tangent line to the graph of f at a point [b,f(b)] is 2b. The defines a function, called the derivative of f,
. It turns out that the derivative function also measures the rate of change of f. The notion of rate of change has application to almost any area of knowledge. In this chapter, we begin to make serious use of differentiation in solving problems which involve rate of change.
Defining Derivatives
> f := x -> x^2 + x -3;
> fp := limit((f(x+h)-f(x))/h,h=0);
You would get the same thing by entering
> fp := diff(f(x),x);
>
> y := x^2 + x;
would be computed with, as follows:
> yp := diff(y,x);
Now evaluate the derivative of y at
using
subs
,
> subs(x=3,yp);
> yp:=unapply(yp,x);
> yp(3);
> f := x -> x^2 + x;
> df := D(f);
> df(3);
The student package
> with(student);
> showtangent(x^3+x-1,x=4.5,color=black);
>
Problems
Exercise: Use each word unapply and D to define the derivative of
Plot both f and its derivative over the interval [-1..1]
> f := x->x^4 - 2*x^3 + x -3 ;
> df := D(f);
> plot({f,df},-2..2);
Exercise: Use 'for x from -1 by .25 to 2 do' to tabulate the values of f and its derivative at increment of .25 over the interval from -1 to 2.
>
>
3. Plot f and its derivative over this interval. Then use showtangent to plot f and the tangent line to the graph at
.
>
>
4. Where does f cross the x-axis? Find the zeros of f '(x). That is, find the extreme values of f.
>
>
Newton's Method.
You have used fsolve to solve an equation
for x. How does that work? It possibly might use Newton's method, which is a very fast method for solving such equations when f is differentiable. The idea is simple. By graphing or guessing, you come up with a first estimate of the solution, call it x0. Now the point (x0,f(x0)) is probably not on the x-axis. Iif it were then f(x0) is 0 and x0 is a solution. So we go along the tangent line to the graph of f until we come to the x-axis, at the point (x1,0) say. We find that we can express x1 in terms of x0, f(x0), and f'(x0). This number x1 is the second approximation to the solution.
> restart;
> eq := diff(f(x0),x0) = (f(x0)-0)/(x0-x1);
> expand(solve(eq,{x1}));
>
>
vnewt := proc(f,start,a,b,iterations)
local i, x0, fp, p,pl1,pl2;
x0 := evalf(start);
fp := D(f);
p := [x0,0];
for i from 1 to iterations do
p := p, [x0, f(x0)];
x0 := x0 - f(x0)/fp(x0);
p := p,[x0,0];
od;
pl1 := plot( [p] ,x=a..b, color=black);
pl2 := plot(f,a..b,color=red) ;
### WARNING: semantics of type `string` have changed
plots[display]([pl1,pl2],title=convert(x0,string));
end:
Now test vnewt to solve
by starting starting at 3 and using a plot interval of 0 to 4..
> vnewt(x -> x^2 - 2, 10 , 0, 10 ,5);
>
Exercises.
Exercise:
Use vnewt to solve
for
x
for various starting points from 2 to 3.05. Are there starting points which don't lead to a solution? Explain your answer.
>
>
Exercise:
Use vnewt to solve
. Try start at .2, a at -.3, b at .3. What happens?
>
>
Exercise: Define a new version of vnewt, tnewt, which has the same inputs, but returns the list of approximations to the root. Test your word.
>
>
>
Use of the derivatives in plotting
For example, let's look at the function
> y := (x^5-1)/(6*x^2+1);
>
First plot it over an interval, say from
to 2.
> plot(y,x=-2..2);
>
> yp := diff(y,x);
> yp := simplify(yp);
>
Get the critical points by solving
. Actually, we get better results by finding when the numerator of yp is 0.
> cp := fsolve(numer(yp),x);
>
cp is an expression sequence of two critical points, cp[1] and cp[2]. By inspecting the graph, we can see that cp[1] is a local maximum and cp[2] is a local min. Let's evaluate y at
, and at
.
> subs(x = cp[1],y);
> subs(x = cp[2],y);
>
Now we know the coordinates of the extreme points on the graph. Next let's get the coordinates of the inflection points.
> ypp := diff(yp,x);
> simplify(ypp);
> pip := fsolve(numer(ypp),x);
> for i from 1 to 3 do print(pip[i], subs(x=pip[i],y)) od;
>
So we see there are three inflection points.
Exercise: there always an inflection point between two extreme points? Explain your answer.
Exercise: Is there always an extreme point between two inflection points? Explain your answer.
Implicit Differentiation
Suppose you have a curve in the plane which is defined by an equation in x and , say
. If [x0,y0] is a point on the curve, that is
, then we can ask for an equation for the tangent line to the curve at that point. One way to obtain the slope of the tangent is as follows: assume that y is a function of x near [x0,y0]. Then near [x0,y0], f(x,y(x)) is the constant function 0, so when we differentiate f(x,y(x)) with respect to x the result function of x is the constant function 0. But also, the function we get will be linear in y'(x). That means we can solve for y'(x) in terms of x and y(x). Evaluating this at [x0,y0] gives the slope of the tangent. This algorithm is referred to as
implicit differentiation
.
Exercise: Plot the equation
in the rectangle x=0..4, y= 0..2, and draw a tangent to the graph at the point [3,y0] where y0 is between 0 and .6.
Solution:
First we will draw the curve using plots[implicitplot] .
> plots[implicitplot](x^2*sin(x*y)+y^3-5 = 0,x=0..4,y=0..2);
Now we need to find the desired y0. Use fsolve for that.
> y0 := fsolve(3^2*sin(3*y)+y^3-5=0,y,0..(.6));
Now let's get a formula for y'(x). First substitute y(x) in for y.
> g := subs(y=y(x),x^2*sin(x*y)+y^3-5=0) ;
Then differentiate the resulting function of x with respect to x.
> dg := diff(g,x);
Notice the left hand side is linear in y'(x), as we asserted it would be. So solve the equation for y'(x).
> yp := solve(dg,diff(y(x),x));
Now turn this back into an expression in x and y.
> yp := subs(y(x)=y,yp);
Calculate the slope of the tangent at [3,y0].
> slope :=evalf(subs({x=3,y=y0},yp));
Write the equation for the tangent line in point slope form.
> tangent := y - y0 = slope*(x-3);
Plot the curve and tangent separately so that we can color them differently. Then display them.
> curve :=plots[implicitplot]( x^2*sin(x*y)+y^3-5 = 0 ,x=0..4,y=0..2,thickness=2):
> tanline := plots[implicitplot]( tangent ,x=0..4,y=0..2,thickness = 2, color=blue):
> plots[display]([curve,tanline]);
Exercise: Find a point on the curve in the rectangle where the tangent line is vertical. (Hint: you will need to assume x is a function of y and differentiate with respect to y here.)
Max-min Problems
A vast number of problems fall into the category of the so-called max-min problems. These are problems in which some quantity, Q, is to be maximized or minimized as needed. The quantity Q is a function of one or more other variables which are subject to some constraints. We attempt to use these constraints to eliminate all but one of the variables in the computation of Q. If we are successful in doing this, we can then use calculus to locate the maximum or minimum if it exists.
Let's take an example.
A Paper folding problem:
Problem: A sheet of paper 4 inches wide by 8 inches high is folded so that the bottom right corner of the sheet touches the left hand edge of the sheet. The tip of the corner is no more than 4 inches above the bottom edge of the paper. Then the paper is creased (see figure). Find the length L of the crease, and find how to fold the paper so that L is minimum.
Solution:
Let h, x, and y be as shown in the diagram below.
> restart;
> A1:=plots[textplot]({[2.6,1.9,'L'],[3.7,2,'h'],[.1,1.1,`y`],[.5,.3,`x`],},align=RIGHT):
> A3:=plot({[[0,0],[0,8],[4,8],[4,4.45],[1.219,0],[0,0]],[[4,4.45],[0, 2.5],[1.219,0]]},color=blue):
> A4:=plot([[4,4.45],[4,0],[1.219,0]],color=red):
> A5:=plots[polygonplot]([[4,4.45],[0,4.45],[0,2.5]],style=patch,color=tan):
> plots[display]([A1,A3,A4,A5],axes=boxed,scaling=constrained);
>
We can see several equations relating x, y, h, and L in the diagram. For example, the small right triangle with legs x and y has a hypotenuse which is 4-x units long. This gives eq1.
> eq1 := y^2+x^2=(4-x)^2;
eq2 comes from the right triangle with hypotenuse L and legs h and 4-x.
> eq2 := L^2 = (4-x)^2 + h^2;
Now it is easy to work out that the tan right triangle with hypotenuse h and legs 4 and h-y is similar to the right triangle with hypotenuse 4-x and corresponding legs y and x. So we get eq3.
> eq3 := 4/(h-y)=y/x;
>
> h := solve(eq3,h);
> x := solve(eq1,x);
> L := unapply(sqrt(op(2,simplify(eq2))),y);
>
So we have L expressed as a function of one variable y. Examining the behavior of L as y varies,
> plot(L,2..4);
we see that there is a minimum length crease of about
inches at about
inches. We can get a more precise value with fsolve, by locating the x between 2.6 and 3 where the derivative of the crease function is 0.
> y1 := fsolve(diff(L(y),y),y,2.6..3);
>
Now check the value of x and L for this value of y.
> minL := L(y1);
> minx := subs(y=y1,x);
>
Notice the nice integer value of minx . This gives rise to a simple construction of the crease of minimum length: by folding twice along the bottom edge, we can mark the point 1 inch from the left edge of the paper. Then bring the corner point up to the left edge and crease.
Exercise: Use Maple to draw the diagram showing the minimum length crease.
>
Exercise: Suppose we wanted to minimize L + y, rather than just L. Would the minimum occur at the same place? Work it out.
>