Chapter 1	Introduction

Welcome to Mathematica! This tutorial manual is intended as a supplement to Rogawski's Calculus textbook and aimed at students looking to quickly learn Mathematica through examples.  It also includes a brief summary of each calculus topic to emphasize important concepts.  Students should refer to their textbook for a further explanation of each topic.

1.1  Getting Started

Mathematica is a powerful computer algebra system (CAS) whose capabilities and features can be overwhelming for new users.  Thus, to make your first experience in using Mathematica as easy as possible, we recommend that you read this introductory chapter very carefully.  We will discuss basic syntax and frequently used commands.

NOTE: You may need to obtain a computer account on your school's computer network in order to access the Mathematica software package available on campus computers.  Check with your instructor or your school's IT office.

1.1.1  First-Time Users of Mathematica 7

Launch the program Mathematica 7 on your computer.  Mathematica will automatically create a new Notebook (see typical startup screen below).

1.1.2  Entering and Evaluating Input Commands

Just start typing to input commands (a cell formatted as an input box will be automatically created).  For example, type 3+7.  To evaluate this command or any other command(s) contained inside an input box, simultaneously press SHIFT+ENTER, that is, the keys SHIFT and ENTER at the same time.  Be sure your mouse's cursor is positioned inside the input box or else select the input box(es) that you want to evaluate.  The kernel application, which does all the computations, will load at the first evaluation.  This is a one-time procedure whenever Mathematica is launched and may take a few seconds depending on the speed of your computer, so be patient.

As can be seen from the screen shot above, a cell formatted as an output box and containing the value 10 is generated as a result of the evaluation.  To create another input box (cell), just start typing again and an input box will be inserted at the position of the cursor (use the mouse to position the cursor where you would like to insert the new input box).

1.1.3  Documentation Center (Help Menu)

Mathematica provides an online help menu to answer many of your questions about the program.  One can search for a particular command expression in the Documentation Center under this menu or else just position the cursor next to the expression (for example, Plot) and select Find Selected Function (F1) under the Help menu (see screen shot that follows).

Mathematica will then display a description of Plot, including examples on how to use it (see screen shot below).

For only a brief description of Plot (or any other expression expr), just evaluate ?Plot (or ?expr).

?Plot

1.2  Mathematica's Conventions for Inputting Commands

1.2.1  Naming

Built-in Mathematica commands, functions, constants, and other expressions begin with capital letters and are (for the most part) one or more full-length English words (each word is capitalized).  Furthermore, Mathematica is case sensitive; a common cause of error is the failure to capitalize command names.  For example, Plot, Integrate, and FindRoot are valid function names.  Sin, Exp, Det, GCD, and Max are some of the standard mathematical abbreviations that are exceptions to the full-length English word(s) rule.

User-defined functions and variables can be any mixture of uppercase and lowercase letters and numbers.  However, a name cannot begin with a number.  User-defined functions may begin with a lowercase letter, but this is not required.  For example, f, g1, myPlot, r12, sOLution, and Method1 are permissible function names.

1.2.2.  Parenthesis,  Brackets, and Braces

Mathematica interprets various types of delimiters (brackets) differently.  Using an incorrect type of delimiter is another common source of error.  Mathematica's bracketing conventions are as follows:

1) Parentheses, ( ), are used only for grouping expressions.  For example, (x-y)^2, 1/(a+b) and (x^3-y)/(x+3y^2) demonstrate proper use of parentheses.  Users should realize that Mathematica understands f(2) as f multiplied with 2 and not as the function f(x) evaluated at x=2.

2) Square brackets, [ ], are used to enclose function arguments.  For example, Sqrt[346], Sin[Pi], and Simplify[(x^3-y^3)/(x-y)] are valid uses of square brackets.  Therefore, to evaluate a function f(x) at x=2, we can type f[2].

3) Braces or curly brackets, { }, are used for defining lists, ranges and iterators.  In all cases, list elements are separated by commas.  Here are some typical uses of braces:
{1, 4, 9, 16, 25, 36}: This lists the square of the first six positive integers.
Plot[f[x],{x,-5,5}]: The list {x,-5,5} here specifies the range of values for x in plotting f.
Table[m^3,{m,1,100}]: The list {m,1,100} here specifies the values of the iterator m in generating a table of cube powers of the first 100 whole numbers.

1.2.3.  Lists

A list (or string) of elements can be defined in Mathematica as List[(Subscript[e, 1]),(Subscript[e, 2]),...,(Subscript[e, n])] or {(Subscript[e, 1]),(Subscript[e, 2]),...,(Subscript[e, n])}.  For example, the following command defines S={1,3,5,7,9} to be the list (set) of the first five odd positive integers.

S=List[1,3,5,7,9]

To refer to the kth element in a list named expr, just evaluate expr[[k]].  For example, to refer to the fourth element in S, we evaluate

S[[4]]

It is also possible to define nested lists whose elements are themselves lists, called sublists.  Each sublist contains subelements.  For example, the list T={{1,3,5,7,9},{2,4,6,8,10}} contains two elements, each of which is a list (first five odd and even positive integers).

T={{1,3,5,7,9},{2,4,6,8,10}}

To refer to the kth subelement in the jth sublist of expr, just evaluate expr[[j,k]].  For example, to refer to the third subelement in the second sublist of T (or 6), we evaluate

T[[2,3]]

A detailed description of how to manipulate lists (e.g., to append elements to a list or delete elements from a list) can be found in Mathematica's Documentation Center (under the Help menu).  Search for the entry List.

1.2.4.  Equal Signs

Here are Mathematica's rules regarding the use of equal signs:

1) A single equal sign (=) assigns a value to a variable.  Thus, entering q = 3 means that q will be assigned the value 3.

q=3

If we then evaluate 10+q^3, Mathematica will return 37.

10+q^3

As another example, suppose the expression y = x^2-x-1 is entered.

y=x^2-x-1

If we then assign a value for x, say x=3, then in any future input containing y, Mathematica will use this value of x to calculate y, which would be 5 in our case.

x=3
y

2) A colon-equal sign (:=) creates a delayed statement for an expression and can be used to define a function.  For example, typing f[x_]: = x^2-x-1 tells Mathematica to delay the assignnment of f(x) as a function until f is evaluated at a particular value of x.

f[x_]:=x^2-x-1
f[3]

We will say more about defining functions in section 1.3 below.

3) A double-equal sign (= =) is a test of equality between two expressions.  Since we previously set x = 3, then evaluating x = = 3 returns True, whereas evaluating x = = -3 returns False.

x==3
x==-3

Another common usage of the double equal sign (= =) is to solve equations, such as the command Solve[x^2-x-1= = 0, x] (see Section 1.5).  Be sure to clear the variable x beforehand.

Clear[x]
Solve[x^2-x-1==0,x]

1.2.5.  Referring to Previous Results

Mathematica saves all input and output in a session.  Type In[k] (or Out[k]) to refer to input (or output) line numbered k.   One can also refer to previous output by using the percent sign %.  A single % refers to Mathematica's last output, %% refers to the next-to-last ouput, and so forth.  The command %k refers to the output line numbered k.  For example, %12 refers to output line number 12.

Out[12]

Mathematica saves all input and output in a session.  Type In[k] (or Out[k]) to refer to input (or output) line numbered k.   One can also refer to previous output by using the percent sign %.  A single % refers to Mathematica's last output, %% refers to the next-to-last ouput, and so forth.  The command %k refers to the output line numbered k.  For example, %12 refers to output line number 12.

%12

NOTE: CTRL+L reproduces the last input and CTRL+SHIFT+L reproduces the last output.

1.2.6.  Commenting

One can insert comments on any input line.  The comments should be enclosed between the delimiters (* and *).  For example,

(* This command plots the graph of two functions in different colors. *)Plot[{Sin[x],Cos[x]},{x,0,2Pi},PlotStyle->{Red,Blue}]

NOTE: One can also insert comments by creating a text box.  First, create an input box.  Then select it and format it as Text using the drop-down window menu.

1.3  Basic Calculator Operations

Mathematica uses the standard symbols +, -, *, /, ^, ! for addition, subtraction, multiplication, division, raising powers (exponents), and factorials, respectively.  Multiplication can also be performed by leaving a blank space between factors.  Powers can also be entered by using the palette menu to generate a superscript box (or else press CTRL+6) and fractions can be entered by generating a fraction box (from palette menu or pressing CTRL+/ ).

To generate numerical output in decimal form, use the command N[expr] or N[expr,d].  In most cases, N[expr] returns six digits of expr by default and may be in the form n.abcde *(10^m) (scientific notation), whereas N[expr,d] attempts to return d digits of expr.

NOTE: Mathematica can perform calculations to arbitrary precision and handle numbers that are arbitrarily large or small.

Here are some examples:

Pi

N[Pi]

N[Pi,200]

(6^(5^4))

1/300!

(* This command returns a decimal answer of the last output *)
N[%]

Example 1.1.  How close is (e^((Sqrt[163])π)) to being an integer?

Solution:

E^(Pi*Sqrt[163])

N[%,40]

We can rewrite this output in non-scientific notation by moving the decimal point 17 places to the right.  This shows that (e^((Sqrt[163])π)) is very close to being an integer.  Another option is to use the command Mod[n,m], which returns the remainder of n when divided by m, to obtain the fractional part of (e^((Sqrt[163])π)):

Mod[%,1]

1-%

1.4  Functions

There are two different ways to represent functions in Mathematica, depending on how they are to be used.  Consider the following example:

Example 1.2.  Enter the function f(x)=(((x^2)+x+2)/(x+1)) into Mathematica.

Solution:

Method 1:  Simply assign f the expression (((x^2)+x+2)/(x+1)), for example,

Clear[f,x] (* This clears the arguments f and x *)

f=(x^2+x+2)/(x+1)

To evaluate f(x) at x=10, we use the substitution command /. (slash-period) as follows:

f/.x->10

Warning: Recall that Mathematica reads f(x) as f multiplied by x; commas are considered delimiters.

f(10)

Method 2: An alternative way to explicitly represent f as a function of the argument x is to enter

Clear[f] 
	f[x_]:=(x^2+x+2)/(x+1)

Evaluating the command f[10] now tells Mathematica to compute f at x=10.

f[10]

More generally, the command f[{a,b,c,...}] evaluates f(x) for every value of x in the list {a,b,c,...}:

f[{-3,-2,-1,0,1,2,3}]

Here, Mathematica is warning us that it has encountered the undefined expression (1/0) in evaluating f(-1) by returning the message ComplexInfinity.

Remark: If there is no need to attach a label to the expression (((x^2)+x+2)/(x+1)), then we can directly enter this expression into Mathematica:

(((x^2)+x+2)/(x+1))/.x->10

(((x^2)+x+2)/(x+1))/.x->{-3,-2,-1,0,1,2,3}

Piece-wise functions can be defined using the command If[cond,p,q], which evaluates p if cond is true; otherwise, q is evaluated.

Example 1.3.  Enter the following piece-wise function into Mathematica:

f(x) ={({{tan (((π x)/4)),, if |x|<1;}, {x,, if |x|≥1.}})

Solution:

f[x_]:=If[Abs[x]<1,Tan[Pi*x/4],x]

1.5  Palettes

Mathematica allows us to enter commonly used mathematical expressions and commands from six different palettes.  Palettes are calculator pads containing buttons that can be clicked on to insert the desired expression or command into a command line.  These palettes can be found under the Palettes menu.  If the Basic Math Assistant Palette does not appear by default, then click on Palettes from the menu and select it.  One can also select more advanced math typesetting palettes such as the Basic Math Input and Algebraic Manipulate Palettes.

Example 1.4.  Enter (Sqrt[(3/(π^4))])into a notebook.

Solution:

Here is one set of instructions for entering this expression using the Basic Math Assistant Palette:

a) Click on the palette button (Sqrt[□]).
b) Click on (□/□).
c) Enter the number 3 into the highlighted top placeholder.

(Sqrt[(3/□)])

d) Press the TAB key to move the cursor to the bottom placeholder.
e) Click on (□^□).
f) To insert π  into the base position, click on the palette button for π.

(Sqrt[(3/(π^□))])

g) Press the TAB key to move the cursor to the superscript placeholder.
h) Enter the number 4.

(Sqrt[(3/(π^4))])

1.6  Solving Equations

Mathematica has a host of built-in commands to help the user solve equations and manipulate expressions.  The command Solve[lhs==rhs, var] solves the equation lhs==rhs (recall Mathematica's use of the double-equal sign) for the variable var.  For example, the command below solves the quadratic equation (x^2)-4=0 for x.

Solve[x^2-4==0,x]

A system of m equations in n unknowns can also be solved with using the same command, but formatted as Solve[{(Subscript[lhs, 1])==(Subscript[rhs, 1]),(Subscript[lhs, 2])==(Subscript[rhs, 2]),...,(Subscript[lhs, m])==(Subscript[rhs, m])},{(Subscript[x, 1]),(Subscript[x, 2]),...,(Subscript[x, n])}].  In situations where exact solutions cannot be obtained (e.g., certain polynomial equations of degree 5 or higher), numerical approximations can be obtained through the command NSolve[lhs==rhs,var].  Here are two examples:

Clear[x,y]
Solve[{2x-y==3,x+4y==-2},{x,y}]

NSolve[x^5-x+1==0,x]

There are many commands to algebraically manipulate expressions: Expand, Factor, Together, Apart, Cancel, Simplify, FullSimplify, TrigExpand, TrigFactor, TrigReduce, ExpToTrig, PowerExpand, and ComplexExpand.

Factor[x^2+4x-21]

NOTE: These commands can also be entered from the Algebraic Manipulation Palette; highlight the expression to be manipulated and click on the button corresponding to the command to be inserted.  The screen shot below demonstrates how to select the Factor command from the Algebraic Manipulate Palette to factor the highlighted expression (x^2)+4x-21.

Exercises

In Exercises 1 through 5, evaluate the expressions:
1. 103.41+20*76	2. (((5^2)+π)/(1+π))	 	3. (1/(1+(1/(1+(1/(4!))))))	 4. ((2.06*(10^9))/(0.99*(10^(-8))))		5. What is the remainder of 1998 divided by 13?

In Exercises 6 through 8,  enter the functions into Mathematica and evaluate each at x=1:
6. f(x)=2(x^3)-6(x^2)+x-5		7. g(x)=(((x^2)-1)/((x^2)+1))		8. h(x)=|(Sqrt[x])-3|

In Exercises  9 through 11, evaluate the functions at the given point using Mathematica:
9. f(x)=1001+(x^4) at x=25		10. 1+(Sqrt[x])+(x^(1/3))+(x^(1/4)) at x=π	11. 1+(1/(2+((((2x+1))^2)/(2+((((4x+1))^2)/2))))) at x=1

In Exercises 12 through 17, enter the expressions into Mathematica:

12. (80^(1/3))		13. ((1024^(1/5))/(2^(-3)))			14. ((Sqrt[125])^(1/3))
15. (Sqrt[((10(a^7)b)^(1/3))])	16. ((((((x^(-3))(y^4))/5)))^(-3))		17. (((((3(m^(1/6))(n^(1/3)))/(4(n^(-(2/3)))))))^2)

In Exercises 18 through 21, expand the expressions:

18. (x+1)(x-1) 		19. (x+y-2)(2x-3)		20. ((x^2)+x+1)(x-1)		21. ((x^3)+(x^2)+x+1)(x-1)

In Exercises 22 through 25, factor the expressions:

22. (x^3)-2(x^2)-3x		23. 4(x^(2/3))+8(x^(1/3))+3.6		24. 6+2x-3(x^3)-(x^4)		25. (x^5)-1

In Exercises 26 through 29, simplify the expressions using both of the commands Simplify and FullSimplify (the latter uses a wider variety of methods to simplify expressions).

26. (((x^2)+4x-12)/(3x-6))			27. ((((2/x)-3))/(1-(1/(x-1))))			28. (((x(1-2x)))^(-3/2))+(((1-2x))^(-1/2))		29. (((x^5)-1)/(x-1))

In Exercises 30 through 33, solve the equations for x (compare outputs using both the Solve and NSolve commands):

30. (x^2)-x+1=0		31. ((x(1-2x))^(-3/2))+(((1-2x))^(-1/2))=0		32. (x^3)-1=0		33. (Sqrt[1+(Sqrt[x+(Sqrt[(x^2)])])])=5

Chapter 2	Graphs of Functions,  Limits, and Continuity

2.1 Plotting Graphs

Students should read Chapter 1 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

2.1.1  Basic Plot

In this section, we will discuss how to plot graphs of functions using Mathematica and how to utilize its various plot options.  We will discuss in detail several options that will be useful in our study of calculus.  The basic syntax for plotting the graph of a function y=f(x) with x ranging in value from a to b is Plot[f,{x,a,b}]. On the other hand, Plot[{(Subscript[f, 1]),(Subscript[f, 2]),...,(Subscript[f, N])},{x,a,b}] plots the graphs of (Subscript[f, 1]),(Subscript[f, 2]),...,(Subscript[f, N]) on the same set of axes.

Example 2.1.  Plot the graph of  f(x)=(x^2)-3x+1 along the interval [-2,5].

Solution:

Plot[(x^2)-3x+1,{x,-2,5}]

Example 2.2.  Plot the graph of y=cos (3x) along the interval [-4,4].

Solution:

Plot[Cos[3x],{x,-4,4}]

Example 2.3.  Plot the graphs of the two functions given in Examples 2.1 and 2.2 prior on the same set of axes to show their points of intersection.

Solution:

Plot[{ (x^2)-3x+1,Cos[x]},{x,-3,6}]

Example 2.4.  Plot the graphs of f(x)=(((x^2)+x+1)/(x+1)) and g(x)=((sin (4x))/4) on the same set of axes.

Solution:

Plot[{(x^2+x+2)/(x+1),Sin[4x]/4},{x,-4,4}]

Note that the graph of y=(sin 4x)/4 is displayed poorly in output above since its range (from -1 to 1) is too small compared to the range of y=((x^2)+x+2)/(x+1).  We can zoom in using the PlotRange option. The syntax for PlotRange is PlotRange->{c,d} (the arrow is generated by entering a minus sign (-) followed by greater than sign) where [c,d] is the interval on the y-axis to be displayed.  More generally, PlotRange ->{{a,b},{c,d}}   specifies the interval [a, b] on the x-axis while [c,d] specifies the interval on the y-axis.

Plot[{(x^2+x+1)/(x+1),Sin[4x]/4},{x,-4,4},PlotRange->{-4,4}]

Example 2.5.    Plot the graphs of the following functions.
a)   f(x)=((x^2)/((x^2)-4))	b) f(x)=sin x +cos x	c)f(x)=x (e^x)+ln x 	d) f(x)=((x^2)/((x^2)+4))

Solution: We recall that the natural base e is entered as E or e (from the Basic Math Assistant Palette) and that ln x is Log[x]. Note also that sin x and cos x are to be entered as Sin[x] and Cos[x] (see Chapter 1 of this text for a discussion of Mathematica's notation).  We leave it to the reader to experiment with different intervals for the domain of each graph so as to capture its salient features.

a)

Plot[((x^(2 ))/(4-(x^2))),{x,-5,5}]

b)

Plot[Sin[x]+Cos[x],{x,-2Pi,2Pi}]

c)

Plot[x (E^x)-Log[x],{x,-3,3}]

NOTE:  The above graph needs to be read carefully. First of all, it is clear from the graph above that f(x)=x (e^x)-ln x tends to ∞ as x tends to 0.  It is also clear from the graph that f(x) tends to ∞ as x tends to ∞.  Note, however, that the graph suggests (incorrectly) that the domain is [0, ∞).  If we zoom in on the graph near x=0, then we see that the domain does NOT include the point x=0.

Plot[((x^2)/((x^2)+4)),{x,-5,5 }]

2.1.2  Plot Options

Next, we will introduce various options that can be specified within the Plot command.  To begin with, evaluating the command Options[Plot] displays the following options:

Options[Plot]

PlotStyle

PlotStyle is an option for Plot that specifies the style of lines or points to be plotted. Among other things, one can use this option to specify a color of the graph and the thickness of  the curve.  PlotStyle  should be followed by an arrow and then the option: PlotStyle -> {option}. For example, if we want to plot a graph colored in red, we evaluate

Plot[(x^2),{x,-3,3},PlotStyle->Red]

The next example shows how to use PlotStyle to specify two styles: a color and thickness.

Plot[(x^2),{x,-3,3}, PlotStyle->{ Blue, Thickness[0.02]}]

PlotStyle can also be used to specify options for two or more graphs.  Here are two examples to demonstrate this:

Plot[{(x^2),(x^3)-x-1},{x,-3,3},PlotStyle->{Green,Yellow }]

Plot[{(x^2),(x^3)-x-1},{x,-3,3},PlotStyle->{{Magenta,Thickness[0.01]},{Cyan,Thickness[0.001],Dashing[{0.01,0.01,0.01}]}}]

PlotRange

We have already used the PlotRange option in Section 2.1 of this text (see Example 2.4 prior).  This option specifies the range of y-values on the graph that should be plotted. As observed in the same example in Section 2.1, some points of a graph may not be plotted unless we specify the y-range of the plot. The option PlotRange -> All  includes all y-values corresponding to the specified values of x.  Here is an example.

Plot[(x^5)-2x-1,{x,-5,5}]

Plot[(x^5)-2x-1 ,{x,-5,5},PlotRange->All]

Axes

There are several options regarding axes of plots. We consider four of them.

1. Axes:    The specification Axes -> True  draws both axes, whereas  Axes -> False  draws no axes and Axes->{True,False} draws the x-axis only. An example of the last case  is given below.

Plot[ x Sin[3x],{x,-10,10},Axes->{True,False}]

2. AxesLabel:	The default specification AxesLabel -> None leaves the axes unlabeled.  On the other hand, AxesLabel -> expr  will only label the y-axis as expr and AxesLabel -> { "expr1", "expr2" } labels both the x-axis and y-axis as expr1 and expr2, respectively.  Examples of both cases are given below.

Plot[x Cos[x],{ x,-10,10},AxesLabel->y]

Plot[x Cos[x],{ x,-10,10},AxesLabel->{"x","y"}]

3.  AxisOrigin:	 The option AxesOrigin  specifies the location where the two axes should intersect. The default value given by AxesOrigin -> Automatic chooses the intersection point of the axes based on an internal (Mathematica) algorithm. It usually chooses (0,0). The option AxesOrigin -> {a,b}  allows the user to specify the intersection point as (a,b).

4.  AxesStyle:  This option specifies the style of the axes. Here is an example where we specify the thickness of the x-axis and color (blue) of the y-axis. We also use the AxesOrigin option.

Plot[x Cos[x],{ x,-10,10},AxesOrigin->{-10,10},
	AxesStyle->{ Blue,Thickness[0.01]},
	AxesLabel->{"x","y"}]

Frame

There are several options regarding the frame (border) of a plot. We show these options in the following examples:

Plot[x Cos[x],{ x,-10,10},Frame->True ]

Plot[x Cos[x],{ x,-10,10},Frame->True,FrameLabel->{"The graph of y = x cos x", "y-axis",None,None}]

Plot[x Cos[x] ,{ x,-10,10}, PlotStyle->Red,Frame->True, FrameLabel->{"The graph of  y = x cos x","y-axis",None,None},FrameStyle->{{Blue,Thickness[0.005]},{Yellow,Thickness[0.005]},{Green, Thickness[0.013]},{Orange} }]

We encourage the reader to experiment with this example by changing the color specifications to see which option controls which edge color of the frame.

Show

The command Show[graphics, options]  displays graphics (consisting of possibly many different graphics objects) using the options specified by options. Also Show[ plot1,plot2, ....] displays the graphics plot1, plot2, ... on one coordinate system.

plot1=Plot[Sin[x],{x,-Pi,Pi} ];

plot2=ListPlot[ {{0,0}, {Pi/2,1}, {Pi,0}}, PlotStyle->  {Red,PointSize[.02]}];

Show[plot1,plot2]

Here is an option we can use to identify the sine curve by inserting the expression y=sin x near its graph.

Show[plot1,plot2, 
 Epilog->Text["y=sin x",{2.7,1},{0,1}]]

Animation

Animate[expr, {t, a,b}] generates an animation of expr in which the parameter t varies from a to b. 
Animate[expr, {t, a,b, dt}] generates an animation of expr in which t varies from a to b in steps of dt. 
Animate[expr, {t,(Subscript[a, 1]),(Subscript[a, 2]), (Subscript[a, 3]),... ,(Subscript[a, n])}] generates an animation of expr in which t takes on the discrete set of values (Subscript[a, 1]), (Subscript[a, 2,])(Subscript[a, 3,])...,(Subscript[a, n]). 
Animate[expr, {t, a,b}, {s, c, d}, .... ] generates an animation of expr in which t varies from a to b,  s varies from c to d,  and so on.

Important Note: If you are reading the printed version of this publication, then you will not be able to view any of the animations generated from the Animate command in this chapter.  If you are reading the electronic version of this publication formatted as a Mathematica Notebook, then evaluate each Animate command to view the corresponding animation.  Just click on the arrow button to start the animation.  To control the animation just click at various points on the sliding bar or else manually drag the bar.

Example 2.6.  Analyze the effect of the shift f(x+a), f(x)+a,  f(b x) , and b f(x) for various values of a and b for the fucntion f(x)= cos x.

Solution:

f[x_]:=Cos[x]

Animate[Plot[{Cos[x],Cos[x+a]},{x,-2Pi,2Pi},PlotStyle->{Black ,Red},PlotRange->{-2,2}],{a,0,8 }]

Next, we will animate the graphs of f(x+a) (in red) and f(x)+a (in blue):

Animate[Plot[{Cos[x],Cos[x+a],Cos[x]+a},{x,-2Pi,2Pi},PlotStyle->{Black,Red,Blue},PlotRange->{-1,5}],{a,0,6 }]

Here is the animation for the graphs of f(b x) and b f(x).

Animate[Plot[{Cos[x],Cos[b*x],b*Cos[x]},{x,-2Pi,2Pi},PlotStyle->{Black , Red, Blue}],{b,0,8 }]

Here is an animation that shows all four shifts at once. We can fix as many parameters as we want (just click on their pause buttons) and analyze the behavior due to the remaining parameters.

Animate[Plot[{Cos[ x] ,Cos[x+a], Cos[x]+b,Cos[c x], d *Cos[x] },{x,0,10},
PlotStyle->{Black,Red, Blue, Green, Brown, Yellow},PlotRange->{-5,5}],
{a,0,5},{b,0,5}, {c,0,5},{d,0,5}]

Example 2.7.  Here is an animated example of a graph that shows the behavior of a general quadratic polynomial as we vary its coefficients.

Solution:

Animate[Plot[a (x^2)+b x+c,{x,-3,3},PlotRange->{-10,10}],{a,-3,3},{b,-3,3},{c,-3,3}]

We suggest that you pause two of the parameters and vary the third one manually to see the change in the location of the zeros, the vertex, the regions of concavity, and the regions on which the graph increases and decreases. Then make the necessary changes to redo this problem for polynomials of higher degree.

Contour Plot

To end our discussion on graphics, we now consider plotting graphs of equations in two variables.  Among such equations are the famous family of elliptic curves that arise in number theory: (y^2)=(x^3)+a x+b, where a and b are parameters. The command for graphing equations implicitly in two variables x and y is ContourPlot[eqn, {x,a,b},{y,c,d}], which displays the graph of eqn for which x varies from a to b and y varies from c to d.

Example 2.8.	Plot the graphs of curves given by the equation (y^2)=(x^3)+a x+b for various values of a and b.

Solution: First, we define a function f[x,a,b] to represent the right-hand side of the equation (y^2)=(x^3)+a x+b so that f is a function of x as well as a and b. We then plot the equation (y^2)=f[x,a,b], where we consider three different sets of values: a=1, b=1; a=-4, b=0; and a=-3, b=3.

f[x_,a_,b_]:=(x^3)+a x+b

ContourPlot[ (y^2)==f[x,1,1],{x,-10,10},{y,-10,10},Axes->True, Frame->False]

ContourPlot[ (y^2)==f[x,-4,0],{x,-10,10},{y,-10,10},Axes->True, Frame->False]

ContourPlot[ (y^2)==f[x,-3,3],{x,-10,10},{y,-10,10},Axes->True, Frame->False]

Discovery Exercise: Evaluate the following table and discuss which pararemeters produce curves that are familiar. Make sure to delete the semicolon at the end of the command.

Table[ContourPlot[ (y^2)==f[x,a,b],{x,-10,10},{y,-10,10},Axes->True, Frame->False]  ,{a,-4,4},{b,-3,3}];

Exercises

In Exercises 1 through 8, plot the graphs of the given functions on the specified interval:
1. f(x)=(x^2)+1 on [-5,5]			2. g(x)=(1/(x-2)) on [0,4]		
3. h(x)=((sin x)/x) on [-π,π]			4.  f(x)=(x^3)-5(x^2)+10 on  [-5,5]		
5. f(x)=(Sqrt[32-2(x^2)]) on  [-4,4] 		6. f(x)=x+(1/x)  for [-10,10]
7. f(x)=(x^3)-x+1 on [-3,3]		8. g(x)=((1-cos x)/x) on [-π,π]

9.  Plot the graphs of f(x)=x(x-3)(x+3) and g(x)=cos 2x  together on the same set of axes and over the interval [-20,20].  Use the PlotRange option to adjust the range of the viewing window so that their points of intersection are visible.

In Exercises 10 through 13,  plot the graphs of the given functions using at least one plot option discussed in this section.
NOTE: ln x is one of the built-in Mathematica functions and is entered as Log[x].   The logarithmic function (Subscript[log , a]) x is entered as Log[a,x].  For the natural base e you either type E or you can obtain e from the Basic Math Assistant Palette.
10. f(x)=(x^4)+2(x^3)+1 for   -3≤x≤3		11. f(x)=x ln x  for   0≤x≤4 
12. f(x)=1-(1/(x^3))+(1/x)      for  -20≤x≤20		13. f(x)=x (e^x) for -4≤x≤4

In Exercises 14 through 18, plot the graphs of the given pairs of functions on the same axes. Use the PlotStyle option to distinguish the graphs.
14. f(x)=(e^x) and g(x)=ln x	 		15. f(x)=((2x)/(x-5)) and g(x)=((x-5)/(2x))   
16. f(x)=   (x^2)-sin x   and   g(x)=(Sqrt[(x^4)+1])- (Sqrt[(x^2)+1])	
17. f(x)=3x+1 and g(x)=((x-1)/3)     		18. f(x)=((x+1)^(1/3))and g(x)=(((x-1))^3)

19. Let f(x)=((((x^2)-1))^(2/3)). 
a) Define f in Mathematica  as it appears above and plot its graph.
b) Rewrite f as f(x)=(((((x^2)-1))^2)^(1/3))plots its graph as it appears here. 
c) Explain why the graphs are not identical. Generalize this remark to general functions with rational exponents.

20. Let f(x)=((2c x-(x^2) )/(c^2)), c>0. 
a)  Graph f for various values of c.  (You may use the Animate command.)
b)  Use the graph in part a) to sketch the curve traced out by the vertices of the highest point as c varies. Can you guess what this curve is?

21.  Use the Animate command to plot the graph of f(x)  by varying the parameters a,b,c,d, and e for each of the following functions.   Discuss how each parameter affects the shape of the graph.
a)  f(x)=a (x^3)+b (x^2)+c x+d 
b)  f(x)=a (x^4)+b (x^3)+c (x^2)+d x +e

22. a) Use ContourPlot to plot the graph of the curve defined by the equation y ((y^2) - c) (y-d) = x (x-a) (x-b) for various values of a, b, c, d.  (Hint: You may want to define g[y,c,d] as the left hand side and f[x,a,b] as the right hand side and then use the command ContourPlot[f[x, a, b] == g[y, c, d], {x, -5, 5}, {y, -5, 5}, Frame -> False, Axes -> True].)
b)  For the parameters you selected in part a, at how many points is the slope of this curve equal to zero?  Estimate the x-coordinates of these points.

2.2	Limits

Students should read Chapter 2 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

2.2.1  Evaluating Limits

Limit[f,x->a,Direction->1] computes the limit as x as approaches a from the left (i.e., x increases to a).

Limit[f,x->a,Direction->-1] computes the limit as x approaches a from the right (i.e., x decreases to a).

Limit[f,x->a] finds the limiting value of f as x approaches a.

NOTE: Mathematica will use the right-hand limit when evaluating Limit.  If the limit does not exist, then Mathematica will attempt to explain why or else return the limit expression unevaluated if it has insufficient information about the function.

Example 2.9.  Evaluate (Underscript[lim , x->1])((((x^2)+x+2)/(x+1))).

Solution: Here is a table of values of the function f(x)=(((x^2)+x+2)/(x+1)) when x is sufficiently close to 1.

f[x_]:=(((x^2)+x+2)/(x+1))

(*From the left*)
Table[{x,f[x]},{x,0.8,0.99,0.01}]//TableForm

(*From the right*)
Table[{x,f[x]},{x,1.2,1.01,-0.01}]//TableForm

From the tables, it is reasonable to expect that the limit is 2. Here is the graph of the function together with the point (1,2).

plot1=Plot[(x^2+x+2)/(x+1),{x,-1,2},PlotRange->{0,3}];
plot2= Graphics[{Green, PointSize[Large],Point[{1,2}] } ];
plot3=Graphics[{Red, Line[{{1,0},{1,2},{0,2}}]}];
Show[plot1, plot2, plot3]

Evaluating the limit confirms this:

Limit[(x^2+x+2)/(x+1),x->1]

Example 2.10.  The height of a projectile, fired in the air with initial velocity 32 ft/s, is given by y(t)=-16(t^2)+64t+3. Find the average velocity of the projectile over the interval [1,t] for various values of t.  Then find the instantaneous velocity at t=1.

Solution: We define

y[t_]=-16(t^2)+64t+3
v[t_]=((y[t]-y[1])/(t-1))

tt={2,1.5, 1.01,1.001,1.0001,1.00001};
Table[{tt[[k]],v[tt[[k]]]},{k,1,Length[tt]}]//TableForm

Here tt is the list of values for t and tt[[k]] refers to the kth element in the list tt (see Chapter 1 of this text for an explanation of lists).  Also, Length[t] gives the number of elements in the list tt, which is 6 for our example.

The above table clearly suggests that the instantaneous velocity at t=1 is 32 ft/s. The graph below also verifies this.

plot1=Plot[v[t],{t,0,2}, PlotRange->{0,50}];
 y=Simplify[v[t]]/.t-> 1;
plot2= Graphics[{ PointSize[Large],Point[{1,y}] } ];
plot3=Graphics[{Red, Line[{{1,0},{1,y},{0,y}}]}];

Show[plot1, plot2, plot3]

Example 2.11.  Show that f(x)=cos(1/x) does not have a limiting value as x approaches 0.

Solution: We define

f[x_]:=Cos[1/x]
f[{0.1,.05,0.001,.0001,.000001}]

These values suggest that the limit does NOT exist. To make this clear, we consider the following two tables.  The first table uses values of the form x=2/(2n+1)π, where n is a positive integer, while the second table uses x=1/(2n+1)π.  Each of these sets of values for x approach 0 as n->∞.

t1=Table[(2./(Pi(2n+1))),{n,1,100,10}];
f[t1]

t2=Table[(1./(Pi(2n+1))),{n,1,100,10}];
f[t2]

The first table indicates that the values of f(x) approach 0, while the second table indicates the values approach -1.  Recall that if the limit exists, then it must be unique.  Thus, our limit does not exist because the values of f do not converge to a single value.  Next, we analyze the graph of the function.

Plot[f[x],{x,-1,1}]

This indicates that there is too much oscillation around x=0.  Let us try zooming in around this point.

Plot[Cos[1/x],{x,-0.1,0.1}]

Note how zooming in on this graph does not help. This indicates that the limit does not exist.

Example 2.12. Consider the function f(x)=(((2^(1/x))-(2^(-1/x)))/((2^(1/x))+(2^(-1/x)))).  Find (lim_(x->0))f(x).

Solution:

Limit[(((2^(1/x))-(2^(-1/x)))/((2^(1/x))+(2^(1/x)))),x->0]

It may appear that the limit is (1/2), but the simplified form of f(x) (using the Simplify command) shows this not to be the case.  Instead we shall consider one-sided limits.

Simplify[(((2^(1/x))-(2^(-1/x)))/((2^(1/x))+(2^(1/x))))]

Limit[(((2^(1/x))-(2^(-1/x)))/((2^(1/x))+(2^(1/x)))),x->0,Direction->1]
Limit[(((2^(1/x))-(2^(-1/x)))/((2^(1/x))+(2^(1/x)))),x->0,Direction->-1]

Since the left- and right-hand limits are not the same, we conclude that the limit does not exist.

Plot[(((2^(1/x))-(2^(-1/x)))/((2^(1/x))+(2^(1/x)))),{x,-1,1}, PlotRange->{-30,1}]

NOTE: One needs to be careful when using Mathematica to find limits. If you are not certain that the limit exists, use one-sided limits:

Example 2.13.  Evaluate (Underscript[lim , x->(SuperPlus[5])])((|x-5|)/(x-5)).

Solution:

Limit[Abs[x-5]/(x-5),x->5,Direction->-1]

Note that Mathematica's convention for right-hand limits is "going in the negative direction." Thus, the standard notation (Underscript[lim , x->(SuperPlus[5])]) should be evaluated as Limit[f[x],x->5, Direction-> -1].  A similar remark applies to the left-hand limit.

Again, we can check the answer by plotting the graph of the function:

Plot[Abs[x-5]/(x-5),{x,3,7}]

Warning: This plot does not show the true graph of f(x) near x=5.  It may appear that f is continuous at x=5 because of the vertical line there but this is not the case since f is undefined at x=5 and its one-sided limits do not agree:

Abs[x-5]/(x-5)/.x->5
Limit[Abs[x-5]/(x-5),x->5,Direction->1]
Limit[Abs[x-5]/(x-5),x->5,Direction->-1]

Below is the true graph of f, which shows the (non-removable) discontinuity at x=5.

2.2.2  Limits Involving Trigonometric Functions

For trigonometric functions, Mathematica uses the same traditional notation in calculus except that the first letter of the trigonometric function must be capitalized. Thus, Sin[x] is Mathematica's notation for sin x (see Appendix A of this text for a description of notational differences).

Example 2.14.  Evaluate (Underscript[lim , x->0])((sin (4x))/x).

Solution:

Limit[Sin[4x]/x,x->0]

Let us check the answer by graphing the function up close in the neighborhood of x=0:

Plot[Sin[4x]/x,{x,-1,1}]

Example 2.15.  Evaluate (Underscript[lim , t->0])((sin t)/(|t|)).

Solution: We will consider both the left- and right-hand limits.

Limit[(( Sin[t])/(Abs[t])),t->0, Direction->-1]

Limit[(( Sin[t])/(Abs[t])),t->0, Direction->1]

Thus, the limit does not exist. This can be clearly seen from the graph of the function below.

Plot[((Sin[x])/(Abs[x])), {x,-2Pi,2Pi}]

Example 2.16. Find
a)	 (lim_(x->0 ))((cos x-1)/(sin x)) 		b) 	(lim_(x->0 ))tan x cos(sin 1/x)

Solution:

a=Limit[(Cos[x]-1)/Sin[x],x->0]

b=Limit[Tan[x] Cos[Sin[1/x]],x->0]

NOTE: In your textbook, it is proven that (lim_(x->0 ))((cos x-1)/x)=0 and (lim_(x->0 ))((sin x)/x)=1. Writing ((cos x-1)/(sin x))=(((cos x-1)/(x  )))/(((sin x)/x)), we see that the answer for part a) is valid by applying the quotient rule for limits. For the second limit in part b), we note that -1≤cos (sin(1/x))≤1and hence -|tan x|≤tan x cos (sin (1/x))≤|tan x|.  Since (lim_(x->0))tan x=(lim_(x->0))(-tan x)=0 we call upon the Squeeze Theorem to conclude that (lim_(x->0))tan x cos (sin (1/x))=0.

The following graphs verify both answers.

Plot[((Cos[x]-1)/(Sin[x])), {x,-2Pi, 2Pi}]

Plot[Tan[x]*Cos[Sin[1/x]],{x, -2Pi,2 Pi}]

Example 2.17.  Find  (lim_(x->c ))((cos x-cos c)/(x-c)) for  values of c=0, π/6, π/4, π/3, π/2.

Solution: We  will use the substitution command /. to evaluate the limit for different values of c.

Limit[((Cos[x]-Cos[c])/(x-c)), x->c]/. c->{0,Pi/6, Pi/4, Pi/3, Pi/2}

Can you guess a general formula for the answer in terms of c?  (Hint: What trigonometric function takes on these values?)

Example 2.18. Find  (lim_(x->0 ))((cos (m x)-1)/(x^2))for various values of m.  Then make a general statement about this limit and prove your assertion.

Solution: Here is a table of limits for integer values of m ranging from 1 to 10.

Table[Limit[((Cos[m x]-1)/(x^2)), x->0], {m, 1, 10}]

A reasonable guess at a general formula for the answer would be (lim_(x->0))(cos m x-1)/(x^2)=-(m^2)/2.  We can check this with values of m ranging from 10 to 20.

Table[{Limit[((Cos[m x]-1)/(x^2)), x->0],-m^2/2}, {m, 10, 20}]

For a mathematical proof, first take m=1 and plot the graph

Plot[((Cos[x]-1)/(x^2)),{x,-Pi,Pi}, AxesOrigin->{0,0}]

The graph above confirms that the limit is -1/2.

For the general case, let t=m x so that (x^2)=((t^2)/(m^2)).  Then note that x-> 0  if and only if t->0.  Thus, the limit can be evaluated in terms of t as

(lim_(x->0))((cos m x-1)/(x^2))=(lim_(t->0))((cos t-1)/((t^2)/(m^2)))=(m^2)(lim_(t->0))((cos t-1)/(t^2))=-((m^2)/2).

2.2.3 Limits Involving Infinity

Example 2.19.  Evaluate (Underscript[lim , x->∞])(3x -2)/(Sqrt[2(x^2)+1]) and  (Underscript[lim , x->-∞])(3x -2)/(Sqrt[2(x^2)+1]).

Solution:

Limit[(3x-2)/Sqrt[2x^2+1],x->Infinity]

N[%]

Limit[(3x-2)/Sqrt[2x^2+1],x->-Infinity]

Observe how the two limits differ. The following graph confirms this.

Plot[(3x-2)/Sqrt[2x^2+1], {x,-30,30}]

NOTE: Can you explain the cusp on the graph near x=0?

Example 2.20.  Evaluate (Underscript[lim , x->(SuperMinus[2])])((Sqrt[4-(x^2)])/(x-2)).

Solution:

Limit[Sqrt[4-x^2]/(x-2),x->2,Direction->1]

We plot the function over two different ranges to visually understand why the answer is -∞.  Notice how the first range fails to show this.

Plot[((Sqrt[4-x^2])/(x-2)),{x,1,3}]

Plot[((Sqrt[4-x^2])/(x-2)),{x,1,3},PlotRange->{-100,10}]

NOTE: The plot domain is specified to be [1,3], but observe that this function is undefined for values of x greater than 2 because this results in taking the square root of a negative number.

Example 2.21.  Evaluate (Underscript[lim , x->∞])sin x.

Solution:

Limit[Sin[x],x->Infinity]

Here, Mathematica is telling us that the limit does not exist by returning the range of values for sin x as x approaches infinity.

Example 2.22. Find  (lim_(x->∞ ))((sin x)/x) .

Solution:

Limit[((Sin[x])/x), x->Infinity]

We can verify this limit by using the Squeeze Theorem.  In our case, we take f(x)=-1/|x|, g(x)=((sin x  )/x)and h(x)=1/|x|.  Then f(x)≤g(x)≤h(x) (recall that -1≤sin x≤1 for all x).

Plot[{-1/Abs[x], Sin[x]/x,1/Abs[x]}, {x,0,30}, PlotStyle->{Red,Green,  Blue}]

Since 1/|x| and -1/|x| both approach 0 as x->∞, we conclude that (sin x)/x approaches zero as well.

Example 2.23.	Evaluate (lim_(x->∞))(((e^x)/(x^n))), where n is any integer.

Solution:

Table[Limit[E^x/(x^n), x-> Infinity], {n, 1, 200, 10}]

This table suggests that the limit is infinity. We confirm this with Mathematica:

Limit[((E^x)/(x^n)),x-> ∞]

NOTE: This example reveals that exponential functions grow more quickly than polynomial functions.

Example 2.24.  Evaluate 	(lim_(x->(SuperPlus[1])))((1/(ln x))-(1/(x-1))).

Solution:

Limit[(1/Log[x])-(1/(x-1)),x->1,Direction->1]

Again, we can graph the function near  x=1 to visually understand why the answer is 1/2 (we leave this to the student).  Note, however, that this example shows that 1/ln x and 1/(x-1) both grow to ∞ at the same rate as x->(SuperPlus[1]).

Example 2.25. Let  f(x)=(((x^n)-1)/((x^m)-1)).  Evaluate (Subscript[limit, x->1])f(x) by substituting in various values of m and n.

Solution:

Table[Limit[((x^n)-1)/((x^m)-1), x->1],{m,1,10},{n,1,10}]//TableForm

Can you guess a formula for (Subscript[limit, x->1])f(x) in terms of m and n?  Enter the command Limit[((x^n)-1)/((x^m)-1),x->1] into an input box and evaluate it to verify your conjecture.

Let us end this section with an example where the Limit command is used to evaluate the derivative of a function (in anticipation of commands introduced in the next chapter for computing derivatives).

By definition, the derivative of a function f at x (i.e., the slope of its tangent line at x) is

f '(x)=(Underscript[lim , Δ x->0])((f(x+Δ x)-f(x))/(Δ x)).

Example 2.26.  Find the derivative of f(x) =(1/x) according to the limit definition.

Solution: We first examine the derivative by tabulating values of the difference quotient, ((f(x+Δ x)-f(x))/(Δ x)), for  some arbitrarily chosen values of Δ x:

f[x_]:=1/x
delta={0.1,0.01,.0001,.00001,.000001,.00000001};
Table[{delta[[k]],Simplify[((f[x+delta[[k]]]-f[x])/(delta[[k]]))]},{k,1,Length[delta]}]//TableForm

This table suggests that f'(x)=-1/(x^2) in the limit as Δ x->0.  We confirm this with Mathematica:

Limit[(f[x+Deltax]-f[x])/Deltax,Deltax->0]

Exercises

In Exercises 1 through 8, compute the limits:
1. (Underscript[lim , x->1])(((x^2)-1)/(x-1))		2. (Underscript[lim , x->-5])(100/(x+5))		3.(Underscript[lim , x->∞])((1+x+(x^2))/(((x^10)-x)^(1/3)))	4. (Underscript[lim , x->0]) ((sin x)/x)	
5. (Underscript[lim , x->0]) ((sin 5x)/(3x))  	6. (Underscript[lim , x->0]) ((1-cos x)/(4x))  	7. (Underscript[lim , x->3]) (((x^3)-27)/((x^2)-9))  	8.  (Underscript[lim , x->-∞]) (((x^3)-27)/((x^2)-6))

In Exercises 9 through 13,  evaluate each of the limits. Verify your answers by plotting the graph of each function in the neighborhood of the limit point. 
9. (lim_(x-> 2))(((2x-1)/(4-3x)))			10. (lim_(x->(SuperPlus[0])))(((1-ln x)/(e^(1/x ))) )		11. (lim_(x->(SuperPlus[0])))((1/x)-ln (x^( )) )		
12. (lim_(x→(SuperMinus[((π/2))])))  ( sec 3x cos 5x) 	13.(lim_(x-> 0))( sin  x)cos((1/x))

14. Use various values of a to find the following limits.  Confirm your answers by plotting the graph of each function corresponding to your chosen values for a.  Make a conjecture for a general formula.  Then verify your conjecture by using Mathematica to evaluate the limits but keeping the constant a  unassigned.
a)  (Underscript[lim , x->a]) (((x^3)-(a^3))/(x-a))		b)   (Underscript[lim , x->1]) (((x^3)-a (x^2)+a x-1)/(x-1))

15. Consider the quadratic function f(x)=a (x^2)-x+1.  Plot the graph of f using small values of a.  What do you observe about the roots of f? What is the limit of the roots of f as a-> 0?  Hint: Use the command Animate[Plot[a (x^2)-x+1,{x,0,50},PlotRange->{-50,50}], {a, 0, .1, .01}]  to help you analyze the root and then change the values of a as well as the plot domain. Then use the quadratic formula to prove your assertion.  NOTE: One can also use the Solve or Roots commands to determine the roots of f.

2.3 Continuity

Students should read Section 2.4 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

Recall that a function is continuous at x=a if and only if (lim_(x->a))f(x)=f(a).  Graphically, this means that there is no break (or jump) in the graph of f at the point (a, f(a)). It is not possible to indicate this discontinuity using computer graphics for the situation where the limit exists and the function is defined at a but the limit is not equal to f(a).  For other cases of discontinuity, computer graphics are very helpful.

To verify if a given function is continuous at a point, we evaluate its limit there and check if this limit is equal to the value of the function.

Example 2.27. Show that the function f(x)=(x^3)-1 is continuous everywhere.

Solution: We could draw the graph and observe this fact. On the other hand, we can get Mathematica to check continuity:

f[x_]:=(x^3)-1
Limit[f[x], x-> c]==f[c]

This means that (lim_(x-> c))f(x)=f(c) and hence f is continuous everywhere.

Example 2.28.  Find points of discontinuity for each of the following functions:
a) Let  f(x)= {({{(((x^2)-1)/(x-1)), if x≠1}, {2,     if x=1.}}).
b) Let  g(x)= {({{(((x^2)-1)/(x-1)), if x≠1}, {6,     if x=1.}}).

Solution: The command If[cond, true, false] evaluates true if cond is satisfied and gives false if cond  is not satisfied. This command can be used to define piece-wise functions such as those in this example.

a) We first check continuity of f at x=1.

f[x_]:=If[x≠1, (((x^2)-1)/(x-1)),2]

Limit[f[x], x->1]==f[1]

Hence, the function is continuous at x=1.  For continuity at other points, we observe that the rational function (((x^2)- 1 )/(x-1)) simplifies to x+1 in this case (factor the numerator!)  and thus is continuous at any point except x=1.  Thus, f is continuous everywhere. We can also confirm this by examining the graph of f below.

Plot[f[x], {x,-6,6}]

b) As in part a, we first consider continuity of g at x=1.

g[x_]:=If[x≠1, (((x^2)-1)/(x-1)),6]

Limit[g[x], x->1]==g[1]

Thus, g is NOT continuous at x=1. For continuity at other points, we again observe that the rational function (((x^2)- 1 )/(x-1))=x+1 and thus is continuous for x≠1.

Caution: The plot of the graph of g given below indicates (incorrectly) that g is continuous everywhere! Care must be taken when examining Mathematica plots to draw conclusions about continuity.

Plot[g[x], {x,-6,6}]

Example 2.29. 		 Let  f(x)={({{2x+c,            if x≥2}, {(x^2)+c x -1,  if x<2.}})  
For what values of c is f continuous over its entire domain?

Solution: For x>2, we have f(x)=2x+c. Hence, f is continuous on the interval (2,∞) since the interval is open.  For x<2, f(x)=(x^2)+c x -1 . Thus, f is continuous on (-∞,2) for the same reason.  For f to be continuous at x=2, we must have (lim_(x->2))f(x)=f(2).  But the limit exists if and only if

(lim_(x->(SuperMinus[2])))f(x)=(lim_(x->(SuperPlus[2])))f(x)

Note that (lim_(x->(SuperPlus[2])))f(x)=4 +c=f(2). Thus, it suffices to find all values of c for which the left-hand limit and the right-hand limit are equal. This can be done using Mathematica's Solve command.

Clear[c,f]
f[x_]:=If[x<2, (x^2)+c x-1,2x+c]

lhs= Limit[f[x], x->2, Direction->1]
rhs=Limit[f[x], x->2, Direction->-1]

Solve[lhs==rhs  ,c]

Thus, f is continuous if c=1. We confirm this by plotting the graph of f corresponding to this c value.

Plot[f[x]/.c->1, {x, -5,7}]

Example 2.30. 	Let  f(x)={({{sin((1/x)), if x≠0}, {0,            if x=0}}).  Prove that for any number k between -1 and 1 there exists a value for c such that f(c)=k.

NOTE: Observe that f is not continuous at x=0 so the converse of the Intermediate Value Theorem does not hold.

Solution: For k=0, we choose c=0 so that f(0)=0.  For any nonzero k between -1 and 1, define y=(sin^(-1)) k (using the principal domain of the sine function) and let c=1/y. Then f(c)=sin (1/c)=sin y=k. The  graph of f following shows that there are in fact infinitely many choices for c.

f[x_]:=Sin[1/x]
Plot[f[x], {x,-Pi,Pi}]

Exercises

1.   Let   f(x)={({{(e^x), if x≤0}, {ln x,if x>0}}).

a)  Graph the above function and discuss the type of discontiniuty at x=0.

b)   Repeat part a. for the function

f(x)={({{cos(((π x)/2)), if |x|≤1}, {|x-1|,if |x|>1}}).

2. Find values for c in which f (defined below) is continuous over its entire domain:

f(x)={({{ (x^2)+c, x<1,}, {c (e^x),    x≥1}})

Plot the graph of f corresponding to these c values.

3. Let

f(x)={({{x+1, if |x|≤2}, {(x^2)-c, if |x|>2}}).

a)  For what value(s) of c is the function  continuous at x=2? With this choice of c does f have a discontinuity at any other point? Plot the graph of the function.

b)  For what value(s) of c is the function  continuous at x=-2? With this choice of c does f have a discontinuity at any other point? Plot the graph of the function.

4. Find values of a and b such that the function f is continuous everywhere where f(x)={({{2a x +b, x<-5}, {6b, -5≤ x<1
 3, x≥ 1}})  .  HINT: Solve first for b by equating the second and third expressions for f.

Chapter 3 	Differentiation

3.1   The Derivative

Students should read Sections 3.1-3.5 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

3.1.1  Slope of Tangent

The derivative is one of the most fundamental concepts in calculus.  Its pointwise definition is given by

f' (a)=(lim_(h->0))(( f(h+a)-f(a))/h)

where geometrically f'(a) is the slope of the line tangent to the graph of f(x) at x=a (provided the limit exists).  We can view this graphically in the illustration below, where the tangent line (shown in blue) is viewed as a limit of secant lines (one shown in red) as h->0.

Example 3.1. Calculate the derivative of f(x)=((x^2)/3) at x= 1 using the pointwise definition of a derivative.

Solution: We first use the Table command to tabulate slopes of secant lines passing through the points at  a=1 and a+h=1+h by choosing arbitrarily small values for h (taken as reciprocal powers of 10):

f[x_]=x^2/3;
a=1;
h=10^(-n);
TableForm[N[Table[{h,((f[a+h]-f[a])/h)},{n,1,5}]]]

Note our use of the TableForm command, which displays a list as an array of rectangular cells.  From the table output, we  infer that f'(1)=2/3.  A more rigorous approach is to algebraically simplify the difference quotient,((f(a+h)-f(a))/h):

Clear[h]
Simplify[((f[a+h]-f[a])/h)]

It is now clear  that ((f(a+h)-f(a))/h)->(2/3)as h->0.  This can be checked using Mathematica's Limit command:

Limit[((f[a+h]-f[a])/h),h->0]

Below is a plot of the graph of f(x) (in black) and its corresponding tangent line (in blue), which also confirms our answer:

Plot[{f[x],f'[a](x-a)+f[a]},{x,-2,2},PlotStyle->{Black,Blue}]

NOTE: Recall that the tangent line of f(x) at x=a is given by the equation y=f'(a)(x-a)+f(a).

ANIMATION: Evaluate the following inputs to see animations of the secant lines approach the tangent line (from the right and left).

Important Note: If you are reading the printed version of this publication, then you will not be able to view any of the animations generated from the Animate command in this chapter.  If you are reading the electronic version of this publication formatted as a Mathematica Notebook, then evaluate each Animate command to view the corresponding animation.  Just click on the arrow button to start the animation.  To control the animation just click at various points on the sliding bar or else manually drag the bar.

(* From the right *)
fa1[x_]:=x^2/3;
a1=1;
Animate[Plot[{fa1[x],fa1'[a1](x-a1)+fa1[a1],(fa1[a1+h]-fa1[a1])/h*(x-a1)+fa1[a1]},{x,0,2},PlotStyle->{Black,Blue,Red}],{h,1.5,0.1,-0.05}]

(* From the left *)
fa1[x_]:=x^2/3;a1=1;
Animate[Plot[{fa1[x],fa1'[a1](x-a1)+fa1[a1],(fa1[a1+h]-fa1[a1])/h*(x-a1)+fa1[a1]},{x,0,2},PlotStyle->{Black,Blue,Red}], {h,-1.0,-0.1,0.05}]

3.1.2  Derivative as a Function

The derivative is best thought of as a slope function, one that gives the slope of the tangent line at any point on the graph of f(x) where this slope exists:

f' (x)=(lim_(h->0))(( f(x+h)-f(x))/h).

Example 3.2. Compute the derivative of f(x)=sin x using the limit definition.

Solution: We first simplify the corresponding difference quotient to obtain

Clear[h]
f[x_]=Sin[x];
Simplify[(f[x+h]-f[x])/h]

Here, it is not clear what the limit of the difference quotient is as h->0.  To anticipate the answer for the derivative without algebraic manipulation, we first note that since sin x is periodic, so should its derivative be.  A plot of the difference quotient (as a function of x) for several arbitrarily small values of h reveals the derivative to be cos x.  Students should recognize from trigonometry that the graph of cos x is merely a left horizontal translation of sin x by (π/2).

plot1=Plot[{f[x],Cos[x]},{x,-Pi,Pi},PlotStyle->{Black,Blue}]

Clear[h]
plot2=Plot[Evaluate[Table[(f[x+h]-f[x])/h,{h,0.1,0.7,0.3}]],{x,-Pi,Pi},PlotStyle->Red]

Show[plot1,plot2]

Of course, there are a number of methods to compute the derivative directly in Mathematica.   One method is to evaluate the command D[f,x]  for a function f defined with respect to the variable x.  A second method is to merely evaluate the expression f'[x] using the traditional prime (apostrophe symbol) notation.  A third method is to use the command  (∂_□) □.  We shall only discuss the first two methods since the third method is usually reserved for derivatives of functions depending on more than one variable, a topic that is treated in the third volume of this publication.

Example 3.3. Compute the derivative of sin ((x^2)) and evaluate it at x= (Sqrt[(π/4)]).

Solution:

Method 1:

D[Sin[x^2],x]
D[Sin[x^2],x]/.x->Sqrt[Pi/4]

NOTE: Recall the substitution command /.x->a was discussed in an earlier section.

Method 2:

f[x_]=Sin[x^2]
f'[x]
f'[Sqrt[Pi/4]]

Warning: Observe that the derivative of sin ((x^2)) is NOT cos ((x^2)) but 2x cos ((x^2)).  This is because sin ((x^2)) is a composite functsion.  A rule for differentiating composite functions, known as as the Chain Rule, is discussed in ection 3.7 of Rogawski's Calculus.

Example 3.4. Compute the derivative of f(x)={({{((sin x)/x), if x≠0}, {0, if x=0}}).

Solution: To define functions described by two different formulas over separate domains, we employ Mathematica's If[expr, p, q] command:

f[x_]=If[x≠0,Sin[x]/x,0]

f'[x]

NOTE: It is clear for x≠0 that the derivative is -((sin x)/(x^2)) + ((cos x)/x) as a result of the Quotient Rule.  For x=0, Mathematica's answer that f'(0)=0 is actually incorrect!  Note that the fact that f(0)=0 does not mean that f is a constant. One cannot differentiate a formula that is valid at only a single point; it is also necessary to understand how the function behaves in a neighborhood of this point.

A plot of the graph of f(x) reveals that it is discontinuous at x=0, that is, (lim_(x->0))f(x)≠f(0), and thus not differentiable there.

Plot[f[x],{x,-3Pi,3Pi}]

Observe that the point f(0)=0 is not distinguished in the Mathematica plot above so that the (removable) discontinuity is detected only by examining the behavior of f around x=0 (the true graph of f is shown following).

In particular, f(x)->1 as x->0.  We confirm this with Mathematica.

Limit[f[x],x->0]

Of course, it is also possible to compute f'(0) directly from the limit definition.  Here, the difference quotient behaves as ((sin h)/(h^2)) as the output below shows.  Since its limit does not exist as h->0, we conclude that f'(0) is undefined.

Simplify[(f[0+h]-f[0])/h]
Limit[(f[0+h]-f[0])/h,h->0]

NOTE: The discontinuity of f at x=0 can be removed by redefining it there to be f(0)=1.  What is f'(0) in this case?

Example 3.5  Find the equation of the tangent line to the graph of f(x) = (Sqrt[x+1]) at  x = 2.

Solution:  Remember that the tangent line to a function f(x) at x = a  is L(x) = f(a) + f '(a) (x-- a). Hear  a = 2:

Clear[f,L]
f[x_] = (Sqrt[x + 1])
L[x_] = f[2] + f'[2](x - 2)

To see that L(x) is indeed the desired tangent line, we will plot f and L together.

Plot[{f[x], L[x]},{x,0,4}]

Example 3.6. Find an equation of the line passing through the point P(2,-3) and tangent to the graph of f(x)=(x^2)+1.

Solution: Let us refer to Q(a,f(a)) as the point of tangency for our desired tangent line.  To determine Q, we compute the slope of our desired tangent line from two different perspectives:

1. Slope of line segment  PQ:

Clear[a]
f[x_]=x^2+1
m=(f[a]-(-3))/(a-2)

2. Derivative of f(x) at x=a:

f[x_]=x^2+1
f'[a]

Equating the two formulas for slope above and solving for a yields

Solve[m==f'[a],a]
N[%]

Since there are two valid solutions for a, we  have in fact found two such tangent lines.  Their equations are given by

Clear[y1,y2]
y1[x_]=Simplify[f'[a](x-a)+f[a]/.a->2 (1-(Sqrt[2]))]
y2[x_]=Simplify[f'[a](x-a)+f[a]/.a->2 (1+(Sqrt[2]))]

Plotting these tangent lines together with the graph of f(x) confirms that our solution is correct:

Plot[{f[x],y1[x],y2[x]},{x,-6,6},PlotRange->{-10,40},PlotStyle->{Black, Blue,Blue}]

NOTE: How would the solution change if we move the given point in the problem to P(2,5)?  Or P(2,10)?

Exercises

In Exercises 1 through 3, compute the derivatives of the given functions:
1.  f(x)= 3(x^2)+1	  2.  g(x)=(1/(x^3))		3.  h(x)=((sin x)/(cos x))

In Exercises 4 and 5, evaluate the derivatives of the given functions at the specified values of x:
4.  f(x)=(x-1)(x+1) at x=1		5.  g(x)=(((Sqrt[x])+1)/((Sqrt[x])-1)) at x=9

In Exercises 6 and 7, compute the derivatives of the given functions:
6.  f(x)=|x+3| 		7.  g(x)=|(x^2)-4| 
Hint: Recall the absolute value function: |x|={({{x, if x ≥0}, {-x, if x <0}}).  Use the If command to define these absolute functions (see Example 3.4).  Note that Mathematica does have a built-in Abs[x] command for defining the absolute value of x, but Mathematica treats Abs[x] as a complex function; thus its derivative Abs'[x] is NOT defined.  The real derivative of Abs[x] for real values of x can still be found using the numerical derivative ND command but we shall not discuss it here.

8.  Find an equation of the line tangent to the graph of x-(y^2)=0 at the point P(9,-3).

9.  Find an equation of the line passing through the point P(2,-3) and tangent to the graph of y=(x^2).

3.2.	Higher-Order Derivatives

Students should read Section 3.5 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

Suppose one is interested in securing higher order derivatives of a function.  Reasons for doing so include applications to maximum and minimum values, points of inflection, and physical applications such as velocity and acceleration and jerk, which all fit into such a context.

Example 3.6. Compute the first eight derivatives of f(x)=sin x.  What is the 255th derivative of f?

Solution: Here are the first eight derivative of f:

f[x_]=Sin[x];
TableForm[Table[{n,D[f[x],{x,n}]},{n,1,8}]]

We observe from the output that the higher-order derivatives of f are periodic modulo 4, which means they repeat every four derivatives. Since 255 has remainder 3 when divided by 4, it follows that (f^((255)))(x)=(f^((3)))(x)=-cos x.  Of course, Mathematica can compute this derivative directly (see  output below), but the pattern above gives us a more in-depth understanding of the higher-order derivatives of sin x.

D[f[x],{x,255}]

Example 3.7. Compute the first three derivatives of f(x)=x cos x .

Solution: We use the command D[f,{x,n}] to compute the nth derivative of f.  Here, we set n=1, 2, 3.

f[x_]=x*Cos[x]

D[f[x],x]

D[f[x],{x,2}]

D[f[x],{x,3}]

A quicker way to generate a list of higher-order derivatives is to use the Table command.  For example, here is a list of the first five derivatives of f:

Table[D[f[x],{x,n}],{n,1,5}]

Discovery Exercise: Find a formula for the nth derivative of f based on the pattern above.   Can you prove your claim using mathematical induction?  What is the 100th derivative of f in this case?   Check your answer using Mathematica.

Exercises

1. Let f(x)=1/x.
a) Compute the first five higher-order derivatives of f.
b) What is the 10th derivative of f?
c) Obtain a general formula for the nth derivative based on the pattern.  Then use the principle of mathematical induction to justify your claim.

2.  Consider f(x)=x sin x.  Determine the first eight derivatives of f and obtain a pattern. Justify your contention.

In Exercises 3 and 4, compute (f^((k)))(x)  for k = 1,2,3,4.
3.   f(x) = (((1 + (x^2)))^(6/5))
4 .  f(x) = ((1-(x^2))/(1-3x+2(x^3)))

3.3	Chain Rule and Implicit Differentiation

Students should read Sections 3.7 and 3.10 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

In this section, we demonstrate not only how Mathematica uses the Chain Rule to differentiate composite functions but also to compute derivatives of functions defined implicitly by equations where solving for the dependent variable is not feasible.

Example 3.8. Find all horizontal tangents of f(x)=(Sqrt[(((x^4)-x+1)/((x^4)+x+1))]) .

Solution: We first compute the derivative of f, which requires the Chain Rule.

f[x_] := (Sqrt[(((x^4) - x +1)/((x^4)+ x + 1))]);
Simplify[f'[x]]

Horizontal tangents have zero slope and so it suffices to solve f'(x)=0 for x.

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

Observe that the solutions above are nothing more than the zeros of the numerator of f'(x).  We ignore the second and third solutions listed above, which are imaginary.  Hence, x=((1/3)^(1/4)) ≈ 0.76  and x=-((1/3)^(1/4)).  A plot of the graph of f below confirms our solution.

Plot[f[x],{x,-2,2}]

Example 3.9.  Find all horizontal tangents of the lemniscate described by 2((((x^2)+(y^2)))^2)=25((x^2)-(y^2)).

Solution: Implicit differentiation is required here to compute ((d y)/(d x)), which involves first differentiating the lemniscate equation and then solving for our derivative.  Observe that we make the substitution y->y(x), which makes explicit our assumption that y depends on x.

Clear[x,y]
eq=2(x^2+y^2)^2==25(x^2-y^2)

2 ((((x^2)+(y^2)))^2)==25 ((x^2)-(y^2))

deq=D[eq/.y->y[x],x]

Solve[deq,y'[x]]

To find horizontal tangents, it suffices to find where the numerator of y'(x) vanishes (since the denominator never vanishes except when y=0).  Thus, we solve the system of equations 25x-4(x^3)-4x (y^2)=0 and 2((((x^2)+(y^2)))^2)=25((x^2)-(y^2))  since the solutions must also lie on the lemniscate.

Solve[{eq,25x-4x^3-4x*y^2==0},{x,y}]

From the output, we see that there are four valid solutions at (5(Sqrt[3])/4,5/4)≈(2.17, 1.25), (-5(Sqrt[3])/4,5/4), (5(Sqrt[3])/4,-5/4), and (-5(Sqrt[3])/4,-5/4), which can be confirmed by inspecting the graph of the lemniscate below.  Observe the symmetry in the solutions.

N[5*Sqrt[3]/4]

ContourPlot[2(x^2+y^2)^2==25(x^2-y^2),{x,-4,4},{y,-2,2}]

Exercises

1. Find all horizontal tangents of  g(x)=(((((x^2)/(x+1))))^7).

2. Find all tangents along the curve  h(x)=(Sqrt[x+(Sqrt[x])]) whose slope equals 1/2.

3. Find all vertical tangents of the cardioid described by (x^2)+(y^2)=(((2(x^2)+2(y^2)-x))^2).

4. Compute the first and second derivatives of

f(x)={({{x cos(1/x), if x≠0}, {0, if x=0}}).

5. Compute the first and second derivatives of

g(x)={({{(x^2) cos(1/x), if x≠0}, {0, if x=0}}).

How do these derivatives at the origin compare with those in the previous exercise?

6. Based on your investigations of the previous two exercises, explain the behavior of higher-order derivatives of

h(x)={({{(x^n) cos(1/x), if x≠0}, {0, if x=0}})

at the origin for positive integer values of n.

7.  Calculate the implicit derivative of y with respect to x of:  x(y^2) + (x^2)(y^4)-- (x^3) = 5.

8.  Plot ((((x^2) + (y^2)))^2)=((x^2)-(y^2))+2  for -4 ≤ x ≤ 4  and  -4 ≤ y ≤ 4.  Then determine how many horizontal tangent lines the curve appears to have and find the points where these occur.

3.4	Derivatives of Inverse, Exponential, and Logarithmic Functions

Students should read Sections 3.8-3.9 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

Exponential functions arise naturally. For example, mathematical models for the growth of a population or the decay of a radioactive substance involve exponential functions. In this section, we will explore exponential functions and their inverses, called logarithmic functions, using Mathematica.  We begin with a review of inverse functions in general.

3.4.1.  Inverse of a Function

Recall that a function g(x) is the inverse of a given function f(x) if f(g(x))=g(f(x))=x.  The inverse of f(x) is denoted by (f^(-1))(x). We note that a necessary and sufficient condition for a function to have an inverse is that it must be one-to-one. On the other hand, a function is one-to-one if it is strictly increasing or strictly decreasing throughout its domain.

Example 3.13.  Determine if the function f(x)=(x^2)-x+1 has an inverse on the domain (-∞,∞). If it exists, then find the inverse.

Solution: We note that f(0)=f(1)=1. Thus, f is not one-to-one. We can also plot the graph of f and note that it fails the Horizontal Line Test since  it is not increasing on its domain.

Clear[f,g]

f[x_]=x^2-x+1;
Plot[f[x],{x,-1,2}]

However, observe that if we restrict the domain of f to an interval where f is either increasing or decreasing, say [0.5,∞), then its inverse exists (see plot below).

plotf=Plot[f[x],{x,0.5,5}]

To find the inverse on this restricted domain, we set y=(f^(-1))(x).   Then f(y)=x. Thus, we solve for y from the equation f(y)=x.

sol=Solve[f[y]==x,y]

Note that Mathematica gives two solutions. Only the second one is valid, having range [0.5,∞), which agrees with the domain of f.  Thus,
				(f^(-1))(x)=  (1/2)(1+(Sqrt[-3+4x])).
To extract this solution from the above output, we use the syntax below and denote the inverse function in Mathematica by g(x) (Mathematica interprets the notation (f^(-1))(x) as (1/(f(x))), the reciprocal of f).

g[x_]=sol[[2,1,2]]

To verify that  f(g(x))=x, we use the Simplify command.

Simplify[f[g[x]]==x]

NOTE: One can also attempt to verify g(f(x))=x.  However, Mathematica cannot confirm this identity (see output below) because it is unable to simplify the radical, which it treats as a complex square root.  Students are encouraged to algebraically check this identity on their own.

Simplify[g[f[x]]==x]

Lastly, a plot of the graphs of f(x) and g(x) (in black and blue, respectively) shows their expected symmetry about the diagonal line y=x (in red).  Observe that the domain of g is [3/4,∞), which is the range of f.

plotg=Plot[g[x],{x,3/4,5}, PlotStyle->Red,AspectRatio->Automatic]

Show[plotf,plotg,Graphics[{Dashing[{0.05,0.05}],Line[{{0,0},{5,5}}]}],PlotRange->{0,5},AspectRatio->Automatic]

Example 3.14.  Determine if the function f(x)=(x^3)+x has an inverse. If it exists, then compute ((f^(-1)))'(2).

Solution: Since f'(x)=3(x^2)+1>0 for all x, we see that f is increasing on its domain. Thus, it has an inverse. Again, we can solve for this inverse as in the previous example:

Clear[f,g,x,sol]
f[x_]:=x^3+x
sol=Solve[f[y]==x,y]

Only the first solution listed above is valid, being real valued.  Thus,
				(f^(-1))(x)=  -(((((2/3)))^(1/3))/(((9 x+(Sqrt[3]) (Sqrt[4+27 (x^2)])))^(1/3)))+((((9 x+(Sqrt[3]) (Sqrt[4+27 (x^2)])))^(1/3))/((2^(1/3)) (3^(2/3)))).
Again we denote our inverse by g(x):

g[x_]=sol[[1,1,2]]

Lastly, we compute g'(2).

Simplify[g'[2]]
N[%]

NOTE: The easier approach in computing g'(2) without having to explicitly differentiate g(x) is to instead use the relation ((f^(-1)))'(x)=1/f'((f^(-1))(x)), which shows that the derivative of f at a point (a,b) on its graph and the derivative of (f^(-1)) (or g in our case) at the corresponding inverse point (b,a) on its graph are reciprocal.  In particular, since f(1)=2 and (f^(-1))(2)=1, we have ((f^(-1)))'(2)=1/f'((f^(-1))(2))=1/f'(1)=1/4.

1/f'[g[2]]
N[%]

NOTE: The plot below illustrates how the slopes of the two tangent lines, that of f at (1,2) and that of g at (2,1) (both in blue), are reciprocal.

Plot[{f[x],g[x],f'[1](x-1)+f[1],g'[2](x-2)+g[2]},{x,-1,5},PlotRange->{-1,5},PlotStyle->{Black,Red,Blue,Blue},AspectRatio->Automatic]

3.4.2.  Exponential and Logarithmic Functions

One of the most important functions in mathematics and its applications is the exponential function. In particular, the natural exponential function f(x)=(e^x), where

e=(lim_(x->0))(((1+x))^(1/x))≈2.718.

In Mathematica, we use the capital letter E or blackboard bold letter e from the Basic Math Input submenu of the Palettes menu to denote the Euler number.

Limit[(1+x)^(1/x),x->0]

Every exponential function f(x)=(a^x), a≠1, a>0, where a≠1 and a>0, has domain (-∞,∞) and range (0,∞). It is also one-to-one on its domain. Hence, it has an inverse.  The inverse of an exponential function f(x)=(a^x) is called the logarithm function and is denoted by g(x)=(Subscript[log, a]) x. The inverse of the natural exponential function is denoted by g(x)=ln x and is called the natural logarithm. In Mathematica, we use Log[a,x] for (Subscript[log, a]) x and Log[x] for ln x.  Below is a plot of the graphs of (e^x) and ln x in black and red, respectively.  Observe their symmetry about the dashed line y=x.

Please refer to Section 3.9 of Rogawski's Calculus textbook for derivative formulas of general exponential and logarithmic functions.

Example 3.15.  Compute derivatives of the following functions.
a) f(x) = (2^x) 	b) f(x)=6(x^2)+4(e^x)	c) f(x) =(Subscript[log, 10])(x^2)	d) f(x)=ln(cos((e^(3x))))

Solution: We will input the functions directly and use the command D to find each derivative. Thus, for a) we will evaluate D[(2^x),x].  Again, note that Log[2] should be read as ln 2.

a)

D[2^x,x]

b)

D[6(x^2)+4(E^x),x]

c)

D[Log[10,x^2],x]

d)

f=D[Log[Cos[(E^(3x))]],x]

Example 3.16.  Find points on the graph of f(x)=(x^2)(e^(3x+5))+3x where  the tangent lines are parallel to the line y=3x-1.

Solution: Since the slope of the given line equals 3 it suffices to solve f'(x)=3 for x to locate these point(s).

Clear[f,sol]
f[x_]=(x^2)(E^(3x+5))+3x
sol=Solve[f'[x]==3,x]

Thus there are two solutions: (-2/3,-2+4(e^3)/9) and (0,0).

x0=sol[[1,1,2]]
x1=sol[[2,1,2]]
f[x0]
f[x1]

The plot that follows on the next page confirms that the two corresponding tangent lines (in blue) are indeed parallel to the given line (in red).

y1=f[x0]+f'[x0](x-x0)
y2=f[x1]+f'[x1](x-x1)
Plot[{f[x],y1,y2,3x-2},{x,-1,1},PlotRange->{-5,15},PlotStyle->{Black,Blue,Blue,Red}]

NOTE: One would expect the tangent line at the origin to be horizontal based on a visual inspection of the graph of f, but this demonstrates the pitfall of using a graphing approach.

Exercises

In Exercises 1 through 4, compute derivatives of the given functions.
1.  f(x) =(x^(2 ))(e^((x^3)-4x))			2.  f(x)=(x^a)+(a^x)		
3.  f(x)=ln (x-1)+ln(x+1)	4.  f(x)=(Subscript[log, 10])(((x((((x^3)-3x+1)/((x^2)-2x-3))))^(3/2)))

5.  Find the second and third derivatives of f(x)=(e^x)ln x.

6.  Let f(x)=cos x +ln x.  Plot the graphs of f and f' on the same set of axes.

7.  Find an equation of the line tangent to the graph of f(x)=((ln x)/(x^2)) that is parallel to the x-axis.

8.  Discovery Exercise: Define sinh x=((e^x)-(e^(-x)))/2 and cosh x=((e^x)+(e^(-x)))/2. These functions are called the hyperbolic sine and hyperbolic cosine of x, respectively.

a) Determine the initial eight derivatives of each of these two hyperbolic functions.

b)  Determine general formulas for the nth derivatives of these functions based on the pattern and verify your contentions via mathematical induction.

c) How do the higher-order derivatives of sinh x and cosh x compare with those of the trigonometric functions sin x and cos x?

Chapter 4 	Applications of the Derivative

We have seen how the derivative of a function is itself a function. This idea leads to many possible applications, some of which we will now explore with Mathematica to demonstrate its ability to manipulate and calculate complicated or tedious expressions.

4.1   Related Rates

Students should read Section 3.11 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

Example 4.1.  Let us assume a rubber ball is sitting out in the sun and that the heat causes its surface area to increase at the rate of 1.5 square centimeters per hour.  How fast is the radius increasing when the radius is 2 centimeters?

Solution: To solve this problem, we will need the formula for the surface area of a sphere: S = 4π(r^2).  Here, the surface area S and the radius r are expressed as functions of t (time).

Clear[S]
sa = S[t] == 4 π r[t]^2

dsa = D[sa,t]

Now differentiate this formula and solve for r'(t):

sol= Solve[dsa,r'[t]]

Since the output above is a nested list (each set of curly braces denotes a list; see Chapter 1 of this manual for a description of nested lists) and our solution, ((S'(t))/(8π r(t))), represents the second element of the first (inner) list, we can extract it in order to define r'(t) as follows:

r'[t]=sol[[1,1,2]]

Since we are given that S'(t)=1.5 and r(t)=2, we substitute these into the formula for r'(t):

r'[t]/. {S'[t]->1.5, r[t]->2}

Therefore, when the radius is 2 cm, it is increasing at the rate of about .0298 cm per hour.

Exercises

1.  If the volume of a cube is increasing at the rate of 2 cubic inches per minute, how fast is the length of one of its sides increasing when that side is 8 inches?

2.  A particle is moving along a parabola y=2(x^2)+3x-1 in such a way that the rate of change of its x-coordinate is constant, namely x'(t)=3.  Find the rate of change of its y-coordinate when the position of the particle is (1,4).

3.  The radius r and height h of a circular cone change at a rate of 2 cm/s.  How fast is the volume of the cone increasing when r = 10 and h = 20? (Recall that the volume of a cone is π(r^2)h/3.)

4.2  Extrema

Students should read Section 4.2 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

Next, let us consider finding critical points and inflection points to determine extrema.  Remember that critical points of a function are those for which f'(x) = 0 or for which f'(x) does not exist. Similarly, inflection points occur where either f''(x) = 0 or where f''(x) does not exist.  Extrema occur at critical points, but not all critical points are extrema (consult your calculus text).  An inflection point is a point (c, f(c)) where concavity changes; this occurs where f''(c) = 0 or where f''(x) does not exist, and like critical points, not all points where f''(x) = 0 (or where f''(x) does not exist) are inflection points.

Example 4.2.  Find all local extrema and inflection points of f(x)=1/((x^2)+3).

Solution: We first define f in Mathematica:

Clear [f,x]

f[x_] := 1/(x^2+ 3)

Plot [f[x],{x, -4, 4}]

To find extrema of f, we locate its critical points, that is, those points where f'(x)=0 or f'(x) is undefined.  We can solve the first case using Mathematica:

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

Since f'(x) is defined everywhere, it follows that there is exactly one critical point at x = 0, and at that point, there is a maximum, as can be seen from the graph above.  We could also have used the second derivative test to confirm this:

f''[0]

Since the second derivative is negative at  x = 0, the curve is concave down there. This, of course, means that we have a local maximum at x = 0.

To find the points of inflection, we locate zeros of the second derivative:

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

To determine if these solutions are indeed inflection points, we need to check if there is a sign change in f''(x)  on either side of each (at x=-1 and x=1):

Plot[f''[x], {x, -2, 2}]

Notice from the graph above that f''(x) changes from positive to negative at x = -1 and from negative to positive at x=1. Thus both points (-1,f(-1)) and (1,f(1)) are inflection points.

Exercises

In Exercises 1through 5, find all critical points and inflection points for:
1. f(x)=(x^3) - 3 (x^2)+ 1		2. f(x)=((x^2) -3) (e^x) 		3. f(x)=sin x on [0, 2π]
4. f(x)=2(x^5)-5(x^4)+5		5. f(x)=(((x^2)+4)/x)

6. Consider the function f(x)=(x^n) where n is a positive integer. For what values of n do we have 
a) a relative minimum but not a point of inflection at the origin?
b)  a point of inflection at the origin but not a relative minimum?
Sketch the graph of several power functions to support your reasoning.

4.3   Optimization

Students should read Section 4.7 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

Extreme values of a function occur where f'(x) = 0 or where f'(x) does not exist.  This idea allows us to find maxima and minima, concepts that are crucial in many applications.  For instance, in business, one wants to minimize costs or maximize profits.  In government, one wants to track the flow of money in an economy, and when that flow is a minimum or a maximum. In engineering design, we may want to know what shape of a conduit will generate  maximum flow.  Similar problems exist in many other fields.  We will now look at some of these applications.

4.3.1  Traffic Flow

Example 4.3.  Traffic flow along a major highway in Boston between 6 AM and 10 AM can be modeled by the function f(t)=20t-40(Sqrt[t])+50 (in miles per hour), where t=0 corresponds to 6 AM.  Determine when the minimum traffic flow occurs.

Solution: Let us first plot the graph of f(t).

Clear[f,t]

f[t_] := 20 t - 40 (Sqrt[t]) + 50

Plot[f[t],{t,0,4}]

Note from the plot above that the average speed is decreasing between 6 AM and 7 AM and increasing after 7 AM.

At 6 AM the average speed is

f[0]

or 50 mph. At 6:30 AM the average speed is

f[.5]

or 31.7 mph. To see how the average speed varies throughout the day we make a table of these values at each half hour from 6 AM to 10 AM:

TableForm[ Table[{t, f[t]},{t,0,4,.5}]]

You can see from the table that the average speed quickly drops from 50 mph to 30 mph in the first hour and then gradually increases back up to 50 mph during the next 3 hours.  If we want to verify that the minimum occurs at 7 AM (or t=1), we can use calculus. Since extrema occur where the derivative is 0, we set the derivative equal to zero and solve for t:

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

Therefore the minimum does occur when t=1 (7 AM) and from the table we see that the minimum average speed at this time is 30 mph.

4.3.2  Minimum Cost

Example 4.4.  A friend of one of the authors owns some land on Long Island off the coast of Portland, Maine.  He wants to build a house there, but there is no electricity.  He is considering laying an underwater cable to connect up with the mainland.  After a while I convince him of the ridiculousness of that idea.  The cost is far more than he can afford, but it does get me thinking about mathematics.  What would be the cheapest way of hooking up a cable to the municipal electrical system?   Let us consider the following scenario:

Imagine the island connection point at (0,3000) and the mainline connection point at (10000,0) where the units are in meters.  Assume it costs $36 per meter to lay cable underwater and $24 per meter to lay cable on land.  You can lay cable underwater from (0,3000) to (x,0) and then lay cable on land from (x,0) to (10000,0).  The variable x can vary between 0 and 10000.  What value of x would minimize the cost for laying this cable and what would that minimum cost be?

Solution: First, we need to determine the cost.  There are two parts: the underwater part and the overland part.  The cost of the underwater part is just $36 times the distance D1 from (0,3000) to (x,0).  We will call that cost c1:

c1[x_] := 36*(Sqrt[(3000^2)+(x^2)])

The overland cost is $24 times the distance D2 from (x,0) to (10000,0).  We will call that cost c2:

c2[x_] := 24*(10000-x)

The total cost is then

cost[x_]= c1[x] + c2[x]

We need to minimize this cost function.  First, we graph it to see if it has a minimum:

Plot[cost[x],{x,0,10000}]

Notice that this cost function has its minimum somewhere between 2000 and 4000.  Also, you will note that as x gets close to that minimum the tangent lines of cost (x) are getting close to horizontal. In other words, the minimum will occur at a point x for which the derivative is zero or horizontal (i.e., the derivative at a point gives the slope of the tangent line at that point). This is a calculus problem that we can solve.

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

N[cost[1200(Sqrt[5])]]

Therefore, the minimum occurs  at x=1200(Sqrt[5])≈ 2683.28 meters and the minimum cost is approximately $320,498.

NOTE: Another method in finding the minimum is to use the command FindMinimum. We will start our search near x=2000:

FindMinimum[cost[x],{x,2000},WorkingPrecision->8]

Again, we get an answer that corroborates the previous answer.

4.3.3  Packaging (Minimum Surface Area)

Example 4.5.  A major concern in business is to minimize the cost of packaging.  This cost is related to the surface area of the package.  If we can minimize that surface area, then we can minimize the cost.  Let us assume that a company has a certain product that needs to be packaged in a rectangular box having a square base.  If the volume of the box is required to be 1 cubic meter, then find the dimensions of the box that will minimize its surface area.

Solution: If the length of the sides of the square base is x and the height of the box is y, then the volume of the box is given by (x^2)y and must equal 1 cubic meter (this is our constraint):

Clear[x, y,S]

constraint=x^2*y==1

The surface area of our package (box) is S=4x y + 2 ((x^2)) and is the quantity that must be minimized (recall that the top and bottom sides each have area (x^2) and the 4 sides each have area x y).  Using our volume constraint, (x^2)y = 1, we can solve for y in terms of x:

y = (1/(x^2))

sol=Solve[constraint,y]

The surface area function can then be expressed as a function of x only:

S(x) = 4 x y  + 2 (x^2) = 4 x (1/(x^2))  +  2 (x^2) =  4/x + 2(x^2)

S[x_]=4x*y+2x^2/.y->sol[[1,1,2]]

Using the idea again that extrema occur at points where the derivative is zero, we calculate:

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

This equation has 1 real and 2 imaginary solutions. We need only the real solution of x = 1. To see that this corresponds to an actual minimum, we plot the curve:

Plot[S[x], {x,0 ,5}]

Alternatively, we could have used the second derivative test to show that a minimum occurs at x = 1:

S''[1]

Since f''(1)>0, we know that the graph is concave up at x=1 and hence must have a minimum there.  Since y=1 when x=1, we conclude that the box with minimum surface area is a cube with sides of 1 meter.

4.3.4  Maximize Revenue

The following application concerns optimizing group fares for charter flights.

Example 4.6.  Suppose a travel agency charges $600 per person for a charter flight if exactly 100 people sign up.  However, if more than 100 people sign up, then the fare is reduced by $2 per person for each additional person over the initial 100.  The travel agency wants to know how many people they should book to maximize revenue.  Also, determine what that maximum revenue is and what the corresponding fare is for each person.

We let x denote the number of passengers above 100.  Keep in mind that revenue is the product of the number of people multiplied by the cost (fare) per person.  If R(x) is defined as the revenue function, then R(x) = (100 +x) (600 - 2x).  To determine the maximum value of R(x) for x≥0, let us first examine its graph:

R[x_] := (100+ x) (600 - 2x)

Plot[R[x], {x,0,200}]

From the plot above, we see that a maximum occurs at about x = 100.  To confirm this, we first solve for the critical points:

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

Therefore the maximum does indeed occur at x = 100, and the maximum revenue is

R[100]

or  $80,000.  Since 100 + x represents the number of customers, this occurs when 200 customers sign up for the flight.  In this case, the cost per person is

600 - 2x /. x ->100

or $400 per person.

Exercises

1. Assume traffic flow is given by a speed function f(t) = 25 t - 45 (Sqrt[t]) + 55.  Analyze speed changes between 6 AM and 10 AM and calculate when traffic flow is minimized.  What is that minimum speed?

2. Find the minimum value of f(x)=3(x^4)+4(x^3).

3. Assume that the average cost of producing compact discs is given by  c(x) = -.0002 x + 3 + 2000/x.  Show that the average cost is always decreasing for x between 0 and 4000.

4. Suppose the population of a city is modeled by

p(t) = 4456 (t^3)  + 8939  (t^2)+ 23463 t + 25528

where t is measured in years from 1990 to 2000.

a)  Show that the population was always increasing in this decade.

b)  Show that the population was increasing at its slowest rate in August of 1990.  Hint:  The population is increasing at its slowest rate when p''(t) = 0.

5.  Given that the total cost for manufacturing x units of a particular product is described by the function C(x)=0.0025(x^2)+80x+10000, find the level of production that minimizes the total cost of manufacturing.

6. The total population of the planet is forecast by the function P(t)=0.00074(t^3)-0.07(t^2)+0.89t+6.04 where t is measured in decades,  t=0 corresponds to the year 2000, and P(t) is measured in billions of people.  In what year will the population peak over the next 200 years?

7. A book designer has decided that the pages of a book are to have 1.5 inch margins top and bottom and 1 inch margins on each side.  If each page is to have an area of 100 square inches, what are the dimensions of this page if its printed area is to be a maximum?

8. The owner of a farm wants to enclose a rectangular region with 3000 m of fencing while dividing the region into two parts, each of which is rectangular, by using part of the fencing to subdivide it and running a fence parallel to the sides (see figure that follows).   What should be the dimensions of the region in order to maximize its area?

9. The owner of a cruise ship charges groups as follows:  For a group of 40 people, the charge is $1,000 per person per day.  If more than 40 people sign up, the fare is reduced by $8 for each addtional person.

a) Assuming at least 40 people sign up, determine the number necessary to maximize revenue.

b) What is the maximum revenue?

c) What would be the cost per person in this case?

4.4   Newton's Method

Students should read Section 4.7 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

4.4.1  Programming Newton's Method

Newton's Method is a technique for calculating zeros of a function based on the direction of its tangent lines.  It is a recursive routine that is rather tedious to do by hand or even with a calculator, but simple with Mathematica. To start the procedure one should have an idea about the general location of each zero.  This is because an initial approximation (Subscript[x, 0]) for that zero, say at x=r, is needed to start the recursion.  For example, one can specify (Subscript[x, 0]) by examining the graph of the function to see where the zeros are approximately.   Then the next approximation (Subscript[x, 1]) can be found by the recursive formula (Subscript[x, 1])=(Subscript[x, 0])-f((Subscript[x, 0]))/f'((Subscript[x, 0])).   This process can be iterated using the general formula

(Subscript[x, n+1])=(Subscript[x, n])-f((Subscript[x, n]))/f'((Subscript[x, n]))

Under suitable conditions, the sequence of approximations {(Subscript[x, 0]),(Subscript[x, 1]),(Subscript[x, 2]),...} (called the Newton sequence) will converge to r.

Example 4.7. Approximate the zeros of the function f(x)=ln(9-(x^2))-x.

f[x_] := Log[9-(x^2)]-x

Plot[f[x], {x,0,3}]

Clearly, there is one zero between 1.5 and 2 based on the plot above.  To approximate this zero, we define a function newtn to perform the recursion:

newtn[x_] := x - f[x]/f'[x]

To generate the corresponding Newton sequence, we compute 8 iterates of this function starting with an initial guess of x = 1.6.  This iteration can be performed efficiently using the NestList[f,x,n] function, which is a recursive routine that outputs a list with x as its first value, followed by f[x], f[f[x]], f[f[f[x]]], etc., up to n iterates as shown in the example below:

approx=NestList[newtn,1.6, 8]

From this we see that the root, accurate to 4 decimal places, is 1.7696.  If greater accuracy is desired, say 12 decimal places, we can redisplay the values of approx if it is already accurate to 12 decimal places or else recalculate it using a higher number of iterations if necessary.

NumberForm[approx//TableForm,13]

Discovery Exercise: The function f(x)=ln(9-(x^2))-x discussed above has a second zero.  Locate it on the graph of f(x) and use Newton's method to approximate it to 12 decimal places.  Hint: First, plot the graph over a wide interval to locate the zero, and then zoom in to obtain an initial approximation.

Warning: Be sure that your initial approximation is sufficiently close to your zero; otherwise the Newton sequence may diverge or converge to another zero.

4.4.2  Divergence

One interesting point about Newton's Method is that it does not always work. For instance, the function y = (x^(1/3)) clearly has a root at x = 0:

Plot[(x^(1/3)) , {x,0,1}]

Yet, Newton's Method fails for any guess x ≠ 0:

Clear[f]
f[x_]:=(x^(1/3))

NestList[newtn,0.6,6]

NOTE: The extremely small imaginary values that appear in the answers earlier should be ignored (or treated as zero) since we expect our answers to be entirely real.  This is due to Mathematica's default algorithm for computing radicals in the domain of complex numbers, which may introduce extremely small numerical errors.  To eliminate these imaginary parts, we use the Re[expr] command to extract the real part of expr.

Re[NestList[newtn,0.6,6]]

Question: Can you explain why Newton's Method fails in the above example?

4.4.3  Slow Convergence

Even when Newton's Method works, sometimes the Newton sequence converges very slowly to the answer.  Consider the following function:

Clear[ f]
f[x_] := (x^3) - x - 1

Plot[f[x], {x, -3,2}]

Clearly, there is a root between 1.2 and 1.4.  If  we use the newtn function with our guess as x = 1, we get quick convergence to the root:

NestList[newtn,1.0,6]

But if we choose our initial guess near 0.6, the convergence is much slower as discussed in the following exercises.

Exercises

1.  Compare the convergence in the above example (Section 4.4.3) for initial guesses of 0.5 and 0.6.  Why does Newton's Method converge so slowly for these values?  (Hint: Consider the tangent lines to the curve f(x).)

2.  Synthesizing the discussion in Sections 4.4.1 and 4.4.2 on the flaws in Newton's Method, can you come up with any general criteria that will tell us when Newton's Method will converge or diverge?

3. Use Newton's Method to find the postive zero of f(x)=(x^2)-2 accurate to 5 decimal places.   Note: This demonstrates how Newton's Method can be used to approximate (Sqrt[2]).

4. Consider the polynomial function p(x)=(x^4)-8(x^2)+15.
a) Find all the roots of this function.
b) Graph this function over the interval [-5,5].
c) Explain why at x=2 is not a good starting approximation for the root in the interval
d) Use Newton’s Method to approximate the other three roots in the appropriate intervals.
e) Which other values of are not good seed (starting) values and why? (Hint : Consider points of horizontal tangency.)

5. Use Newton's Method to find a solution (accurate to 5 decimal places) to the following equations:

a)  sin x = cos(2x) in the interval [0, π/2] (Hint: Define f(x)=sin x-cos(2x).)		b)  (e^x)= 5x		c)   cos x = x

Chapter 5 	Integration

5.1  Antiderivatives (Indefinite Integral)

Students should read Section 4.8 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

Integrate[f,x] gives the indefinite integral (or antiderivative) of f with respect to x.  The command Integrate can evaluate all rational functions and a host of transcendental functions, including exponential, logarithmic, trigonometric, and inverse trigonometric functions.  One can also use the palette button ∫□d□ (BasicMathInput Palette) to evaluate integrals.

Example 5.1.  Evaluate  ∫((x^2)-2x+1)dx.

Solution:

Method 1: (Palette buttons)

∫((x^2)-2x+1)\[DifferentialD]x

NOTE: Mathematica does not explicitly include the constant of integration C in its answers for indefinite integrals; the user should always assume that this is implicitly part of the answer.

Method 2: (Integrate command)

Integrate[(x^2-2x+1),x]

Example 5.2.  Evaluate  ∫((x((x^2)+1))^2)dx.

Solution:

Method 1: (Palette buttons)

∫x((((x^2)+1))^2)\[DifferentialD]x

NOTE: Observe that if the substitution u=(x^2)+1 is used to transform this integral, then the answer becomes ∫((x((x^2)+1))^2)dx=(1/2)∫(u^2)du=(1/6)(((1+(x^2)))^3).  How does one reconcile this answer with the one obtained in the output above?

The following are examples of integrals that can be evaluated in a routine manner using the substitution method.  The reader should perform the integration by hand to check answers.

Example 5.3.   Evaluate ∫(x/(Sqrt[x+1]))dx.

Solution:

∫(x/(Sqrt[x+1]))\[DifferentialD]x

Example 5.4.  Evaluate ∫(x^2)sin((x^3))dx.

Solution:

∫(x^2) Sin[(x^3)]\[DifferentialD]x

Note: Mathematica can certainly integrate much more complicated functions, including those that may require using any of the integration techniques discussed in your calculus textbook. We will consider some of these in Section 5.4.

Exercises

In Exercises 1 through 6, evaluate the integrals. Simplify your answers.
1. ∫((x^2)+2)dx			2. ∫cos 3xdx				3. ∫(Sqrt[1-(x^2)])dx		
4. ∫(sin^( 2))xdx				5.∫((3(x^5)+6(x^4)-x+1)/(x^3))d x			6.  ∫(( 1)/(1+ sin2 x))d x

In Exercises 7 and 8, evaluate the integrals by first using Mathematica to decompose the integrand as a sum of partial fractions (using the Apart[expr] command to perform this decomposition).
7. ∫(((x^2)+2x-1)/(2(x^3)+3(x^2)-2x))dx			8.∫(1/(x(x+1)(2x+3)))dx

5.2  Riemann Sums and the Definite Integral

Students should read Sections 5.1 and 5.2 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

There are two basic integration commands in Mathematica to evaluate definite integrals. Integrate[f,{x,a,b}] calculates the definite integral (area under the curve) of f on the interval [a,b] using analytic methods. NIntegrate[f,{x,a,b}] calculates a numerical approximation of the definite integral of f on [a,b] using numerical methods.

Review of Riemann Sums: A partition of a closed interval [a,b] is a set P={(Subscript[x, 0]), (Subscript[x, 1]), (Subscript[x, 2]), .... , (Subscript[x, n])} of points of [a,b] such that

a=(Subscript[x, 0])<(Subscript[x, 1])<(Subscript[x, 2])<..... <(Subscript[x, n])=b.

Given a function f on a closed interval [a,b] and a partition P={(Subscript[x, 0]), (Subscript[x, 1]), .... , (Subscript[x, n])} of the interval [a,b],  recall that a Riemann sum of f over [a,b] relative to P is a sum of the form

(∑_(i=1)^n)f((SuperStar[(Subscript[x, i])]))Δ (Subscript[x, i]),

where 	Δ (Subscript[x, i])=(Subscript[x, i])-(Subscript[x, i-1]) and (SuperStar[(Subscript[x, i])])is an arbitrary point in the ith subinterval [(Subscript[x, i-1]),(Subscript[x, i])].  For simplicity, we shall assume that Δ (Subscript[x, i])=Δ x =((b-a)/n) for all i.  A Riemann sum is therefore an approximation to the (signed) area of the region between the graph of f and the x-axis along the interval [a,b].  The exact area is given by the definite integral of f over [a,b], which is defined to be the limit of its Riemann sums as n->∞ and is denoted by (∫_a^b)f(x)dx. In other words,

(∫_a^b)f(x)dx=(lim_(n->∞))(∑_(i=1)^n)f((SuperStar[(Subscript[x, i])]))Δ x.

This definite integral exists provided the limit exists.  For a continuous function f, it can be shown that (∫_a^b)f(x)dx exists.

5.2.1  Riemann Sums Using Left Endpoints

A Riemann sum of f relative to a partition P can be obtained by considering rectangles whose heights are based on the left endpoint of each subinterval of P.   This is achieved by setting (SuperStar[(Subscript[x, i])])=(Subscript[x, i])=a+i(b-a)/n for i=0, 1, .... n-1,  so that the corresponding height of each rectangle is given by f((Subscript[x, i])).  This leads to the following formula for a Riemann sum using left endpoints, which we denote by LRSUM. To use this function, we need to specify the values of a, b, and n as well as define f using Mathematica's format.

Clear[f]
LRSUM[a_,b_,n_]:=Sum[f[a+i*(b-a)/n]*(b-a)/n,{i,0,n-1}]

Example 5.4. Let f(x)=(x^2) on [0,1] and let P={0, 1/n, 2/n, 3/n, ....,( n-1)/n, 1} be a partition of [0,1]. 
a) Approximate (∫_0^1)f(x)dx by computing the Riemann sum relative to P using the left endpoint method.
b) Plot the graph of f and the rectangles corresponding to the Riemann sum in part (a). 
c) Find the limit of the Riemann sum obtained in part a) by letting n->∞.

Solution: a) We define f(x)=(x^2) in Mathematica and evaluate LRSUM using a=0, b=1, and various values for n. In the table below, the first column gives the value of n and the second column gives the corresponding Riemann sum.

f[x_]:=(x^2)
TableForm[Table[{n,N[LRSUM[0,1,n]]},{n,10,100,10}],
TableHeadings->{{},{"n","Riemann Sum"}}]

Thus, (∫_0^1)(x^2)dx≈0.30875 for n=20 (rectangles). We leave it to the reader to use large values of n to investigate more accurate approximations using left endpoints.

b) The following program gives a plot of the rectangles corresponding to the Riemann sum in part (a) using left endpoints.

LEPT[f_,{a_,b_,n_}]:=Module[
{dx, k, xstar, lrect, plot},
dx=N[(b-a)/n];
xstar=Table[a+i* dx, {i,0,n}]; 
lrect=Table[Line[{{xstar[[i]],0},{xstar[[i]],f[xstar[[i]]] }, {xstar[[i+1]],f[xstar[[i]]] }, {xstar[[i+1]],0}}],{i,1,n}];
plot=Plot[f[x],{x,a,b},Filling ->Axis];
Show[plot,Graphics[{Green,lrect}]]]

To demonstrate this for our example, we evaluate LEPT by specifying f(x)=(x^2),  a=0, b=1 and n=20.

f1[x_]:=x^2
LEPT[f1,{0,1,20}]

Here is a graphics animation of the plot above as n (number of rectangles) increases from 1 to 50.

Important Note: If you are reading the printed version of this publication, then you will not be able to view any of the animations generated from the Animate command in this chapter.  If you are reading the electronic version of this publication formatted as a Mathematica Notebook, then evaluate each Animate command to view the corresponding animation.  Just click on the arrow button to start the animation.  To control the animation just click at various points on the sliding bar or else manually drag the bar.

Animate[LEPT[f1,{0,1,a}] ,{a,1,50,5 }]

NOTE: The underestimation given by LRSUM in this example can be explained from the above graph: The sum of the area of the rectangles is less than the area of the region under the graph of f since the rectangles are contained inside the same region.  This is due to the fact that f is increasing on [0,1].

c)  We evaluate LRSUM in the limit as n-> ∞.

Limit[LRSUM[0,1,n], n->Infinity]

Thus,  (∫_0^1)(x^2)dx=1/3=0.33....

5.2.2  Riemann Sums Using Right Endpoints

We can similarly define a Riemann sum of f relative to a partition P by considering rectangles whose heights are based on the right endpoint of each subinterval of P.   This is achieved by setting (SuperStar[(Subscript[x, i])])=(Subscript[x, i])=a+i(b-a)/n for i=1,2,.... n,  so that the corresponding height of each rectangle is given by f((Subscript[x, i])).  Note that i ranges from 1 to n in this case (as opposed to 0 to n-1 for the left endpoint method).  This leads to the following formula for the Riemann sum using right endpoints, which we denote by RRSUM:

Clear[f]
RRSUM[a_,b_,n_]:=Sum[f[a+i*(b-a)/n]*(b-a)/n,{i,1,n}]

Example 5.5. Let f(x)=(x^2) on [0,1] and let P={0, 1/n, 2/n, 3/n, ....,( n-1)/n, 1} be a partition of [0,1]. 
a) Approximate (∫_0^1)f(x)dx by computing the Riemann sum relative to P using the right endpoint method.
b) Plot the graph of f and the rectangles corresponding to the Riemann sum in part (a). 
c) Find the limit of the Riemann sum obtainded in part a) by letting n->∞.

Solution:  a) We evaluate

f[x_]:=(x^2)
TableForm[Table[{n,N[RRSUM[0,1,n]]},{n,10,100,10}],
TableHeadings->{{},{"n","Riemann Sum"}}]

b) Similarly, we can write a program that gives a plot of the rectangles corresponding to the Riemann sum in part (a) using right endpoints.

REPT[f_,{a_,b_,n_}]:=Module[
{dx, i, xstar, rrect, plot},
dx=N[(b-a)/n];
xstar=Table[a+i* dx, {i,0,n}];
rrect=Table[Line[{{xstar[[i]],0},{xstar[[i]],f[xstar[[i+1]]]}, {xstar[[i+1]],f[xstar[[i+1]]]}, {xstar[[i+1]],0}}],{i,1,n}];
plot=Plot[f[x],{x,a,b},Filling ->Axis];
Show[plot,Graphics[{Blue,rrect}]]]

For our example, we have:

f2[x_]:=x^2
REPT[f2,{0,1,20}]

Important Note: If you are reading the printed version of this publication, then you will not be able to view any of the animations generated from the Animate command in this chapter.  If you are reading the electronic version of this publication formatted as a Mathematica Notebook, then evaluate each Animate command to view the corresponding animation.  Just click on the arrow button to start the animation.  To control the animation just click at various points on the sliding bar or else manually drag the bar.

Animate[REPT[f2,{0,1,a}] ,{a,1,50,5 }]

NOTE: The overestimation of the RRSUM can be explained analogously as with the underestimation obtained from LRSUM.

c) We evaluate RRSUM in the limit as n->∞:

Limit[RRSUM[0,1,n],n->Infinity]

NOTE: Here is a comparison between the two plots of the left-endpoint and right-endpoint rectangles:

LREPT[f_,{a_,b_,n_}]:=Module[
{dx, i, xstar,lrect, rrect, plot},
dx=N[(b-a)/n];
xstar=Table[a+i* dx, {i,0,n}]; 
lrect=Table[Line[{{xstar[[i]],0},{xstar[[i]],f[xstar[[i]]] }, {xstar[[i+1]],f[xstar[[i]]] }, {xstar[[i+1]],0}}],{i,1,n}];
rrect=Table[Line[{{xstar[[i]],0},{xstar[[i]],f[xstar[[i+1]]]}, {xstar[[i+1]],f[xstar[[i+1]]]}, {xstar[[i+1]],0}}],{i,1,n}];
plot=Plot[f[x],{x,a,b},Filling ->Axis];
Show[plot,Graphics[{Blue,rrect}],Graphics[{Green,lrect}] ]
]

f[x_]:=(x^2)
LREPT[f,{0,1,20}]

f3[x_]:=(x^2) 
Animate[LREPT[f3,{0,1,a}] ,{a,1,100,5 }]

5.2.3  Riemann Sums Using Midpoints

The Riemann sum using the midpoints of each subinterval is given by the following formula. (We leave it to the student to verify that the midpoint of ith subinterval is given by  a+(i+(1/2))(((b - a)/n)) for i=1,...,n.)

Clear[f]
MRSUM[a_,b_,n_]:=Sum[f[a+(i+1/2)*(b-a)/n]*(b-a)/n,{i,1,n}]

Example 5.6. Let f(x)=(x^2) on [0,1] and let P={0, 1/n, 2/n, 3/n, ....,( n-1)/n, 1} be a partition of [0,1]. 
a) Approximate (∫_0^1)f(x)dx by computing the Riemann sum relative to P using the midpoint method.
b) Plot the graph of f and the rectangles corresponding to the Riemann sum in part (a). 
c) Find the limit of the Riemann sum obtainded in part a) by letting n->∞.

Solution:  a) We evaluate

f[x_]:=(x^2)
TableForm[Table[{n,N[MRSUM[0,1,n]]},{n,10,100,10}],
TableHeadings->{{},{"n","Riemann Sum"}}]

Options[TableForm]

b) Again, we can write a program that gives a plot of the rectangles corresponding to the Riemann sum in part (a) using midpoints.

MIDPT[f_,{a_,b_,n_}]:=Module[
{dx, i, xstar,mrect, plot},
dx=N[(b-a)/n];
xstar=Table[a+i* dx, {i,0,n}]; 
mrect=Table[Line[{{xstar[[i]],0},{xstar[[i]],f[(xstar[[i]]+xstar[[i+1]])/2]}, {xstar[[i+1]],f[(xstar[[i]]+xstar[[i+1]])/2]}, {xstar[[i+1]],0}}],{i,1,n}];
plot=Plot[f[x],{x,a,b},Filling ->Axis];
Show[plot,Graphics[{Red,mrect}]]
]

f[x_]:=(x^2)
MIDPT[f,{0,1,10}]

Important Note: If you are reading the printed version of this publication, then you will not be able to view any of the animations generated from the Animate command in this chapter.  If you are reading the electronic version of this publication formatted as a Mathematica Notebook, then evaluate each Animate command to view the corresponding animation.  Just click on the arrow button to start the animation.  To control the animation just click at various points on the sliding bar or else manually drag the bar.

f4[x_]:=(x^2) 
Animate[MIDPT[f4,{0,1,a}] ,{a,1,100,5 }]

c) The limit of the Riemann sum using the midpoints is given by

Limit[MRSUM[0,1,n],n->Infinity]

NOTE: Here is a visual comparison of all three Riemann sums in terms of rectangles:

ALL[f_,{a_,b_,n_}]:=Module[
{dx, i, xstar,lrect, rrect,mrect, plot},
dx=N[(b-a)/n];
xstar=Table[a+i* dx, {i,0,n}]; 
lrect=Table[Line[{{xstar[[i]],0},{xstar[[i]],f[xstar[[i]]] }, {xstar[[i+1]],f[xstar[[i]]] }, {xstar[[i+1]],0}}],{i,1,n}];
rrect=Table[Line[{{xstar[[i]],0},{xstar[[i]],f[xstar[[i+1]]]}, {xstar[[i+1]],f[xstar[[i+1]]]}, {xstar[[i+1]],0}}],{i,1,n}];
mrect=Table[Line[{{xstar[[i]],0},{xstar[[i]],f[(xstar[[i]]+xstar[[i+1]])/2]}, {xstar[[i+1]],f[(xstar[[i]]+xstar[[i+1]])/2]}, {xstar[[i+1]],0}}],{i,1,n}];
plot=Plot[f[x],{x,a,b},Filling ->Axis];
Show[plot,Graphics[{Blue,rrect}],Graphics[{Green,lrect}],Graphics[ {Red,mrect}]]
]

f5[x_]:=(x^2)
ALL[f5,{0,1,10}]

Here is how all three Riemann sums behave when we increase the number of rectangles.

f5[x_]:=(x^2)
Animate[ALL[f5,{0,1,a}] ,{a,1,100,5 }]

NOTE: All three limits from the left-endpoint, right-endpoint, and midpoint methods are equal. This is not surprising since each is equal to (∫_0^1)(x^2)dx (remember that the existence of a definite integral requires that all Riemann sums converge to the same limit).  However, the midpoint method tends to converge faster to the limit than the other two methods (discussed in your calculus text).

Example 5.7.  Let f(x) =(x^3)+(x^2)+1 on [0,1] and let P={0, 1/n, 2/n, ...., n/n=1} be a partition of  [0,1].
a) Find the Riemann sum of f relative to P using the left endpoints of the partition.
b) Find the Riemann sum of f relative to P using the right endpoints of the partition.
c) Show that the difference between the two sums goes to 0 at n-> ∞.  
d) Find the limit of the Riemann sums in parts (a) and (b). Is this consistent with part (c)?
e) What do you conclude from part (d)?

Solution: a) The Riemann sum using left endpoints is given by

Clear[f]
LRSUM[a_,b_,n_]:=Sum[f[a+i*(b-a)/n]*N[(b-a)/n],{i,0,n-1}]

f[x_]:=(x^3)+(x^2)+1
LRSUM[0,1,n]

b) The Riemann sum using right endpoints is given by

Clear[f]
RRSUM[a_,b_,n_]:=Sum[f[a+i*(b-a)/n]*N[(b-a)/n],{i,1,n}]

f[x_]:=(x^3)+(x^2)+1
RRSUM[0,1,n]

c) We now evaluate and simplify the difference between the two Riemann sums:

Simplify[RRSUM[0,1,n]-LRSUM[0,1,n]]

As n ->∞, observe that this difference goes to zero.

d) Next, we use the limit command to evaluate the limit of the two Riemann sums:

Limit[LRSUM[0,1,n],n->Infinity]

Limit[RRSUM[0,1,n],n->Infinity]

In light of (c), we should not be surprised that the two limits are the same. After all, their difference was seen to converge to zero!

e) By definition of a definite integral, we conclude from (d) that (∫_0^1)((x^3)+(x^2)+1)dx=19/12. We confirm this by evaluating

(∫_0^1)((x^3)+(x^2)+1)\[DifferentialD]x

Exercises

1.  Let f(x)=(x/((x^2)+1))for 0≤x≤1 and let P={0/n, 1/n, 2/n, ... , n/n=1} be a partition of [0,1].

a)  Find the Riemann sum of f using the left endpoints of P and plot the rectangles that approximate the integral of f over [0,1]. Also, use the Animate command to see if the total area of the rectangles converges to the area of the region under the graph of f and above the x-axis.

b)  Repeat (a) using right endpoints of P.

c)  Repeat (a) using midpoints of P.

2.  Let f(x)=x sin x on [0, π].  Use a uniform partition P and repeat Exercise 1 (immediately above) for this function.

5.3  The Fundamental Theorem of Calculus

Students should read Sections 5.3 and 5.4 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

The crowning achievement in calculus is the Fundamental Theorem of Calculus (FTC), which reveals that integration and antidifferentiation are equivalent.  This can be expressed in two parts:

FTC - Part I: Given a continuous function f(x) on [a,b], we have

(∫_a^b)f(x)dx=F(b)-F(a).

Here, F(x) is any antiderivative of f(x).

FTC - Part II: If F(x)=(∫_a^x)f(t)dt, then F'(x)=f(x).

NOTE: Physically the Fundamental Theorem of Calculus tells us that the area under a velocity curve of an object is the same as the change in position of the object.

Mathematica naturally uses FTC to evaluate definite integrals whenever it is able to find an antiderivative.  Of course, there are examples where it is not able to do this, as the latter examples following demonstrate.

Example 5.8.  Evaluate (∫_1^5)(x/(Sqrt[2x-1]))dx.

Solution:

(∫_1^5)(x/(Sqrt[2x-1]))\[DifferentialD]x

Example 5.9.  Evaluate (∫_(Sqrt[3])^2)((Sqrt[(x^2)-3])/x)dx.

Solution:

Integrate[Sqrt[x^2-3]/x,{x,Sqrt[3],2}]

N[%]

Example 5.10.  Approximate (∫_0^1)tan (x^2)dx.

Solution:  Here is an example of an integral that Mathematica cannot evaluate exactly but returns the integral unevaluated because the precise answer is not expressible in terms of elementary functions.

Integrate[Tan[x^2],{x,0,1}]

However, a numerical approximation is still possible through the command N.

N[%]

Or we could use the command NIntegrate to perform both steps at once:

NIntegrate[Tan[x^2],{x,0,1}]

Example 5.11.  Use the fact that if m≤f(x)≤M for all x∈[a,b], then m(b-a)≤(∫_a^b)f(x)dx≤M(b-a) to approximate  (∫_0^2)(Sqrt[(x^3)+1])dx.

Solution: We note that the function f(x)=(Sqrt[(x^3)+1]) is increasing on [0,2].  This can be checked by finding f'(x) and observing that f'(x)>0 for all x (or by simply drawing the graph of f).  Thus, 1=f(0)≤f(x)≤f(2)=3 and so

1(2-0)≤(∫_0^2)(Sqrt[1+(x^3)])dx≤3(2-0)

or

2≤(∫_0^2)(Sqrt[1+(x^3)])dx≤6

We can confirm this by evaluating

Integrate[(Sqrt[(x^3)+1]),{x,0,2}]

Since the function Hypergeometric2F1 is not known to us, we use

NIntegrate[(Sqrt[(x^3)+1]),{x,0,2}]

Example 5.12.  Let f(x)=cos((x^2)) on [0,2] and define g(x)=(∫_0^x)f(t)dt=(∫_0^x)cos((t^2))dt. 
a) Plot the graph of f.
b) Find the value(s) of x for which g(x) starts to decrease.
c) Estimate g(x) for x=0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1,4, 1.6, 1.8, 2.
d) Draw the graphs of g(x) and g'(x).
e) How do the graphs of f(x) and g'(x) compare?

Solution: a) We plot the graph of f.

Clear[f]
f[x_]=Cos[(x^2)]
g[x_]=(∫_0^x)f[t]\[DifferentialD]t

NOTE: The function FresnelC is called the Fresnel Cosine function and plays an important role in physics and engineering.  The Fresnel Sine function is defined in the obvious manner.

Plot[f[x],{x,0,2}]

b) We note that the graph of f is above the x-axis (positive area) for x between 0 and (Sqrt[π/2]) and below the x-axis for x between (Sqrt[π/2]) and 2.  Thus, the graph of g starts to decrease after (Sqrt[π/2]).  The following table of the Riemann sums of f on [0,x] (for x varying from 0 to 2) shows this point.

f[x_]:=(x^2)
TableForm[Table[{n,N[MRSUM[0,1,n]]},{n,10,100,10}]]

LRSUM[a_,b_,n_]:=Sum[f[a+i*(b-a)/n]*N[(b-a)/n],{i,0,n-1}]

TableForm[Table[{x,LRSUM[ 0, x,100]}, {x, 0, 2, 0.1}],TableHeadings->{{},{"x","Riemann Sum"}}]

NOTE: Since g is the integral, it should start to decrease at x=(Sqrt[π/2])≈1.25.  We can confirm this by examining the values of g in the neighborhood of this point:

Table[{x,LRSUM[ 0, x,100]}, {x, 1.2, 1.3, 0.01}]//TableForm

From the table above, we see that the function g does indeed start to decrease at approximately x=1.25:

c) Here is the table of values for g(x):

TableForm[Table[{x, g[x]},{x,0.2,2,0.2}]]

d) The graphs of the function f(x) and g'(x) are given below:

Plot[{g[x],g'[x]},{x,0,2}, PlotStyle->{Red,Blue}]

e) The graphs of the function f(x) and g'(x) are given below:

Plot[{f[x],g'[x]},{x,0,2}, PlotStyle->{Red,Blue}]

This means that the two graphs are the same.  In fact, from the Fundamental Theorem of Calculus, we know that g'(x)=f(x).

Exercises

In Exercies 1 troough 11, evalaute the given integrals. 
1. (∫_0^1)((x^2)+2)dx		2. (∫_0^π)cos 3xdx			3. (∫_0^1)(Sqrt[1-(x^2)])dx		4. (∫_(-π)^π)(sin^( 2))xdx

5. ((∫_0)^3)((x^3)-4(x^2)+x)d x	6. ((∫_1)^4)((( 1)/(Sqrt[x]))+2(Sqrt[x]))d x	7. ((∫_0)^(π/4)) sec x  d x		8. (∫_0^((Sqrt[2])/4))(2/(Sqrt[1-4(x^2)])) d x
9. ((∫_0)^3)(1/(x+1))d x			10. ((∫_1)^4)((( 1)/x)+2(x^2))d x		11. ((∫_0)^π) (e^x)sin x  d x

12. Let S(x)=(∫_0^x)sin((1/2)π (t^2))dt (S(x) is called the Fresnel sine)

a)  Plot the graph of S and approximate the value of S as x->∞.  Confirm your approximation by evaluating the limit as x-> ∞.

b)  Find S'(x) and use it to find the interval(s) on whcih S(x) increase and decrease.  Hint: Apply the Fundamental Theorem of Calculus.

c)  On what intervals is S concave up? Concave down?

d)  Find the value of x for which S(x)=0.7.

13. Find an explicit formula for a continuous function f such that

(∫_0^x)f(t)dt=x (e^x)+(∫_0^x)((f(t))/(2(t^2)+1))dt.

(Hint: First take the derivative of both sides and then solve for f(x).)

5.4  Integrals Involving Trigonometric, Exponential, and Logarithmic Functions

In your calculus text, you will learn how to evaluate integrals using different techniques.  In Mathematica, we do not need to specify the technique.  It chooses the technique appropriate for the problem. However, there are some integrals that cannot be evaluated in terms of elementary functions. In such cases, Mathematica will return the integal unevaluated or gives us a name for the integral.

Below, we will consider some examples of integrals that involve trigonometric functions, exponential, and logarithmic functions.  If done by hand, some of these integrals require integration by parts, partial fraction decompositions, or trigonometric substitutions.

Example 5.13.  Evaluate ∫((x^2)/((((x^3)+1))^2))dx.

Solution: If done by hand, this integral involves using the substitution method.

Integrate[x^2/(x^3+1)^2,x]

Example 5.14.   Evaluate ∫(((x^5)+(x^2)+x+2)/((x^2)-1))dx.

Solution:  This integral involves long division and partial fraction decomposition.

∫(((x^5)+(x^2)+x+2 )/((x^2)-1))\[DifferentialD]x

Example 5.15.   Evaluate ∫(((x^4)+(x^3)+x+1)/((((x^2)+1))^2))dx.

Solution:  This integral involves long division, partial fraction decomposition, and inverse trigonometric functions.

∫(((x^4)+(x^3)+x+1 )/((((x^2)+1))^2))\[DifferentialD]x

NOTE: All functions that appear as output are written in Mathematica's notation. To convert the output to a more familiar form the command TraditionalForm can be used.  Here is the "traditional" form of the output below (note that log x means the same as ln x in this case).

∫(((x^4)+(x^3)+x+1 )/((((x^2)+1))^2))\[DifferentialD]x//TraditionalForm

Example 5.16.  Evaluate ∫(x^2)sin xdx.

Solution:  This integral involves integration by parts (twice).

∫(x^2) Sin[x]\[DifferentialD]x

Example 5.17.  Evaluate ∫((-1)/(Sqrt[1-(x^2)]))dx.

Solution:  This integral involves trigonometric substitution.

Integrate[-1/Sqrt[1-x^2],x]

NOTE: Your calculus textbook may give arccos x for the answer, as opposed to -arcsin x as above. Can you explain how the integration constant resolves the difference in these two answers?

Here are some examples of integrals that are important in applications but do not have an elementary antiderivative.

∫ Sin[(x^2)]\[DifferentialD]x

∫ (E^(-(x^2)))\[DifferentialD]x

Integrate[Sin[x]/x,x]

We can use NIntegrate to evaluate these integrals over any finite interval. For example:

NIntegrate[(E^(-(x^2))),{x,0,10}]

NIntegrate[Log[x]/x,{x,2,100}]

Example 5.18.  Let (Subscript[f, n])(x)=(∫_1^x)(t^n)dt . Investigate the limit graphically by plotting (Subscript[f, n])(x) for n = 0, –0 .3, –0 .6, and –0 .9 together with g(x)=ln x on a single plot.

Clear[f,g]
g[x_]:=Log[x]
f[x_,n_]:=(∫_1^x)(t^n)\[DifferentialD]t

Plot[{f[x,n]/.n->  {0,-0.3,-.6,-.9},g[x]},{x,0,10},PlotStyle->{Red,Blue}]

Exercises

In Exercises 1 though 5, evaluate the given integral.
1. ∫x(Sqrt[2-x])dx		2. ∫(x^3)(Sqrt[1+(x^2)])dx		3. ∫(tan^2)x (sec^4)xdx		
4. ∫(((x^2)-2x-1)/((x^3)+x))dx		5. ∫((x-1)/(Sqrt[(x^2)+x-1]))dx

In Exercises 6 through 11, use various values of a, b, and n to evaluate the  given integral. Then make a conjecture for a general formula and prove your conjecture. 
6. ∫(1/((x+a)(x+b)))dx	7. ∫cos (a x) sin(b x) dx		8. ∫(x^n)ln xdx
	
9. ∫(x^n)(e^x)dx		10. ∫(x^n)sin(x)dx			11. ∫(e^(a x))cos(b x)dx

Chapter 6 	Applications of the Integral

Evaluating integrals can be tedious and difficult.  Mathematica makes this work relatively easy.  For example, when computing the area of a region the corresponding integral can be difficult to set up because the limits of integration are not known.  Mathematica, with its powerful plotting capability, can turn this job into a very doable one.  We will examine several applications that demonstrate this.

6.1  Area Between Curves

Students should read Section 6.1 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

Let us consider the problem of finding the area between two curves.

Example 6.1. Determine the area of the region bounded between the curves f(x)=sin x and g(x)=(csc^2)x on [π/4,3π/4].

Solution: To find the area here, we first plot the graphs of f and g.

Clear[f, g]

f[x_] := Sin[x]  
 g[x_] := Csc[x]^2

Plot[{f[x],g[x]}, {x, π/4, 3π/4},
PlotStyle -> {Red, Blue}, PlotRange -> {-.5, 2.5},
Filling -> {1 ->{ 2}}]

Looking at the plot above and recalling that csc x is always greater than or equal to 1 on this interval, it follows that (csc^2) x is always greater than or equal to sin x, which is less than or equal to 1 on the same interval.  Hence, calculating the area between these two curves between x=π/4 and x=3π/4 is straightforward:

(∫_(π/4)^(3π/4))(g[x] - f[x])\[DifferentialD]x

N[%]

Example 6.2. Determine the area of the region enclosed between the curves f(x)=x((x^2)-3x+3) and g(x)=(x^2).

Solution: To find the area between these two curves, we will need to see if they intersect and if so where by plotting their graphs.

Clear[f,g, x]

f[x_] := x ((x^2) - 3 x + 3)

g[x_] := (x^2)

Plot[{f[x],g[x]}, {x, -2, 4},
PlotStyle -> {Red, Blue}, PlotRange -> {-2, 11},
Filling -> {1 ->{ 2}}]

Notice that f(x) is graphed in red, while g(x) is graphed in blue.  Also, the "Filling" option in the Plot command fills in the region between the two graphs (functions 1 and 2 in the Filling command) in gray.  The bounded region between the two curves seems to lie between x=0 and x=3.  To ascertain this, we solve for the intersection points:

Solve[ f[x] == g[x], x]

Hence, the intersection points are at x =0,1, and 3.  Noting that f(x) is greater than g(x) on [0, 1] and g(x) is greater than f(x) on [1, 3], we need two integrals to calculate the (physical) area between the two curves since areas are always calculated by subtracting the smaller function from the larger one.  In particular, on [0,1] the area is given by (∫_0^1)[f(x)-g(x)]dx and on [1,3] the area is given by (∫_1^3)[g(x)-f(x)]dx.

(∫_0^1)(f[x] - g[x])\[DifferentialD]x  +  (∫_1^3)(g[x] -f[x])\[DifferentialD]x

N[%]

Example 6.3. Determine the area of the region bounded between the curves f(x)=|x| and g(x)=cos x on [-π/2,π/2].

Solution: To find the area here, we first plot the graphs of f and g.

Clear[f, g]

f[x_] := Abs[x]
g[x_] := Cos[x]

Plot[{f[x],g[x]}, {x, -π/2, π/2},
PlotStyle -> {Red, Blue}, PlotRange -> {-1, 2},
Filling -> {1 ->{ 2}}]

From the picture above, we will need to consider the total area as a sum of three separate regions.  To this end, we first find the intersection points of these two curves in order to obtain the limits of integration. Make note of the fact that the Solve command does not work here because it is only able to solve algebraic equations. Instead, we use the FindRoot command to solve the equation f(x)-g(x)=0 using an initial guess of x=0.75 (based on the plot above):

FindRoot[f[x]-g[x], {x, 0.75}]

Thus our root is approximately x=0.739085.  By symmetry we see there is another root at x=-0.739085.  Hence, the area between these two curves is the sum of the three integrals:

(∫_(-π/2)^(-0.739085))(f[x] - g[x])\[DifferentialD]x+(∫_(-0.739085)^0.739085)(g[x] - f[x])\[DifferentialD]x +(∫_0.739085^(π/2))(f[x] - g[x])\[DifferentialD]x

Hence the area of our bounded region is 2.06936.

NOTE: Observe that our region is symmetric about the y-axis and thus the same answer could have been found by computing the area of only half the region (the right half, say) and doubling the result.

Exercises

1.  Find the area between the curves y = sin x and y = sin(2x) between x=0 and x=π.

2.  Find the area between the graphs of x = sin y and x = 1 - cos y between y=0 and y=π/2.

3.  Find the area above y = 1 - x/π and below y = sin x.

6.2  Average Value

Students should read Sections 6.2 and 6.3 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

Remember that the average value of a function f(x) on [a,b] is defined as

(Subscript[f, ave])=(1/(b-a))(∫_a^b)f(x)dx.

Related to this notion is the Mean Value Theorem for Integrals (MVTI), which states that for any continuous function f(x) on [a,b] there exists a value c∈[a,b] such that

f(c)=(Subscript[f, ave]).

Example 6.4. Let f(x)=2cos x-x.
a) Find the only positive root α of f.
b) Calculate the average value of f on [0,α].
c) Determine a value c that satisfies the Mean Value Theorem for Integrals on [0,α].

Solution: 
a) To calculate α, we first plot the graph of f and then use the FindRoot command with x=1 as our initial guess:

Clear[f]

f[x_] := 2 Cos[x] -x

Plot[f[x], {x, -π, π}]

root=FindRoot[f[x], {x, 1}]

Therefore,  α = 1.02987 accurate to 5 decimal places.

b) We next calculate the average value of f on [0,α]:

α = root[[1,2]]

fave = (1/(α-0)) (∫_0^α)f[x]\[DifferentialD]x

Thus, the average value is approximately (Subscript[f, ave])=1.14981.

c) By MVTI, there exists a value c∈[0,α] such that f(c)=(Subscript[f, ave]).  To find c, we solve this equation for c, or equivalently,

f(c)-(Subscript[f, ave])=0.

FindRoot[f[c]-fave, {c, .5}]

Exercises

1.  Which of f(x)= x (sin^2)x and g(x) = (x^2) (sin^2)x has a larger average value over [0,2]?  Over [2,4]?

2.  Let (Subscript[f, ave]) denote the average value of f(x)= (x^3) + (x^2)+ 5 on [0,4].  Find a value for c inside [0,4] such that f(c) = (Subscript[f, ave]).

6.3  Volume of Solids of Revolution

Students should read Sections 6.2-6.4 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

We recall that a definite integral can be evaluated by employing the definition

(∫_a^b)f(x)dx=(Underscript[lim , n->+∞])[(∑_(i=1)^n)f((Subscript[x, i]^( * )))Δ (Subscript[x, i])].

Another application of the definite integral involves finding the volume of a solid of revolution, that is, a solid obtained by revolving a region in the plane about one of the coordinate axes.

6.3.1  The Method of Discs

Let S be a solid of revolution obtained by revolving the region bounded by the graphs of y=f(x), y=0, and the vertical lines x = a and x = b, about the x-axis.  To obtain the volume of S, we can approximate S by discs, i.e., cylinders obtained by revolving each rectangle, constructed by a Riemann sum of f relative to a partition P={(Subscript[x, 0]), (Subscript[x, 1]), (Subscript[x, 2]), .... , (Subscript[x, n])} of [a,b], about the x-axis.   Using the fact that the volume of a cylinder with radius R and height h is given by

V=π (R^2) h,

it follows that the volume of the ith cylinder (corresponding to the ith rectangle) is (Subscript[V, i])=((π[f((Subscript[x, i]^( * )))])^2)Δ x.  Hence, an approximation to the volume of S is given by the Riemann sum

Vol(S)≈(∑_(i=1)^n)(Subscript[V, i])=π(∑_(i=1)^n)(([f((Subscript[x, i]^( * )))])^2)Δ x.

In the limit as n->∞, we obtain the exact volume of S:

Vol(S)=π (lim_(n->∞))(∑_(i=1)^n)(([f((Subscript[x, i]^( * )))])^2)Δ x=π(∫_a^b)(([f(x)])^2)dx.

NOTE: If the region is revolved about the y-axis, then the volume of S is given by

Vol(S)=π(∫_c^d)(([f(y)])^2)dy.

Example 6.5. Find the volume of the solid of revolution obtained by rotating the region bounded by the graph of f(x)=(Sqrt[x]), the x-axis, and the vertical line x=3.

Solution: We define f(x) in Mathematica and illustrate both the region and rectangles that are rotated to obtain the solid and discs, respectively.  For this, we recall our program from Chapter 5 of this manual that was used to draw these rectangles.

LEPT[f_,{a_,b_,n_}]:=Module[
{dx, k, xstar, lrect, plot},
dx=N[(b-a)/n];
xstar=Table[a+i* dx, {i,0,n}]; 
lrect=Table[Line[{{xstar[[i]],0},{xstar[[i]],f[xstar[[i]]] }, {xstar[[i+1]],f[xstar[[i]]] }, {xstar[[i+1]],0}}],{i,1,n}];
plot=Plot[f[x],{x,a,b},Filling ->Axis];
Show[plot,Graphics[{Green,lrect}]]
]

f[x_]:=(Sqrt[x])
plot=LEPT[f,{0,3,20}]

The plot above shows our region shaded in gray and our rectangles outlined in green.  We now rotate this shaded region about the x-axis to obtain a solid of revolution called a paraboloid.  This is achieved in Mathematica using the RevolutionPlot3D[{f,x},{x,a,b}] command, which generates a surface of revolution having radius f at height x.  This means that the vertical axis shown in the plot below is actually the x-axis.

S=RevolutionPlot3D[{(Sqrt[x]),x},{x,0,3}]

The exact volume of the paraboloid is then given by

V=π(∫_0^3)(((f[x]))^2)\[DifferentialD]x

6.3.2  The Method of Washers

For a solid of revolution S generated by revolving a region bounded between two curves f(x) and g(x) on [a,b] about the x-axis, we employ washers (rings) instead of discs.  Refer to your calculus textbook for a detailed treatment.  The corresponding volume of S is given by (let's assume g(x)≥f(x))

Vol(S)=π(∫_a^b){(([g(x)])^2)-(([f(x)])^2)}dx.

Example 6.6. Find the volume of the solid generated by revolving about the x-axis the region enclosed by the parabola y=(x^2)+1 and the straight line y=x+3.

Solution:   Our initial goal is to find the points of intersection and secure the limits of integration.

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

Plot[{f[x],g[x]},{x,-2,4},PlotStyle->{Red,Blue},PlotRange->{-2,8},Filling->{1->{2}}]

We notice that f(x) is graphed in red, while g(x)  is graphed in blue.  The following command solves for their intersection points:

Solve[f[x]==g[x],x]

One can easily verify that the intersection points are (-1, 2) and (2, 5).  Thus, our limits of integration are x=-1 and x=2.

Let P and Q denote the solids of revolution by revolving each of the regions lying under f and g, respectively, along the interval [-1,2].  Our solid S, obtained by rotating the region between f and g on [-1,2] about the x-axis, can then be viewed as the difference of Q and P, i.e., the solid Q with the solid P removed from it.  Following are surface plots of the three solids P, Q, and S. Again, note that the vertical axis shown in each of the plots below is actually the x-axis.

P=RevolutionPlot3D[{f[x],x},{x,-1,2},AspectRatio->Automatic]
Q=RevolutionPlot3D[{g[x],x},{x,-1,2},AspectRatio->Automatic]

S=Show[P,Q]

Since the curve  y=f(x)=x+3 is lower than the curve  y=g(x)=(x^2)+1, it follows that the volume of S is given by

V=π(∫_(-1)^2)((((g[x]))^2)-(((f[x]))^2))\[DifferentialD]x

Observe that in the above discussion, the methods for calculating volumes of solids of revolution were via discs and washers.  In other words, the element of volume is obtained by taking the rectangular element of area whose height is perpendicular to the axis of revolution and revolving it to construct a disc or washer.

6.3.3  The Method of Cylindrical Shells

Students should read Section 6.4 of Rogawski's Calculus [1] for a detailed discussion of the material presented in this section.

Another approach to finding the volume of a solid of revolution is to approximate it using cylindrical shells in contrast to discs (or washers).  Recall that a cylindrical shell element is one that is obtained by revolving a rectangular element of area whose height is parallel to the axis of revolution.

A cylindrical shell is by definition a solid contained between two concentric cylinders having the same axis of rotation.  Suppose a cylindrical shell has inner radius (Subscript[r, 1]), outer radius (Subscript[r, 2]), and altitude h, then its volume V is given by

V=π  (Subscript[r, 2]^( 2))h-π  (Subscript[r, 1]^( 2))h=2π h((((Subscript[r, 2])+(Subscript[r, 1]))/2))((Subscript[r, 2])-(Subscript[r, 1]))=2π (OverBar[r]) h Δ x,

where (OverBar[r])=((Subscript[r, 2])+(Subscript[r, 1]))/2 is the average radius and Δ x=(Subscript[r, 2])-(Subscript[r, 1]).

Let S denote denote the solid obtained by revolving the region bounded between a function f(x), the x-axis, x=a, and x=b, about the y-axis.  The volume of the ith shell corresponding to the ith rectangle is defined to be (Subscript[V, i])=2π (Subscript[x, i]^( * ))f((Subscript[x, i]^( * )))Δ x, where (Subscript[x, i]^( * ))=((Subscript[x, i])+(Subscript[x, i-1]))/2.  Hence, an approximation to the volume of S is given by the Riemann sum

Vol(S)≈(∑_(i=1)^n)(Subscript[V, i])=2π(∑_(i=1)^n)(Subscript[x, i]^( * ))f((Subscript[x, i]^( * )))Δ x.

In the limit as n->∞, we obtain the exact volume of S:

Vol(S)=2π (lim_(n->∞))(∑_(i=1)^n)(Subscript[x, i]^( * ))f((Subscript[x, i]^( * )))Δ x=2π(∫_a^b)x f(x)dx.

NOTE: If the region is revolved about the x-axis using cylindrical shells, then the volume of S is given by

Vol(S)=2π(∫_c^d)y f(y)dy.

Example 6.7.  Consider the region bounded by the curve y=(x^2), the x-axis, and the line x = 2.  Find the volume of the solid generated by revolving this region about the y-axis using the method of cylindrical shells.

Solution: Let us first plot the region bounded by the given curves (shaded in the plot below):

f[x_]=x^2;
Plot[f[x],{x,0,2},Filling ->Axis]

We then revolve this shaded region about the y-axis to obtain our solid S (parabolic bowl).  This can be seen in the three plots following, which illustrate S as the difference of the solids Q (cylinder) and P (paraboloid), that is, Q with P removed from it.

P=RevolutionPlot3D[{f[x]} ,{x,0,2}]
Q=RevolutionPlot3D[{{2,y}} ,{y,0,4}]

S=Show[P,Q]

The volume of S is given by

V= 2π(∫_0^2)x*f[x]\[DifferentialD]x

NOTE: The volume in this example can also be calculated using the washer method.  However, one would first have to solve the equation y=(x^2) for x, yielding  x=(Sqrt[y]).  Moreover, the limits of integration (with respect to y) would have to be determined, which in this case would be y = 0 and y = 4 corresponding to x = 0 and x = 2, respectively.  Hence,

V= π(∫_0^4)((2^2)-((((Sqrt[y])))^2))\[DifferentialD]y

The two answers from both methods agree as they should.

Example 6.8.  Sketch the ellipse  ((x^2)/(a^2))+((y^2)/(b^2))=1 and find the volume of the solid obtained by revolving the region enclosed by the ellipse about the x-axis.

Solution: We will use the ContourPlot command to plot the ellipse for a=2 and b=3.  The reader should experiment with other values of a and b.

a=2;
b=3;
ContourPlot[((x^2)/(a^2))+((y^2)/(b^2))==1, {x,-a-1,a+1}, {y, -b-1,b+1},AspectRatio->Automatic, Axes->True,Frame->False]

To plot the corresponding solid of revolution (ellipsoid), we first solve ((x^2)/(a^2))+((y^2)/(b^2))=1 for y.

Clear[a,b]
 sol=Solve[((x^2)/(a^2))+((y^2)/(b^2))==1,y]

The positive and negative solutions above correspond to the upper half and lower half, respectively, of the ellipse.  We shall consider the upper half in plotting the ellipsoid and computing its volume by defining

f(x)=(Sqrt[(b^2)-(((b^2) (x^2))/(a^2))])=b(Sqrt[1-(( (x^2))/(a^2))]).

f[x_]=sol[[2,1,2]]

Here is a plot of S (rotated 90 degrees about the x-axis).

a=2;
b=3;
RevolutionPlot3D[{f[x],x} ,{x,-a,a}]

To find the volume of the ellipsoid, we can employ either method, disc or shell, but in this case the disc method is preferable from a computational standard.  This is because the disc formula for volume contains the square term (([f(x)])^2), which lets us avoid having to deal with radical terms if the shell method were used.  Since the ellipsoid is defined along the integral [-a,a], its volume based on the disc method is therefore

V= π(∫_(-a)^a)(((f[x]))^2)\[DifferentialD]x

More generally, the volume of the ellipsoid for arbitrary positive values of a and b is given by

Clear[a,b]
V= π(∫_(-a)^a)(((f[x]))^2)\[DifferentialD]x

Thus, V=(4/3)π a (b^2).

NOTE: If we let a=b, then the ellipsoid becomes a sphere and the formula above reduces to the classic formula V=(4/3)π (a^3), where a is the radius of the sphere.

Exercises

1.  Plot the solid of revolution obtained by rotating the region enclosed by the graphs about the given axis and calculate its volume.
a)  y=(9/(x^2)), y=10-(x^2) about the x-axis
b) y=16-(x^4), y=0, x=2, x=3 about the y-axis

2.  Plot the hypocycloid (x^(2/3))+(y^(2/3))=1 and find the volume of the solid obtained by revolving the region enclosed by the hypocycloid about the y-axis. Is the volume of the solid obtained by revolving the same region about the x-axis the same?  Justify your answer.  (Hint: Use the ContourPlot command.)

3. Use the Shell Method to find the volume of the solid obtained by rotating the region enclosed by the graphs in each part below about the y-axis.
a)   y=(x^2), y=8-(x^2), and x=0
b) y=(1/2)(x^2)and y=sin((x^2))

4. The solid generated by revolving the region between the two branches of the hyperbola (y^2)-(x^2)=1 from x=-a to x=a about the x-axis is called a hyperboloid.  Find the volume of the hyperboloid for a=2 and then for any arbitrary value of a.