Graphs, Shape Tables, and Plot[.]

by
K. D.  Stroyan
University of Iowa

copyright 1997 by Academic Press, Inc. - All rights reserved.

Special Mathematica Functions used in this NoteBook

Needs["Graphics`Colors`"];

Notebook Overview

This NoteBook shows the connection between the analytical "shape" information and the graph.  The point is not only to make a graph with Plot[.], but to use calculus to see where to graph.

References to the Text

This NoteBook goes with Chapter 9 of the text.

Simple Algebraic Examples

A Simple Function on Several Scales (Compare with Example 9.1)

This next function has a different appearance at different scales.  <Enter> the calculation to see for yourself.

Clear[x, f]; f[x_] := (x^4) - 5 (x^3) + 4 xscale = 100; \(large = Plot[f[x], {x, \(-scale\), scale}, PlotStyle -> {Red}]; 

    scale = 10; 

    medium = Plot[f[x], {x, \(-scale\), scale}, PlotStyle -> {Blue}]; 

    scale = 1; 

    small = Plot[f[x], {x, \(-scale\), scale}, PlotStyle -> {DarkGreen}]; 

    scale = 0.1; 

    tiny = Plot[f[x], {x, \(-scale\), scale}, PlotStyle -> {Brown}]; 

    Show[GraphicsArray[{{large, medium}, {small, tiny}}]]; \)

The First Derivative Shape Information

We do the procedure from the text to find the places where the graph is increasing and decreasing.  First, we solve for  f'[x] = 0:

Solve[f'[x]==0,x]NSolve[f'[x]==0,x]

f'[-1.0]f'[0.0]f'[1.0]f'[4.0]

This shows that y = f[x] is decreasing until  x = -0.49, increasing from there to  x = 0.56, decreasing from there to x = 3.7 and incrasing after that.  The full shape is included in the interval [-1,4], so here's a Plot[.] over that interval:

Plot[{f[x],20 Sign[f'[x]]},{x, -1.5, 5},PlotStyle -> {{Thickness[0.02], Red}, Blue}];
Print["Slope  ±  with Blue"];

Example 9.2: The Shape of f[x] = 3 (x^5) - 5 (x^3)

Clear[x, f]; f[x_] := 3 (x^5) - 5 (x^3)NSolve[f'[x]==0,x]

f'[-2.0]f'[-0.5]f'[0.5]f'[2.0]

The location of zero, positive and negative derivatives shows that the shape is up before x = -1, down to x = 0 (over at this point) then down again to  x=+1 and up after that.  A graph on the interval [-2,2] shows all the shape:

Plot[{f[x],5 Sign[f'[x]]},{x, -1.75, 1.75},PlotRange -> {-10, 10},PlotStyle -> {{Thickness[0.02], Red}, Blue}];
Print["Slope  ±  with Blue"];

Trascentental Examples

The Shape of  y = f[x] = (x^2) Cos[x]

Mathematica may not be able to solve for all the zeros of the derivative.  Here is an example:

Clear[x, f]; f[x_] := (x^2) Cos[x]; f'[x]

Solve[f'[x]==0,x]

We can see by inspection of the derivative that  x = 0  is one root.  There are lots of others, though we don't want to solve the equation

2 x Cos[x] == (x^2) Sin[x]

by hand.  In this case, we can sketch the graph by hand without calculus or Mathematica, simply by sketching  y = Cos[x]  and then amplifying the height of the oscillations as  x  grows.

scale = 2; Plot[f[x], {x, -scale, scale}]; scale = 10; Plot[f[x], {x, -scale, scale}]; scale = 50; Plot[f[x], {x, -scale, scale}];

If needed, we can approximate the x-values where the derivative is zero by use of FindRoot[.] with a starting guess near a place that looks close to a horizontal point.

FindRoot[f'[x]==0,{x, 1}]FindRoot[f'[x]==0,{x, 4}]FindRoot[f'[x]==0,{x, 7}]FindRoot[f'[x]==0,{x, 10}]

Example 9.3: The Slope of  y = f[x] = x Exp[ -x ]

Clear[x, f]; f[x_] := x Exp[-x]; f'[x]

Solve[f'[x]==0,x]

f'[0]f'[2]

The shape information alone says up until  x = 1, then down.  It is helpful to know limiting values as  x -> - Infinity and  x -> + Infinity:

Limit[f[x], x -> -∞]Limit[f[x], x -> +∞]

Plot[{f[x],Sign[f'[x]]},{x, -1, 10},PlotStyle -> {{Thickness[0.02], Red}, Blue},AxesLabel -> {"x", "y"}];
Print["Slope  ±  with Blue"];

Example 9.7: The Shape of  y = f[x] = Exp[-(x^4)]  with Bending

The second derivative tells us when a graph  y = f[x]  bends upward or downward.  Mathematica can help find the signs.

Clear[x, f]; f[x_] := Exp[-(x^4)]f'[x]

This derivative is only zero at x=0.  Obvious, but Mathematica knows:

Solve[f'[x]==0,x]

f''[x]

Solve[12 (x^2) == 16 (x^6), x]

N[%]

Three real roots,  x=0, x=-0.93, x=+0.93.

f''[-1.0]
f''[-0.1]
f''[0.1]
f''[1.0]

Smile, frown, frown, smile.  The plot can still give thecomputer trouble:

Plot[f[x],{x,-1,1},PlotStyle->{Red}];
Plot[f[x],{x,-10,10},PlotStyle->{Red}];
Plot[f[x],{x,-2,2},PlotStyle->{Red}];
Plot[{f[x],0.8Sign[f'[x]],1.1Sign[f''[x]]},{x,-2,2},PlotStyle->{Red,Blue,DarkGreen},AxesLabel->{"x","y"}];
Print["Slope  ±  with Blue, bend  ±  with Green"];

Example 9.8: The Shape of y = f[x] = x Log[x] with Bending

The second derivative tells us when a graph  y = f[x]  bends upward or downward.  Mathematica can help find the signs.

Clear[x, f]; f[x_] := x Log[x]f'[x]

This derivative is only zero at x=1/E.  Obvious, but Mathematica knows:

Solve[f'[x]==0,x]

f''[x]

Always smiling...  Limits might help:

Limit[x Log[x], x -> 0]Limit[x Log[x], x -> ∞]

Let's plot:

\(Plot[{f[x], 0.8  Sign[\(f'\)[x]], 1.1  Sign[\(\(f'\)'\)[x]]}, {x, 0.01, 
        2}, PlotStyle -> {Red, Blue, DarkGreen}, 
      AxesLabel -> {"x", "y"}]; 

    Print["Slope  ±  with Blue, bend  ±  with Green"]; \)

Exercises

Exercise 9.1.3

Plot the function  y = f[x] = (x^5) + 4 (x^4) + x  on the scales -100 to 100,  -10 to 10, -1 to 1 and -0.1 to 0.1 and compare the different appearances.  Solve for the x-values where the slope is horizontal,  f'[x] = 0  and compute the signs of the derivatives at inbetween points to find the complete shape information of this function.

Exercises 9.3.3 &  9.4.2: Check your Hand-Computed Shape Tables

Use Mathematica to help determine the shape of the following functions and plot over an appropriate range.

a)  y = f[x] = 2 (x^2) - (x^4)

b)  y = f[x] = (x^3) - 3 x

c)  y = f[x] = 6 (x^5) - 10 (x^3)

d)  y = f[x] = (((x + 2))^(2/3))

e)  y = f[x] = Sin[x] + Cos[x]

f)  y = f[x] = Sin[x] * Cos[x]

g)  y = f[x] = x Exp[x]

h)  y = f[x] = Exp[-(x^2)]

i)  y = f[x] = x Log[x]

j)  y = f[x] = x - Log[x]

k)  y = f[x] = (1/(1 + (x^2)))

j)  y = f[x] = (1/(1 - (x^2)))

Problem 9.1: y = ((((x^3) - (x^2) + 1))^2)

Plot the function  y = f[x](( = ((x^3) - (x^2) + 1))^2).  Working by hand to solve  f'[x] = 0  is possible if you look at the factors of  f'[x]  and analyse the graph of those factors.  Mathematica's NSolve[.] makes that a freebie, but the question still is: "What's a good x-range?"

Clear[x, f]; f[x_] := ((((x^3) - (x^2) + 1))^2)f'[x]

Plot[f'[x],{x, -?? ,??}];

NSolve[f'[x]==0,x]NSolve[f''[x]==0,x]