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.

Chapter 7	Techniques of Integration

7.1  Numerical Integration

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

Numerical integration is the process of approximating a definite integral using appropriate sums of function values.  We already saw in Chapter 5 of this text formulas for Right, Left, and Midpoint Rules and their subroutines LRSUM, RRSUM, and MRSUM, respectively.  In this section, we will develop two additional rules: the Trapezoidal Rule and Simpson’s Rule.

7.1.1  Trapezoidal Rule

The Trapezoidal Rule approximates the definite integral (∫_a^b)f(x)dx by using areas of trapezoids and is given by the formula:

(Subscript[T, n])  =  .5 ((b-a)/n )((Subscript[y, 0]) +2(Subscript[y, 1]) + ...  + 2(Subscript[y, n-1]) + (Subscript[y, n]))

where n is the number of trapezoids and (Subscript[y, i])=f(a+i (b-a)/n) .  This formula can be found in your calculus text.  Here is a Mathematica subroutine, called TRAP, for implementing the Trapezoidal Rule:

Clear[f,a,b,n]

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

Example 7.1.  Calculate the area under the function f(x)=(x^2) on [0,1] using the Trapezoidal Rule for various values of n.

Solution: The following output gives a table of approximations of (∫_0^1)(x^2)dx based on the Trapezoidal Rule for n=10,20,...,100.

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

It is clear that these values are converging to 1/3, which is the exact value of our definite integral:

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

7.1.2  Simpson’s Rule

One difference between Simpson’s Rule and all the other rules we have developed so far (TRAP, LRSUM, RRSUM, and MRSUM) is that the number of partition points, n, in this case, must be even.  The other difference is that Simpson’s Rule is a quadratic approximation based on parabolas, whereas the other rules are linear approximations based on lines.  The formula for Simpson’s Rule is given by (refer to your calculus text for details):

(Subscript[S, n])= (1/3) [(Subscript[y, 0])+ 4(Subscript[y, 1])+2(Subscript[y, 2])+4(Subscript[y, 3])+2(Subscript[y, 4])+...+4(Subscript[y, n-3])+2(Subscript[y, n-2])+4(Subscript[y, n-1])+(Subscript[y, n])] (b-a)/n
     =(1/3)[((Subscript[y, 0])+ 4(Subscript[y, 1])+(Subscript[y, 2]))+((Subscript[y, 2])+4(Subscript[y, 3])+(Subscript[y, 4]))+...+((Subscript[y, n-2])+4(Subscript[y, n-1])+(Subscript[y, n]))] (b-a)/n

where (Subscript[y, i])=f(a+i (b-a)/n).  Here is a Mathematica subroutine, called SIMP, for implementing Simpson’s Rule:

Clear[a,b,n]

SIMP[a_,b_,n_] := (1/3)Sum[f[a + (2 i -2)(b-a)/n] + 4 f[a + (2i-1)(b-a)/n] + f[a + 2i (b-a)/n],{i, 1, n/2}] (b-a)/n

Example 7.2.  Calculate the area under the function f(x)=(x^2) on [0,1] using Simpson’s Rule for various values of n.

Solution: We use the same set of values of n as in the previous example.  This will allow us to compare Simpson’s Rule with the Trapezoidal Rule.

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

Notice how fast SIMP converges to the actual value of the integral (1/3) compared to TRAP.

Example 7.3.  Calculate the definite integral of f(x)=sin(25(x^2)) on [0,1] using Simpson’s Rule and approximate it to five decimal places.  What is the minimum number of partition points needed to obtain this level of accuracy?

Solution: We first evaluate SIMP using values for n in increments of 20.

f[x_]:=Sin[25(x^2)]
TableForm[Table[{n,N[SIMP[0,1,n]]},{n,20,200,20}], TableHeadings-> {{},{"n", " (Subscript[s, n])"}}]

Based on the output our approximation, accurate to five decimal places, is 0.10558.  This first occurs between n=100 to n=120.  We evaluate SIMP inside this range to zoom in on the minimum number of partition points needed.

f[x_]:=Sin[25(x^2)]
TableForm[Table[{n,N[SIMP[0,1,n]]},{n,100,120,2}], TableHeadings-> {{},{"n", " (Subscript[s, n])"}}]

Thus, we see that the minimum number of points needed is n=116.  How does this compare with the minimum number of points needed by TRAP to obtain the same level of accuracy?

NOTE: Observe that SIMP does not converge as fast in this example as in the previous example.  This is because the function f(x)=sin(25(x^2)) is oscillatory as the following graph demonstrates:

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

Try increasing the frequency of this function, say to sin(100(x^2)), to see how well SIMP performs.

7.1.3  Midpoint Rule

Since most calculus texts include again the Midpoint Rule in the section on numerical integration, for completeness, we will too.  The Riemann sum using the midpoints of each subinterval is given by the following formula:

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

Example 7.4.  Calculate the area under the function f(x)=(x^2) on [0,1] using the Midpoint Rule for various values of n.

Solution:

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

Exercises

1. Consider the definite integral (∫_1^2)ln(x)dx.
a) Using the Trapezoidal Rule, Simpson's Rule, and Midpoint Rule, approximate this integral for n=10,20,...,100.
b) Compare how fast each subroutine (TRAP, SIMP, MRSUM) converges to (∫_a^b)ln(x)dx and decide which of these rules is "best."

2. Repeat Exercise 1 for the following definite integrals:
a)  (∫_0^2)((e^x)/(x+1))dx   		b)  (∫_0^1)cos((x^2))dx		c)  (∫_0^1)(e^(x^2))dx		
Can you make any general conclusions about which rule (Trapezoidal, Simpson’s, Midpoint) is best?

3.  For each of the functions given below, set up a definite integral for the volume of the solid of revolution obtained by revolving the region under f(x) along the given interval and about the given axis.  Then use the subroutines TRAP, SIMP, and MRSUM to approximate the volume of each solid accurate to two decimal places (use various values of n to obtain the desired accuracy).
a) f(x) = cos x;    [0, π/2];    x-axis           b) f(x) = (e^(-(x^2)));    [0,1];   y-axis	c) f(x)=sin x,  [0,π], x-axis

7.2  Techniques of Integration

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

All calculus texts have at least a chapter devoted to "Techniques of Integration."  When using Mathematica, these techniques are usually not necessary since Mathematica automatically gives you the answer.

7.2.1 Substitution

On occasion, we do need to use techniques of integration, even when using Mathematica.

Example 7.5.  Evaluate the following integral: ∫(2^x)(Sqrt[((((2^x)))^2)-1])dx.

Solution: We evaluate this integral in Mathematica:

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

To students in a first-year calculus course, this answer makes no sense.  There are many integrals that Mathematica cannot evaluate at all, or cannot evaluate in terms of elementary functions (such as the integral above).  Some of these integrals are doable in terms we should understand, once we first use an appropriate technique of integration. In the above example, all we need to do is first make the following substitution:  u = (2^x)  and d u = (ln 2) (2^x) d x, which transforms the integral to:

(1/(Log[2]))∫(Sqrt[(u^2)-1])\[DifferentialD]u

This is the correct answer.  All we need to do is substitute (2^x) for u, and add the arbitrary constant of integration, getting:
(1/(2 Log[2]))( (2^x)(Sqrt[-1 + ((((2^x)))^2)]) - Log[(2^x) + (Sqrt[-1 + ((((2^x)))^2)])] ) + C
Note that the Mathematica function Log[x] is equivalent to the standard form ln x.

7.2.2 Trigonometric Substitution

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

Solution: By hand, the integral ∫(1/((x^2)(Sqrt[(x^2)-9])))dx would normally be evaluated with a trigonometric substitution of the form x=3secθ.  But with Mathematica, we can do this directly:

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

This, of course, is the correct answer, when we remember that Mathematica does not add an arbitrary constant to indefinite integrals.

7.2.3 Method of Partial Fractions

Integrals of rational expressions often require the Method of Partial Fraction Decomposition to evaluate them (by hand).  For example:

∫((3x-3)/((x^2)+5x+4))dx=∫((5/(x+4))-(2/(x+1)))dx=5ln|x+4|-2ln|x+1|=ln|((((x+4))^5)/(((x+1))^2))|

On the other hand, Mathematica will give us essentially the same answer for this integral, but does its work behind the scenes without revealing its technique:

Simplify[∫((3x-3)/((x^2)+5x+4))\[DifferentialD]x]

If we would like to see the partial fraction decomposition of the integrand, ((3x-3)/((x^2)+5x+4)), Mathematica will also do that for us without strain by using the Apart command:

Apart[((3x-3)/((x^2)+5x+4))]

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

Solution:  We simply evaluate this integral using Mathematica:

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

But again, if we would like to see the partial fraction decomposition of the integrand, ((2(x^3)+(x^2)-2x+2)/((((x^2)+1))^2)), then this is straightforward with Mathematica:

Apart[((2 (x^3)+ (x^2) -2 x + 2)/((((x^2)+ 1))^2))]

Exercises

1.  Evaluate ∫(1+ln(x))(Sqrt[1+(((x ln(x)))^2)])dx with Mathematica. If it doesn't give an understandable answer, use a technique of integration that changes the integral into one that Mathematica will evaluate.

In Exercises 2 through 5, use Mathematica to find the partial fraction decomposition of the given functions and then integrate them:
	2.  (((x^2)+3 x - 44)/((x-3)(x+5)(3x-2)))     		3.  ((3(x^2)-4x+5)/((x-1)((x^2)+1)))     	 4.  (25/(x ((x^2)+2x+5))) 		5.  (10/((x((x^2)+2x+5))^2))

In Exercises 6 through 10, use Mathematica to evaluate the given  integrals.
	6. ∫((x^2)/((((x^2)- 4))^(3/2)))dx		7. ∫(x^3)(Sqrt[9-(x^2)])dx		8. ∫(1/(Sqrt[25+(x^2)]))dx	
	9. ∫(sin^5)xdx			9. ∫(((tan^(-1))t)/(1+(t^2)))dt			10. ∫(sinh^3)x cosh xdx

7.3  Improper Integrals

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

Recall that there are two types of improper integrals.

Type I: If we assume that f(x) is integrable over [a,b] for all b≥a, then the improper integral of f(x) over [a,∞) is defined as
	(∫_a^∞)f(x)dx = (lim_(t-> ∞))(∫_a^t)f(x)dx,
provided this limit exists.  Similarly, we define
	(∫_(-∞)^b)f(x)dx = (lim_(t-> -∞))(∫_t^b)f(x)dx,
provided this limit exists.

Type II: If f(x) is continuous on [a,b) but discontinuous at x=b, we define
	(∫_a^b)f(x)dx = (lim_(t-> b-))(∫_a^t)f(x)dx ,
provided this limit exists.  Similarly, if f(x) is continuous on (a,b] but discontinuous at x=a,
	(∫_a^b)f(x)dx = (lim_(t-> a+))(∫_t^b)f(x)dx,
provided this limit exists.  Finally, if f(x) is continuous for all x on [a,b] except at x=c, where a<c<b, we define
	(∫_a^b)f(x)dx=(lim_(t->c-))(∫_a^t)f(x)dx+(lim_(t->c+))(∫_t^b)f(x)dx,
provided both of these limits exist.

By using the Limit command in Mathematica along with Integrate, Mathematica eliminates the drudgery of having to evaluate these integrals by hand.

Example 7.8.  Evaluate the following improper integrals:
a)  (∫_20^∞)(1/y)dy
b) (∫_2^∞)(e^(-2x))dx
c) (∫_0^1)x ln xdx
d) (∫_(-∞)^∞)(1/(1+(x^2)))dx

Solution:

a)  We evaluate

(∫_20^∞)(1/y)\[DifferentialD]y

Thus, evaluating this integral directly using Mathematica tells us it does not exist.  Alternatively, we could have used the limit definition:

Limit[(∫_20^t)(1/y)\[DifferentialD]y,t-> ∞]

Observe the difference in the two outputs above.  Both correctly express the answer as divergent; however, the second answer is better since it reveals the nature of the divergence (infinity), which is the answer we would expect if solving this problem by hand.

b)  We evaluate

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

Again, we obtain the same answer using the limit definition (as it should):

Limit[(∫_2^t)(E^(-2x))\[DifferentialD]x , t-> ∞]

Mathematica will similarly handle discontinuities. In the following example, the function has a discontinuity at x = 0.

c) We evaluate

(∫_0^1)x Log[x]\[DifferentialD]x

Limit[(∫_t^1)x Log[x]\[DifferentialD]x, t-> 0, Direction->-1]

d)  We evaluate

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

Note that Mathematica does not require us to break the integral up into two integrals, which would be required according to its definition, if evaluated by hand.  On the other hand, there is nothing wrong with dividing this integral into two in Mathematica:

(∫_(-∞)^0)(1/(1+(x^2)))\[DifferentialD]x + (∫_0^∞)(1/(1+(x^2)))\[DifferentialD]x

NOTE: Observe that it does not matter where we divide the integral.  It is valid to express (∫_(-∞)^a)(1/(1+(x^2)))dx+(∫_a^∞)(1/(1+(x^2)))dx for the integral  (∫_(-∞)^∞)(1/(1+(x^2)))dx for any real value a as long as they are convergent.  However, evaluating this sum in Mathematica yields different expressions for the answer, which depend on the sign of a and whether it is real or complex.  This is shown in the following output:

Clear[a]
(∫_(-∞)^a)(1/(1+(x^2)))\[DifferentialD]x + (∫_a^∞)(1/(1+(x^2)))\[DifferentialD]x

If instead, a is given a fixed value, then Mathematica will give us our answer of π:

a=1
(∫_(-∞)^a)(1/(1+(x^2)))\[DifferentialD]x + (∫_a^∞)(1/(1+(x^2)))\[DifferentialD]x

Exercises

In Excercises 1 through 8, evaluate the given improper integrals:
1.  (∫_(-∞)^4)(e^(.01 t))dt 		2.  (∫_(-3)^∞)(1/(((x+4))^(3/2)))dx 		3.  (∫_(-2)^4)(1/(((x+2))^(1/3)))dx 		4.  (∫_(-∞)^∞)x (e^(-(x^2)))dx		
5. (∫_0^3)(1/(x-1))dx			6. (∫_(-∞)^∞)(1/((e^x)+(e^(-x))))dx		7. (∫_1^∞)(1/(x^(.999)))dx			8.  (∫_1^∞)(1/(x^1.003))dx

11.  Find the volume of the solid obtained by rotating the region below the graph of  y=(e^(-x)) about the x-axis for  0≤x<∞.

12.  Determine how large the number b has to be in order that   (∫_b^∞)(1/((x^2)+1))dx <  .0001.

13. Evaluate the improper integral (∫_(-1)^1)(1/(|(x^(1/3))|))dx.

14.  Determine how large the number b should be so that  (∫_b^∞)(1/((x^2)+1))dx   <   .0001.

15. Consider the function defined by

G(x)=(∫_0^∞)(t^(x-1))(e^(-t))dt

a)  Evaluate G(n)  for n=0, 2,,3, 4, ...., 10.  Make  a conjecture about these values.  Verify your conjecture.
b) Evaluate G((2n-1)/2), for n=1, 2, 3, ... 10.  Make a conjecture about these values.  Verify your conjecture.
c) Plot the graph of G(x) on the interval [0, 5].

NOTE: The function G is called the gamma function and is denoted by Γ[x]. In Mathematica it is denoted by Gamma[x].   The gamma function was first introduced by Euler as a generalization of the factorial function.

7.4  Hyperbolic and Inverse Hyperbolic Functions

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

7.4.1. Hyperbolic Functions

The hyperbolic functions are defined in terms of the exponential functions.  They have a direct connection to engineering mathematics, including bridge construction.  For example, cables from suspension bridges typically form a curve called a catenary (derived from the Latin word catena, which means chain) that is described by these functions.

The six hyperbolic functions are denoted and defined as follows:

sinh x =(((e^x)- (e^(-x)))/2), 	 cosh x=(((e^x)+ (e^(-x)))/2),	tanh x=(((e^x)- (e^(-x)))/((e^x)+ (e^(-x))))

coth x =(((e^x)+ (e^(-x)))/((e^x)- (e^(-x)))), 	 sech x=(2/((e^x)+ (e^(-x)))),	csch x=(2/((e^x)- (e^(-x))))

The reason these functions are called hyperbolic functions is due to their connection with the equilateral hyperbola (x^2)-(y^2)=1.  Here, one defines x=cosh t and y=sinh t.  Hence, one obtains the basic hyperbolic identity (cosh^2)t-(sinh^2)t=1, much the same manner as the corresponding trigonometric identity (cos^2)t+(sin^2)t=1, when one considers the unit circle (x^2)+(y^2)=1 with x=cos t and y=sin t.

In Mathematica, we use the same notation with the obvious convention that the first letter of each function is capitalized and square brackets must be used in place of parentheses.  Thus, sinh x will be entered as Sinh[x].

Example 7.9.  Consider the hyperbolic sine function f(x)=sinh x.
a) Plot the graph of f. 
b) From the graphs deduce the domain and range of the function. 
c) Is f bounded? 
d) Does f attain an absolute minimum? Maximum?
e) Repeat a) through d) for the hyperbolic function g(x)=cosh x  
f) Repeat a) through d) for the hyperbolic function h(x)=tanh x.

Solution: We begin by defining f in Mathematica:

Clear[f,x]
f[x_]=Sinh[x]

a) We next plot its graph on the interval [-3,3].

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

b) The preceding graph indicates that the domain and range of sinh x is (-∞,∞). To convince yourself, you should plot the graph over wider intervals.  We should also expect this from the definition of sinh x itself.  Can you explain why?

c) The function sinh x is not bounded. The graph earlier should not be used as a proof of this.  However, we can evaluate its limit at -∞ and ∞ to see that this is indeed true.

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

d) The limits just computed show that sinh x has no absolute maximum or minimum since it is unbounded.

e) Next, we consider the hyperbolic cosine function denoted by cosh x.

Clear[g,x]
g[x_]=Cosh[x]

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

The preceding graph indicates that the domain of cosh x is (-∞,∞). The range appears to be  [1,∞). Can you prove this?

The hyperbolic cosine function, cosh x, is not bounded from above. This can be seen from the following limits:

Limit[Cosh[x],x->-∞]
Limit[Cosh[x],x->∞]

Again, since cosh x is not bounded from above, it follows that cosh x has no absolute maximum. As we have observed in part b) of this example, cosh x has absolute minimum value 1, attained at x=0.

f) Finally, we consider the hyperbolic tangent function, tanh x:

Clear[h,x]
h[x_]=Tanh[x]

Plot[h[x],{x,-3,3}]

Again, the preceding graph indicates that the domain of tanh x is (-∞,∞). The range appears to be  (-1,1). This can be seen from the following limits:

Limit[Tanh[x],x->-∞]
Limit[Tanh[x],x->∞]

The graph of tanh x also indicates that it is strictly increasing on its domain.  This can be proven by showing that its derivative, which we will calculate later, is strictly positive.  It is clear that tanh x has no absolute extrema.

NOTE: The reader will notice some similarities between the hyperbolic functions and the associated trigonometric functions. Moreover, if one studies the theory of functions of a complex variable, the relationship between these classes of transcendental functions becomes even more transparent; for numerous identities exist between the classes of functions.

7.4.2 Identities Involving Hyperbolic Functions

It is immediate that the ratio and reciprocal identities for the hyperbolic functions coincide with their trigonometric counterparts. In fact, for each trigonometric identity, there is a corresponding (not necessarily the same) hyperbolic identity.  Following are some examples.

Example 7.10.  Show that the following identities hold true.
a) 1-(tanh^2)x=(sech^2)x	b)  cosh(x+y)=cosh x cosh y+sinh x sinh y

Solution:

a) We use the definitions for tanh x and sech x to express each side of the identity in terms of exponentials:

Simplify[(1-((Tanh[x])^2))/.Tanh[x]->(E^x-E^(-x))/(E^x+E^(-x))]

Simplify[((Sech[x])^2)/.Sech[x]->2/(E^x+E^(-x))]

We leave it for the reader to verify that both of these outputs agree, that is, ((4(e^(2x)))/(((1+(e^(2x))))^2))=(4/((((e^(-x))+(e^x)))^2)) (cross-multiply and then simplify).

The identity can also be confirmed in Mathematica by evaluating the difference between its left- and right-hand sides, which should equal zero:

Simplify[1-((Tanh[x])^2)-((Sech[x])^2)]

NOTE: We can also confirm the identity graphically by plotting the graphs of each side of the identity, which should coincide.

Plot[{1-Tanh[x]^2,Sech[x]^2},{x,-2,2}]

b) We again evaluate the difference between the left- and right-hand sides of the identity:

Simplify[Cosh[x+y]-(Cosh[x] Cosh[y]+Sinh[x] Sinh[y])]

7.4.3 Derivatives of Hyperbolic Functions

We next contrast the formulas for the derivatives of the trigonometric functions versus the formulas for the derivatives of the companion hyperbolic functions.

Example 7.11.  Compare the derivatives of the given pair of functions.
a) sinh x and sin x	b)  cosh x and cos x	 c) tanh x and tan x

Solution: We use the derivative command, D, to evaluate derivatives of each pair.

a)

D[Sinh[x],x]
D[Sin[x],x]

b)

D[Cosh[x],x]
D[Cos[x],x]

b)

D[Tanh[x],x]
D[Tan[x],x]

It is clear that derivatives of hyperbolic and trigonometric functions are quite similar.

7.4.4 Inverse Hyperbolic Functions

In light of the fact that hyperbolic functions are defined in terms of the exponential functions, it is readily apparent that the inverse hyperbolic functions are defined in terms of the natural logarithmic function.  The inverses of the hyperbolic functions have notation similar to those of inverse trigonometric functions.  Thus, the inverse of sinh x is denoted by arcsinh x or (sinh^(-1)) x.  In Mathematica, the notation is (sinh^(-1))x is ArcSinh[x].

Example 7.12.  Plot the graphs of (sinh^(-1))x and sinh x on the same axis.

Solution: Recall that the graph of a function and the graph of its inverse are reflections of each other across the line y=x.  This is confirmed by the following plot of (sinh^(-1))x (in blue) and sin x (in red).

Plot[{Sinh[x], x, ArcSinh[x]},{x, -3,3}, PlotStyle->{Blue,Green,Red},AspectRatio->Automatic,PlotRange->{-3,3}]

Example 7.13.  Show that (tanh^(-1))x=(1/2)ln(((1+x)/(1-x))) for -1<x<1.

Solution: We plot the graphs of y=(tanh^(-1))x and y=(1/2)ln(((1+x)/(1-x))) on the same axes. Note that Mathematica's notation of (tanh^(-1))x is ArcTanh [x] and ln y is entered as Log[y]:

Plot[{ArcTanh[x],(1/2)Log[((1+x)/(1-x))]},{x,-2,2}]

The fact that there is only one graph indicates that the functions are the same. We prove this by letting y=(tanh^(-1))x and solving for y as follows.  From y=(tanh^(-1))x we get x=tanh y=(((e^y)-(e^(-y)))/((e^y)+(e^(-y)))).  Now solving this last equation for y in Mathematica yields:

Solve[x==(E^y-E^(-y))/(E^y+E^(-y)),y]

The first solution in the preceding output is imaginary, which we ignore, and consider only the second solution.  Hence,

(tanh^(-1)) x =y=ln((Sqrt[-1-x])/(Sqrt[-1+x]))=ln(Sqrt[((1+x)/(1-x))])=(1/2)ln(((1+x)/(1-x))).

NOTE: The message in the previous output refers to the fact that when solving equations involving inverse functions, not all solutions are necessarily found by Mathematica since there may be infinitely many of them or they depend on the domain of definition.  For example, the equation sin x=1 has infinitely many solutions, in particular all values of the form x=π/2+2π n, where n is any integer.  On the other hand, solving this equation in Mathematica yields only the solution in its principal domain, that is, x=π/2:

Solve[Sin[x]==1,x]

Exercises

In Exercises 1 through 5, verify the given hyperbolic identities using the Simplify command. Also state the corresponding trigonometric identity.

1.  sinh(x+y)=sinh x cosh y+cosh x sinh y 			2.  cosh 2x = (cosh^2)x+(sinh^2)x		3.   tanh 2x=((2 tanh x)/(1+(tanh^2)x)) 
4.  cosh(x+y)=cosh x cosh y + sonh x sinh y		5.  tanh(x+y)=((tanh x+tanh y)/(1+tanh x tanh y))

6.  Determine the first few positive integral powers of cosh x + sinh x. Can you form a general conjecture for the nth case, namely (((cosh x+ sinh x))^n), where n is any natural number?  Then justify your conclusion via mathematical induction.

In Exercises 7 through 12, determine the derivatives of thegiven functions and simplify your answers where possible. Compare your solution via paper and pencil methods with the one generated by Mathematica.

7.  f(x)=tanh (1+(x^2)) 			8.  f(x)=x sinh x - cosh x					9. f(x)=(Sqrt[((1+tanh x)/(1- tanh x))])
10. f(x)=(x^2)(sinh^(-1))(2x)	 		11.  f(x)=x (tanh^(-1))x+ ln ((Sqrt[1-(x^2)]))			12. f(x)=x coth x -sech x

13. The Gateway Arch in St. Louis was designed by Eero Saarinen and was constructed using the equation

y = 211.49 - 20.96 cosh (0.03291765 x)

for the central curve of the arch, where x and y are measured in meters and |x|≤ 91.20.

a) Plot the graph of the central curve.
b) What is the height of the arch at its center?
c) At what points is the arch 100 meters in height?
d) What is the slope of the arch at the points in part (c)?

14.  A flexible cable always hangs in the shape of a catenary y = c + a cosh (x / a), where c and a are constants and a > 0.  Plot several members of the family of functions y = a cosh (x / a) for various values of a.  How does the graph change as a varies?

In Exercises 15 through 17,  evaluate each of the given integrals:

15.  ∫sinh x (cosh^n)xdx			16. ∫((cosh x)/((cosh^2)x-1))dx			17.  ∫(((sech^2)x)/(2+tanh x))dx

18.   Let t=ln(((1+(Sqrt[5]))/2)) and define

f(n)={({{(2/(Sqrt[5]))cosh(t n), if n is odd}, {(2/(Sqrt[5]))sinh(t n), if n is even}})

Evaluate f(n) for n=1, 2, 3, ...,20.  Do these values seem familiar? If not, we highly recommend the interesting article by Thomas Osler, Vieta-like products of nested radicals with Fibonacci and Lucas numbers, to appear in the journal Fibonacci Quarterly.

Chapter  8	Further Applications of Integration

8.1  Arc Length and Surface Area

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

8.1.1 Arc Length

The integrals for calculating arc length and surface area are generally difficult to do by hand.  Thus, Mathematica is the appropriate tool for evaluating these integrals.

If y is a function of x, that is, y = f(x), and f'(x) exists and is continuous on [a,b], then the arc length of the graph of f(x) over the interval [a,b] is

L=(∫_a^b)(Sqrt[1 + f'(((x))^2)])dx

If x is a function of y, that is, x = g(y), and g'(y) exists and is continuous on [c,d], then the arc length of the graph of g(y) over the interval [c,d] is

L=(∫_c^d)(Sqrt[f'(((y))^2) +1])dy

Example 8.1.  Estimate the arc length of  y=(1/x) over the interval [1,2].

Solution: Finding the arc length of this simple rational function by hand is virtually impossible.  This is because f'(x)=-(1/(x^2)) and thus the arc length integral is L=(∫_1^2)(Sqrt[1+ (1/(x^4))])dx, which cannot be evaluated in terms of elementary functions, as the following answer illustrates.

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

However, there are numerical techniques that we can use.  For example, the Mathematica command NIntegrate uses sophisticated algorithms to gives us a good estimate for this definite integral:

NIntegrate[(Sqrt[1 + (1/(x^4))]), {x,1,2}]

A more elementary method of estimating this arc length is Simpson's Rule as shown in Section 7.1 of this text.

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

f[x_]:= (Sqrt[1 + (1/(x^4))])
TableForm[Table[{n,N[SIMP[1,2,n,f]]},{n,10,100,10}],TableHeadings->{{},{"n", "(Subscript[S, n])"}} ]

Thus, we see that Simpson's Rule gives us as accurate an estimate of the arc length, as does the NIntegrate command for n as small as 20.

Example 8.2.  Consider the the ellipse whose equation is given by

((x^2)/(a^2))+((y^2)/(b^2))=1

Assume that a>b. Find the arc length of the upper half of the ellipse.

Solution: To plot the ellipse for various values of a and b, we define a plotting command plot[a,b] as follows.

Clear[a,b,x,y,eq,plot]
eq[x_,y_,a_,b_]:=((x^2)/(a^2))+((y^2)/(b^2))-1 
plot[a_,b_]:=ContourPlot[eq[x,y,a,b]==0, {x, -a,a}, {y, -b,b},
AspectRatio->Automatic, Axes->True, Frame->False]

Here is a plot of the ellipse for a=2 and b=3.

plot[2,3]

On the upper half of the ellipse, we have y≥0. Thus, we can solve for y and and take the positive solution. We will denote this positive solution as a function of x, a, and b.

sol=Solve[((x^2)/(a^2))+((y^2)/(b^2))==1, y];
f[x_,a_,b_]=sol[[2,1,2]]

Clearly, the domain of f is [-a, a]. The natural thing to do would be to evaluate the integral (∫_(-a)^a)(Sqrt[1+(((f'(x)))^2)])dx.  Try this yourself, but be prepared to wait awhile.  Moreover, Mathematica will give the following output:

If[Im[a]==0&&(a Im[(1/(Sqrt[-(a^2)+(b^2)]))]≥1||1+a Im[(1/(Sqrt[-(a^2)+(b^2)]))]≤0||a Im[(1/(Sqrt[-(a^2)+(b^2)]))]==0||a Re[(1/(Sqrt[-(a^2)+(b^2)]))]≠0),((2 (((-a))^(3/2)) (Sqrt[(b^2)]) EllipticE[1-((b^2)/(a^2))] Sign[a])/(Sqrt[-a (b^2)])),Integrate[(Sqrt[1+(((b^2) (x^2))/((a^4)-(a^2) (x^2)))]),{x,-a,a},Assumptions->(Re[b]==0&&Re[a]≠0&&Im[a]==0&&Im[b]≠0)||Im[a]<0||Im[a]>0]]

To understand this output, let us make a change of variable x=a sin  t. Then the integral becomes (verify this)

(∫_(-a)^a)(Sqrt[1+(((f'(x)))^2)])dx=a(∫_(-π/2)^(π/2))(Sqrt[1+(((b^2)(sin^2)t)/((a^2)(cos^2)t))])cos t d t

The latter integral can be expressed as

2a(∫_0^(π/2))(Sqrt[1+(((b^2)(sin^2)t)/((a^2)(cos^2)t))])cos t d t =2a(∫_0^(π/2))(Sqrt[(cos^2)t+((b^2)/(a^2))(sin^2)t]) d t =2a (∫_0^(π/2))(Sqrt[1-(c^2) (sin^2)t]) d t ,

where  c=(Sqrt[1-(((b/a))^2)])and we have used the identity (cos^2)t=1-(sin^2)t.

To simplify our notation, let us define the integrand in the preceding far left integral as

g[t_, a_,b_]=(Sqrt[1-(1-(((b/a))^2))(((Sin[t]))^2)])

Here are some values of the arc length of the upper half of the ellipse.

TableForm[Table[2a(∫_0^(π/2))g[t,a,b] \[DifferentialD]t,{a,1,3},{b,1,3}],
TableHeadings->{{"a=1","a=2","a=3"},{"b=1","b=2","b=3"} }]

Observe that we obtain exact values for the arc length when a=b.  Can you explain why?

The approximate values of the numbers appearing in the preceding table are as follows:

TableForm[N[Table[2a(∫_0^(π/2))g[t,a,b] \[DifferentialD]t,{a,1,3},{b,1,3}],10],
 TableHeadings->{{"a=1","a=2","a=3"},{"b=1","b=2","b=3"} }]

NOTE: The integral ∫(Sqrt[1-(c^2)(sin^2)t])dt is known as an elliptic integral.  It is very useful in mathematics and has many applications. In Mathematica, it is denoted by Elliptic[t,c^2].  The command Elliptic[x,m] gives (∫_0^x)(Sqrt[1-m (sin^2)t])dt, while Elliptic[m] gives  (∫_0^(π/2))(Sqrt[1-m (sin^2)t])dt.

8.1.2 Surface Area

If f'(x) exists and is continuous on [a,b], then the surface area of revolution obtained by rotating the graph of f(x) about the x-axis for a ≤ x ≤ b is

S=2π(∫_a^b)f(x)(Sqrt[1 + (([f'(x)])^2)])dx

Similarly, if x=g(y) and g'(y) exists and is continuous on [c,d], then the surface area of revolution obtained by rotating g(y) about the y-axis for c ≤ y ≤ d is

S=2π(∫_c^d)g(y)(Sqrt[(([g'(y)])^2)+ 1])dy

Again, evaluating these complicated integrals is what Mathematica does best, as the following examples illustrate.

Example 8.3.  Determine the surface area of revolution obtained by rotating the region under y=(e^(-x)) along the interval [0,2] about the x-axis.

Solution: We calculate

Clear[f,x]
f[x_] := (E^(-x))
S= 2π(∫_0^2)f[x](Sqrt[1+ ((f'[x])^2)])\[DifferentialD]x

N[%]

Here is the corresponding surface of revolution (rotated 90° about the y-axis):

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

NOTE: Observe that in this case Mathematica was able to find an anti-derivative of the integrand.  However, not all integrals of this form can be evaluated analytically as the next example illustrates.

Example 8.4.  Determine the surface area of revolution obtained by rotating the region under y=tan x along the interval [0,(π/4)] about the x-axis.

Solution: As in the previous example, we evaluate

Clear[f,x]
f[x_] := Tan[x]
NIntegrate[2π f[x](Sqrt[1+ ((f'[x])^2)]), {x,0,Pi/4}]

To appreciate the complexity of the integral and understand why we used the command NIntegrate, we advise the reader to define the anti-derivative F[t] below and evaluate F[π/4] (be prepared to wait awhile).

F[t_]:=Integrate[f[x](Sqrt[1+ ((f'[x])^2)]),{x,0,t}]

Here is the corresponding surface of revolution:

RevolutionPlot3D[Tan[x],{x,0, Pi/4}]

Exercises

In Exercises 1 and 2, calculate the arc length of the given function over the given interval:
1.  y=(x^4),  over [1,2]         2.  y=sin x,  over [0,(π/2)]

3.  Calculate the arc length of the astroid  (x^(2/3)) + (y^(2/3))=1.  Below is a plot of its graph.  Hint: By symmetry it suffices to calculate only the portion in the first quadrant.

ContourPlot[(x^2)^(1/3)+(y^2)^(1/3)==1,{x,-1,1},{y,-1,1}]

4.  Show that the circumference of the unit circle is 2π by calculating its arc length. Use the fact that the equation of the unit circle is given by   (x^2) + (y^2)=1.

In Exercises 5 through 7, compute the surface area of the given functions rotated about the x-axis over the given intervals:
5.  y=(x^3)+(1/x),  over [1,4]      	6.  y=(((4-(x^(2/3))))^(2/3)) over [0,8]   	 7.  y=cos x, over [0,π]

8.  Show that the surface area of the unit sphere is 4π by rotating the top half of the unit circle  (x^2)+(y^2)=1 about the x-axis.

8.2  Center of Mass

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

A lamina is a thin plate whose mass is distributed throughout a region in the plane. Suppose a lamina has a constant density ρ and that the lamina occupies a region in the plane under the graph of a continuous function f over the interval [a,b], where f(x)≥0 for all x.

The mass of the lamina is given by

M=ρ(∫_a^b)f(x)dx

Then the moments of the lamina with respect to x-axis and y-axis are denoted by (Subscript[M, x]) and (Subscript[M, y]) and are defined by

(Subscript[M, x])=(1/2)ρ(∫_a^b)(([f(x)])^2)dx

(Subscript[M, y])=ρ(∫_a^b)x f(x)dx

The center of mass (also called the centroid) of the lamina is defined to be ((OverBar[x]),(OverBar[y])), where

(OverBar[x])=((Subscript[M, y])/M) and (OverBar[y])=((Subscript[M, x])/M)

NOTE:  If the lamina described above as a density ρ that continuously depends on x, that is, if ρ=ρ(x) for x in the interval [a,b], then the moments, the total mass, and the center of mass are given by

M=(∫_a^b)ρ(x)f(x)dx

(Subscript[M, x])=(1/2) (∫_a^b)((ρ(x)[f(x)])^2)dx

(Subscript[M, y])= (∫_a^b)x ρ(x)f(x)dx

(OverBar[x])=((Subscript[M, y])/M) and (OverBar[y])=((Subscript[M, x])/M)

Example 8.5.  Suppose a lamina lies underneath the graph of y=16-(x^2) and over the interval [-4,4].

a)  Assume the density of the lamina is ρ=3. Find the mass, moments, and the center of mass of the lamina. 
b)  Assume the density of the lamina is ρ=(x/2)+2. Find the mass, moments, and the center of mass of the lamina.

Solution:

a) We use the above formulas with ρ=3:

f[x_]=16-(x^2)

The mass is given by

M=3(∫_(-4)^4)f[x]\[DifferentialD]x

The moment with respect to the x-axis is

Mx=(3/2)(∫_(-4)^4)(((f[x]))^2)\[DifferentialD]x

The moment with respect to the y-axis is

My=3(∫_(-4)^4)x f[x]\[DifferentialD]x

The coordinates for the center of mass are

xbar=My/M
ybar=Mx/M

Observe that the region of the lamina is symmetric with respect to the y-axis. Hence, the fact that (OverBar[x])=0 is also clear from the fact that the density is a constant.

Below is the plot of the lamina and its center of mass:

plot1=Plot[f[x], {x, -4,4} ,Filling->Axis];
plot2=ListPlot[{{xbar,ybar}},PlotStyle->{PointSize[0.02],Red}];
Show[plot1,plot2]

b) Here, ρ=x+4. With the above notation we have

f[x_]=16-(x^2)
ρ[x_]=(x/2)+2

The mass is

Mv=(∫_(-4)^4)ρ[x] f[x]\[DifferentialD]x

The moment with respect to the x-axis is

Mxv=(1/2)(∫_(-4)^4)ρ[x] (((f[x]))^2)\[DifferentialD]x

The moment with respect to the y-axis is

Myv=(∫_(-4)^4)ρ[x] x f[x]\[DifferentialD]x

The coordinates for the center of mass are

xbarv=Myv/M
ybarv=Mxv/M

Here is a plot of the lamina showing the center of masses with the uniform density of ρ=3 and variable density of ρ=(x/2)+2  represented by the red and green dots, respectively.

plot3=ListPlot[{{ xbarv,ybarv}}, PlotStyle->{Green,PointSize[.02]}];
 Show[plot1,plot2,plot3]

NOTE: Observe that the center of mass with variable density (green dot) is shifted to the right, as expected, since the density is more weighted to the right.

Example 8.6.  Suppose a lamina covers the top half of the ellipse

((x^2)/(a^2))+((y^2)/(b^2))=1

a) Assume the density of the lamina is ρ=1. Find the mass, moments and the center of mass of the lamina. 
b) Assume the density of the lamina is ρ=(e^(-x)). Find the mass, moments and the center of mass of the lamina.

Solution:  To distinguish between the uniform and variable density cases in parts a) and b), respectively, we attach the letter u and v to the notation in this solution. Thus, Mu will be the mass corresponding to the uniform density while Mv is the mass corresponding the variable density.

a) We solve the equation of the ellipse for y:

Clear[a,b,x,y]
sol=Solve[((x^2)/(a^2))+((y^2)/(b^2))==1,y]

In the top half of the ellipse , we have y≥0. Thus, we take the second solution, simplify, and define it as a function of x, a, and b

fa[x_,a_,b_]:=b (Sqrt[1-((x^2)/(a^2))])

Let the mass, the moment with respect to the x-axis, the moment with respect to the y-axis , and the center of mass be denoted by M(a,b), (Subscript[M, x])(a,b), (Subscript[M, y])(a,b), and ((OverBar[x])(a,b), (OverBar[y])(a,b)), respectively.  We now compute these quantities assuming ρ=1.

Clear[a,b,Mua,Mxua,Myua,xbaru,ybaru]
Mua[a_,b_]=(∫_(-a)^a)fa[x,a,b]\[DifferentialD]x
Mxua[a_,b_]=(1/2)(∫_(-a)^a)(((fa[x,a,b]))^2)\[DifferentialD]x
Myua[a_,b_]=(∫_(-a)^a)x fa[x,a,b]\[DifferentialD]x

xbarua[a_,b_]=((Myua[a,b])/(Mua[a,b]))
ybarua[a_,b_]=((Mxua[a,b])/(Mua[a,b]))

That  (OverBar[x])=0 is also clear from the fact that the density is a constant and the upper half of the ellipse is symmetric with respect to the y-axis.

The mass of the lamina, the moments of the lamina with respect to the x- and y-axis for various values of a and b are as follows:

umassa=TableForm[Table[Mua[a,b],{a,1,3},{b,1,3}],
TableHeadings->{{"a=1","a=2","a=3"},{"b=1","b=2","b=3"}}];
uxmomenta=TableForm[ Table[Mxua[a,b]  ,{a,1,3},{b,1,3}] ,
TableHeadings->{{"a=1","a=2","a=3"},{"b=1","b=2","b=3"}}];
uymomenta=TableForm[ Table[Myua[a,b]  ,{a,1,3},{b,1,3}]  ,
TableHeadings->{{"a=1","a=2","a=3"},{"b=1","b=2","b=3"}}];
TableForm[{umassa,uxmomenta,uymomenta},TableHeadings->{{"Mass","x-moment","y-moment"},{}}]

The corresponding y-coordinate of the center of mass in each case is (recall that (OverBar[x])=0 for all cases)

centermassua=Table[((Mxua[a,b])/(Mua[a,b])),{a,1,3},{b,1,3}];
TableForm[centermassua,
TableHeadings->{{"a=1","a=2","a=3"},{"b=1","b=2","b=3"}}]

The following animation shows how the center of mass changes as a and b varies.

plot4a[a_,b_]:=Plot[f[x,a,b],{x,-a,a},PlotRange->{{-5,5},{-15,15}},Filling->Axis];
plot5a[a_,b_]:=ListPlot[{{((Myua[a,b])/(Mua[a,b])),((Mxua[a,b])/(Mua[a,b]))}},PlotStyle->{Red,PointSize[0.02]}]
plotua[a_,b_]:=Show[plot4a[a,b],plot5a[a,b]]

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[plotua[a,b],{a,1,8},{b,1,10}]

b) Here, ρ=(e^(-x)). With the above notations modified to reflect variable density,  we have

Clear[a,b,Mv,Mxv,Myv,xbarv,ybarv]
 ρ[x_]=(E^(-x))
Mvb[a_,b_]=(∫_(-a)^a)ρ[x] fa[x,a,b]\[DifferentialD]x
Mxvb[a_,b_]=(1/2)(∫_(-a)^a)ρ[x] (((fa[x,a,b]))^2)\[DifferentialD]x
Myvb[a_,b_] =(∫_(-a)^a)ρ[x]  x fa[x,a,b]\[DifferentialD]x

xbarvb[a_,b_]=((Myvb[a,b])/(Mvb[a,b]))
ybarv[a_,b_]=((Mxvb[a,b])/(Mvb[a,b]))

Observe that the formulas for the mass and moments of the lamina are no longer elementary.  Here is a table of numerical values for these quantities assuming various choices for a and b:

umassb=TableForm[Table[Mvb[a,b],{a,1,3},{b,1,3}],
TableHeadings->{{"a=1","a=2","a=3"},{"b=1","b=2","b=3"}}];
uxmomentb=TableForm[ Table[Mxvb[a,b]  ,{a,1,3},{b,1,3}] ,
TableHeadings->{{"a=1","a=2","a=3"},{"b=1","b=2","b=3"}}];
uymomentb=TableForm[ Table[Myvb[a,b]  ,{a,1,3},{b,1,3}]  ,
TableHeadings->{{"a=1","a=2","a=3"},{"b=1","b=2","b=3"}}];
TableForm[N[{umassb,uxmomentb,uymomentb}],TableHeadings->{{"Mass","x-moment","y-moment"},{}}]

The coordinates for the center of mass are

centermassvb=N[Table[{((Myvb[a,b])/(Mvb[a,b])),((Mxvb[a,b])/(Mvb[a,b]))},{a,1,3},{b,1,3}]]

Here is a plot showing the two centers of mass with for uniform and variable density.

plot4b[a_,b_]:=Plot[f[x,a,b],{x,-a,a},PlotRange->{{-8,8},{-1,8}},AspectRatio->Automatic,Filling->Axis];
plot5b[a_,b_]:=ListPlot[{{((Myvb[a,b])/(Mvb[a,b])),((Mxvb[a,b])/(Mvb[a,b]))}},PlotStyle->{Green,PointSize[0.02]}]
plotvb[a_,b_]:=Show[plot4b[a,b],plot5b[a,b]]

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[plotvb[a,b],{a,1,8},{b,1,8}]

Exercises

1.  Suppose a lamina is lying underneath the graph of y=1+(x^2) over the interval [0,2] .
a) Assume the density of the lamina is ρ=3. Find the mass, moments, and the center of mass of the lamina. 
b) Assume the density of the lamina is ρ=2x. Find the mass, moments, and the center of mass of the lamina. 
c) Plot the lamina and the center of mass on the same axes for both parts a) and b) above.

2.  Suppose a lamina of constant density ρ=2 is in the shape of the astroid  (x^(2/3)) + (y^(2/3))=1.  Find its mass, moments, and center of mass.  Plot the lamina with its center of mass.

Chapter 9	Introduction to Differential Equations

9.1  Solving Differential Equations

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

An ordinary differential equation is an equation that involves an unknown function, its derivatives, and an independent variable. Differential equations are useful for modeling many physical phenomena some of which are discussed in the next section.

Given a differential equation, our objective is to find all functions that satisfy it.  Mathematica's command for solving a differential equation is DSolve[eqn,y[x],x] where eqn is the differential equation to be solved and y[x] is the unknown function that depends on the independent variable x.

If the differential equation has initial conditions, we use braces { } to group the equation as well as the initial conditions (separated by commas): DSolve[{eqn,cond1,cond2,...,condn},y[x],x], where cond1, cond2,...,condn are initial conditions.

9.1.1. Separation of Variables

As discussed in your textbook, there is a special class of first-order differential equations that can be solved by hand using the method of separation of variables.  Mathematica can help in applying this method but of course it can solve the differential equation outright.  This makes Mathematica useful for verifying solutions obtained by other methods or for solving more complicated differential equations.  Since your textbook focuses on solving differential equations by hand, we will primarily discuss how to solve them using Mathematica.

Example 9.1.  Solve the given differential equation and plot the graph of the solutions.

a)  y'=2(4-y), y(0)=1		b)  (Sqrt[1-(x^2)])y'=x y		 c) y ((d y)/(d x)) +5x =0

Solution:

a) This is an initial value problem. Let us first solve this differential equation by hand using the method of separation of variables:
				(dy/dx)=2(4-y)	   ⟹ 	(dy/(y-4))=-2dx
							∫(dy/(y-4))=-∫2dx
							log|y-4|= -2x+C
							|y-4|= (e^(-2x+C))=(e^C)(e^(-2x))
							y-4=±(e^C)(e^(-2x))=C (e^(-2x)) (±(e^C) replaced by C)
This shows that the general solution is given by

y=C (e^(-2x))+4

It remains to determine the value of the constant C using the initial condition y(0)=1 (recall from your textbook that each value of C corresponds to a particular solution):

1=y(0)=C (e^(-2·0))+4=C+4

Thus, C=-3 and the unique solution is

y=-3 (e^(-2x))+4

Next, let us confirm this solution using Mathematica.  Recall that when entering a differential equation in Mathematica, we write y[x] instead of y to make explicit the dependence on x.

sola=DSolve[{y'[x]==2(4-y[x])},y[x],x]

This solution agrees with the solution obtained earlier by hand (the arbitrary constant C[1] is the same to the constant C).  We can visualize the behavior of the particular solutions by plotting some of their graphs for different values of C[1].  First, let us define the general solution to be g(x,c), where c=C[1] as follows (see Section 1.2.3 to learn how to extract elements from lists):

Clear[g,x,c]
g[x_,c_]=sola[[1,1,2]]/.C[1]->c

We then plot the one-parameter family of solution curves by combining the graphs of g(x,c) for c=-5,-4,...,5.

plotgeneralsolution=Plot[Table[g[x,c],{c,-5,5}],{x,-2,2},PlotRange->{-20,20},ImageSize->250]

Can you explain how the graph of g(x,c) varies as c varies?  Which c value corresponds to the top graph?

Next, to find the unique particular solution satisfying the given initial condition y(0)=1, we solve the equation g(0,c)=1 for c:

Solve[g[0,c]==1,c]

Thus, our unique solution is y=-3 (e^(-2x))+4.  This agrees with the solution we obtained earlier by hand.  Of course, Mathematica can solve for the unique solution on its own, bypassing the algebraic steps involved:

sola=DSolve[{y'[x]==2(4-y[x]), y[0]==1},y[x],x]

However, this unique solution does not appear to be the same as the one we obtained earlier.  To remedy this, let us extract solution from the output and define it as y=f(x):

f[x_]= sola[[1,1,2]]

We then apply the Expand command to simplify f(x):

Expand[f[x]]

Thus, the unique solution obtained by Mathematica is the same as the one obtained by hand.  Here is the plot of the unique solution:

plotuniquesolution=Plot[f[x], {x,-2,2},PlotRange->{-20,20},PlotStyle->Thickness[0.01],ImageSize->250]

Lastly, we combine plots of the general solution and the unique solution to show where the latter (bold graph) is situated in the former:

Show[{plotgeneralsolution,plotuniquesolution},ImageSize->250]

b)  From this point on, we shall skip using the method of separation of variables, which we leave for the reader to employ, and proceed directly to solving all differential equations using Mathematica as in part a) above.

solb=DSolve[(Sqrt[1-(x^2)])y'[x]==x y[x],y[x],x]

Again, we can visualize the behavior of these particular solutions by plotting graphs of some particular solutions corresponding to different values of C[1].  As before, we define the general solution to be g(x,c), where c=C[1].

Clear[g,x,c]
g[x_,c_]=solb[[1,1,2]]/.C[1]->c

We then make a combined plot of the graphs of g(x,c) for c=-5,-4,...,5.

Plot[Table[g[x,c],{c,-5,5}],{x,-2,2},ImageSize->250]

c) We again use Mathematica to directly obtain the solution:

Clear[y]
solde=DSolve[ y[x] y'[x]-5 x==0,y[x],x]

Observe that the two solutions, which we denote by f(x,c) and g(x,c), differ only in sign:

f[x_,c_]=solde[[2,1,2]]/.C[1]->c
g[x_,c_]=solde[[1,1,2]]/.C[1]->c

The following two plots show the graphs of f(x,c) and g(x,c) corresponding to c=-50, -40,...,0,..., 40,50.

Plot[Table[f[x,c],{c,-50,50,10}],{x,-5,5},PlotRange->{0,10},ImageSize->250]

Plot[Table[g[x,c],{c,-50,50,10}],{x,-5,5},PlotRange->{-10,0},ImageSize->250]

Observe that the two solutions y=-(Sqrt[5(x^2)+2c]) and y=(Sqrt[5(x^2)+2c])can be represented by a single equation:

(y^2)-5(x^2)=2c

which describes a family of hyperbolas. Here is a contour plot of this equation.  Observe that it nothing more than a combination of the two plots above as to be expected.

ContourPlot[(y^2)-5(x^2),{x, -5,5}, {y,-10,10}, Frame->False, Axes->True,ContourShading->False,Contours->10,ImageSize->250]

Exercises

In Exercises 1 through 8, solve the given differential equations.  If initial conditions are also given, then plot the unique solution.  If not, then make a combine plot of several particular solutions by choosing various values of the arbitrary constant.  Then describe the graphs and explain how they vary as the arbitrary constant varies.

1.  (1+(x^2))y'=(x^(2 ))y; y(0)=2		2.  y'+3(x^4)(y^2)=0; y(0)=1
3.  y'+(y^2)=-1; y(0)=-1			4.  y'+3 y=sin x; y(0)=0

5.  y'=-2x y (bell-shaped curves)		6.  16y y'+9x=0
7.  y'- y=(y^2)					8. 2x y y'-(y^2)+(x^2)=0

9. Consider the differential equation

(3+2 y)y'=2-(e^x),  y(0)=a

a) Solve the equation.
b) Plot the graphs for values of a=-2,-1, 0, 1, 2.
c) Plot the graphs for the values of a=-.5, -.1, .1,.5.
NOTE: For parts b) and c), make sure to use a sufficiently large interval for x.

10. Consider the differential equation

y=x y (b-y)/(4+x),    y(0)=a

a) Solve the equation.
b) Plot the graphs for values of a=-2,-1, 0, 1, 2  and b=-2, -1, 0, 1, 2.
c) Plot the graphs for the values of a=-.5, -.1, .1,.5 and b=-.5, -.1, .1,.5
d) Show that the limit as x-> ∞ of the solution does not depend on a. Does the limit depend on b? If so, how?

11. Suppose a skydiver falls from rest toward the earth and assume that the air resistance caused by his open parachute is  proportional to the square of his velocity v with proportionality constant k (we neglect air resistance due to the skydiver himself).  A model for describing the skydiver's velocity after his parachute opens is then given by the differential equation

v'=-(k/m)((v^2)-((m g)/k))

where m is the mass of the skydiver and g=9.8 meters/(sec^2) is his acceleration due to gravity.

a) Solve the equation assuming an initial velocity v(0)=(Subscript[v, 0]).
b) Suppose that for a particular skydiver m=70 kg and k=30 kg/meter.  Solve the equation again using these values and plot the particular solutions for the following values of (Subscript[v, 0]): 0, 2, ..., 10.
c) What is the skydiver's limiting (terminal) velocity as t->∞ for each of the particular solutions in part b)?  Does it depend on (Subscript[v, 0])?
d) Find a formula for the terminal velocity in terms of m, g, and k.

12. Recall that the first-order linear differential equation y'+y=0 has solution y=C (e^(-x)).  Solve the following higher-order generalizations of this equation:

a) y''+2y'+y=0
b) y'''+3y''+3y'+y=0
c) (y^((4)))+4y'''+6y''+4y'+y=0
d) Do you recognize the coefficients involved in the differential equations above?  What would be the next differential equation (of order 5) that follows this pattern?  Solve this differential equation to verify that its solution follows that same pattern exhibited in parts a) through c).

9.2  Models of the Form y'=k(y-b)

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

NOTE: The differential equations we encounter in this section can be solved by the method of separation of variables and is discussed in the text. We leave it to the reader to solve the examples in this section by hand to verify the solutions obtained using Mathematica.

9.2.1. Bacteria Growth

The growth of bacteria in a culture is known to be proportional to the amount of the bacteria present at time t.  Suppose the initial amount of the bacteria is (Subscript[y, 0]) and the amount at time t is y(t). Then the above physical law is modeled by the differential equation

y'=k y,           y(0)=(Subscript[y, 0])

where k is the proportionality (growth) constant. Such a model exhibits exponential growth as can be seen from its solution below:

Clear[k]
DSolve[{y'[x]==k*y[x],y[0]==y0},y[x],x]

NOTE: Since the bacteria is growing in number, y(t) is increasing and hence y'(t)>0. Thus, k must be a positive number.

Example 9.2.  Suppose the amount of bacteria in a culture was 200 at time t=0.  It was found that there were 450 bacteria after 2 minutes.
a) Find the amount of the bacteria at any time t.   
b) At what time will the number of bacteria exceed 10,000?

Solution:

a) First, note that y(0)=200 and y(2)=450. We solve the differential equation y'=k y with the former as the initial condition:

Clear[y,t,k]
solde=DSolve[{y'[t]==k y[t],y[0]==200},y[t],t]

f[t_]=solde[[1,1,2]]

To find the value of k we solve f(2)=450 for k.

solk=Solve[f[2]==450,k]

N[%]

Thus, the proportionality constant is k=(1/2)l n(9/4)≈0.405465. Substituting this value into y(t), we see that the amount of bacteria at a given time t is

y(t)=200 (e^(0.405465 t))

b) To find the amount of time it takes for the bacteria to exceed 10,000, we solve

k=solk[[1,1,2]]
Solve[f[t]==10000,t]

We can approximate this value for t by

N[%]

Thus, it takes about 9.64824 minutes for the bacteria to reach 10,000. To visually see this, we plot the graphs of the solution y(t)=200 (e^(0.405465 t)) (blue curve) and y=10000 (red line) on the same axes.

Plot[{f[t],10000}, {t, 0, 15},PlotStyle->{Blue,Red},ImageSize->250]

NOTE: The solution y(t)=200 (e^(0.405465 t)) is only approximate since we approximated the growth constant k.  By using the exact value for k=(1/2)l n(9/4)=l n(3/2), we can derive the exact solution:

y(t)=200 (e^(k t))=200 (e^( t ln(3/2)))=200 (e^( ((ln((3/2)))^t)))=200((((3/2)))^t)

This agrees with the answer obtained by Mathematica:

f[t]

9.2.2. Radioactive Decay

The differential equation y'=k y is also used to model the amount of a radioactive substance whose rate of decay is proportional to the amount present.  However, in this case we note that the proportionality constant k<0. (Explain this!)

Example 9.3.  Carbon dating is a method used to determine the age of a fossil based on the amount of radioactive Carbon-14 in it compared to the amount normally found in the living environment. Suppose that a bone fossil contains 5% of the amount of Carbon-14 normally found in living animals. If the half-life of Carbon-14 is 5600 years, estimate the age of the bone.

Solution: Let y(t) be the amount of Carbon-14 in the bone and let (Subscript[y, 0]) be the initial amount of Carbon-14. Then the differential equation we need to solve is

Clear[k,y,y0]
solde=DSolve[{y'[t]==k y[t],y[0]==y0} , y[t],t]

Thus, the solution to the differential equation is y(t)=(Subscript[y, 0])(e^(k t)).  The half-life of Carbon-14 is 5600 implies that y(5600)=(1/2)(Subscript[y, 0]). We solve this equation for k:

y[t_]=solde[[1,1,2]]
solk=Solve[y[5600]==(1/2)y0,k]

N[%]

Thus, k=-0.000123776. To find the age of the bone, we solve y(t) = 0.05(Subscript[y, 0]) (5% of the initial amount) for t.

k=-((Log[2])/5600);
Solve[y[t]==0.05y0,t]

Thus, the bone is about 24,203 years old. Observe that it not necessary to know the original amount (Subscript[y, 0]) of Carbon-14 in the bone.

9.2.3. Annuity

An annuity is an  investment in which a principal amount of money is placed in a bank account that earns interest at an annual rate (compounded continuously) and the money is withdrawn at a regular interval. The differential equation that models an annuity is given by the annuity equation (rate of change = growth due to interest - withdrawal rate):

P'(t)=r P(t)-W =r(P(t)-(W/r))

where P(t) is the balance in the annuity at time t, r is the interest rate, and W is the rate (dollars per year) at which money is withdrawn continuously.

Example 9.4.  Find the general solution of the annuity equation for P(t) and then use it to calculate the following:
a) Assume r=6% and W=$ 6000 per year and P(0)=$ 50000.  Find P(t) and determine if and when the annuity runs out of money.
b) Assume r=6% and W=$ 6000 per year and P(0)=$ 100000.  Find P(t) and determine if and when the annuity runs out of money.
c) Assume r=6% and W=$ 12000 per year.  If we want the annuity to run out of money after 20 years, how much should be invested now?

Solution: We solve

DSolve[P'[t]==r(P[t]-(W/r)),P[t], t]

Thus, the general solution is P(t)=W/r+c (e^(r t)).

a) We set r=0.06, W=6000, and solve the initial value problem:

Clear[r,W,P]
r=0.06;
W=6000;
solde=DSolve[{P'[t]==r(P[t]-(W/r)),P[0]==50000},P[t], t]

We then define P(t) to be the solution above and plot it to see when the money will run out.

P[t_]=solde[[1,1,2]]
Plot[P[t], {t, 0,15},ImageSize->250]

As the graph indicates, the money runs out after approximately 11.5 years. We can confirm this by solving P(t)=0:

NSolve[P[t]==0,t]

b) We repeat the procedure in part a) with the obvious modifications:

Clear[r,W,P]
r=0.06;
W=6000;
solde=DSolve[{P'[t]==r(P[t]-(W/r)),P[0]==100000},P[t], t];
P[t_]=solde[[1,1,2]]
Plot[P[t], {t, 0, 80},ImageSize->250]

Observe that the balance P(t)=100,000 remains constant (can you explain why?) and thus the account will never run out of money.  What happens if we invest $100,001? $99,999?

c) In this case, we have r=0.06 and W=10000 per year.  The general solution is then given by

Clear[r,W,P,c]
r=0.06;
W=12000;
dsol=DSolve[{P'[t]==r(P[t]-(W/r)),P[0]==c},P[t], t];
P[t_]=dsol[[1,1,2]]

To determine the principal amount that will make the account run out of money in 20 years, we solve P(20)=0 for c:

NSolve[P[20]==0,c]

Thus, we need to invest $139,761.00 now.

9.2.4. Newton's Law of Cooling

Newton's Law of Cooling states that the rate of change in the temperature of an object is proportional to the difference between its temperature and that of the surrounding environment (known as the ambient temperature).  If A is the ambient temperature and T(t) is the temperature of the object at time t, then the differential equation that models this law is

T'(t)=-k(T(t)-A),   T(0)=(Subscript[T, 0])

where (Subscript[T, 0]) is the initial temperature of the object and k is a positive proportionality constant.

Example 9.6.  The temperature in an oven is (350^°) F when the oven is turned off. After 15 minutes, the temperature is (250^°) F.  Assume the temperature in the house is (70^°) F.

a) Find the temperature of the oven at any time t.
b) At what time will the temperature become (75^°) F? 
c) What will the temperature be in the limit as t-> ∞?
d) Does your answer in c) conform with your physical intuition?

Solution:

a) The ambient temperature here is room temperature.  Hence, A=70.  The initial temperature is (Subscript[T, 0])=350.  Newton's Law of Cooling then gives the model

T'(t)=-k(T(t)-70)),   T(0)=350

We solve this equation to get

Clear[T,k]
sol=DSolve[{T'[t]==-k (T[t]-70),T[0]==350},T[t],t]

T[t_]=sol[[1,1,2]]

Thus, the solution is T(t)=70(e^(-k t))(4+(e^(k t))) or T(t)=70+280 (e^(-k t)). To find the value of k, we solve T(15)=250 for k:

solk=Solve[T[15]==250,k]

k=solk[[1,1,2]]

N[%]

Thus, k=((ln(14/9))/15)=0.0294555.  Hence, the temperature of the oven at any time t is given by

T(t)=20+280(e^(-0.029455516818602614`t))

b) We solve T(t)=75 for t:

NSolve[T[t]==75, t]

Thus, the temperature will be (75^°) F after about two hours and 17 minutes.

c) We make a plot of the solution:

Plot[T[t], {t, 0, 100},AxesOrigin->{0,0},ImageSize->250]

To find the limiting temperature, we evaluate

Limit[T[t], t->Infinity]

d) Since heat flows from a region of higher temperature to a region of lower temperature, it is intuitively clear that the oven will cool down to the room (ambient) temperature.  Hence, the limit should be (70^°) F as expected.

Exercises

1. Mass of bacteria in a culture grow at a rate proportional to its size. Suppose the culture contains 200 cells intially and there are 800 cells after 3 hours.

a) Find the formula for the number of cells in the culture at time t.
b) Find the amount of bacteria after 2 hours.
c) At what time will the bacteria exceed 10,000 cells?

2. A mummy excavated from an archaelogical site in Egypt is found to contain 20% of Carbon-14 normally found in living humans.  Use carbon dating to estimate the age of the mummy.

3. Plutonium-239 is a highly radioactive element generated from waste in nuclear power plants and has a half-life of approximately 24,000 years.  How many years would it take for Plutonium-239 to decay to a safe level of 1/1000 its original amount?

4. Solve the following using the annuity differential eqaution discussed in this section.
a) Assume r=6% and W=$500 per year and P(0)=$5,000. Find P(t) and determine when the annuity runs out of money.
b) Assume r=6% and W=$500 per year and P(0)=$9,000. Find P(t) and determine when the annuity runs out of money.
c) Assume r=6% and W=$20,000 per year.  If we want the annuity to run out after 40 years, how much should we invest now?

5. Suppose a retired worker wants to invest in an annuity that will pay out $10,000 per year.
a) Assuming the annuity has an interest rate of 5%, find the minimum principal amount that should be invested so that the annuity never runs out of money.
b) Assuming the principal amount of money invested is $250,000, find the minimum interest rate that the annuity should bear so that it never runs out of money.

6. A hot metal rod is placed in a water bath whose temperature is  40° F. The rod cools from 300° F to 200° F in 1 minute. How long will take the rood to cool down to 150° F?  45° F?

9.3  Numerical Methods Using Slope Fields

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

9.3.1.  Slope Fields

Consider a differential equation in the form

y'=f(x,y)

Since y' represents the slope of the line tangent to the graph of the solution y, we can think of f(x,y) as the slope of the same tangent line at the point (x,y), which we indicate by drawing a segment of it at the point of tangency.  The set of all such line segments (normalized to have the same length) is called the slope (or direction) field of the differential equation. Note that the slope field gives a graphical approximation to the solution.  It enables us to draw or visualize the graph of the unique solution of the equation passing through a given point. We will illustrate this in an upcoming example.

To plot the slope field of the differential equation y'=f(x,y) along the intervals (a,b) and (c,d) on the x- and y-axis, respectively, we use the command VectorPlot[{1, f[x, y]}, {x, a, b}, {y, c, d}], where slope is represented as a two-dimensional vector (1,f(x,y)) with the change in x normalized to equal 1.

NOTE: The command VectorPlot replaces the command VectorFieldPlot, which is obsolete in version 7 of Mathematica.

Example 9.9.  Consider the differential equation y'=(x^2)-2y, y(0)=-1.

a)  Draw the slope fields for the differential equation.
b)  Solve the differential equation.
c)  Plot both the slope field and the solution on the same axes.
d)  Redo parts b) and c) for the same equation but with initial condition given by y(a)=b.  Choose various values for a and b.

Solution:

a) Here, f(x,y)=(x^2)-2y.  We use the VectorPlot command to plot the corresponding slope field:

f[x_,y_]:=(x^2)-2y

plot1=VectorPlot[{1,f[x,y]},{x, -5,5},{y,-10,10},Axes->True,Frame->False,VectorScale->{Tiny,Tiny,None},ImageSize->250]

b) We use the DSolve command to find the exact solution of the differential equation.

Clear[y,x,g]
sol=DSolve[{y'[x]==f[x,y[x]],y[0]==-1},y[x],x]
g[x_]=sol[[1,1,2]]

c) We now plot the slope field together with the solution above passing through the point (0,-1):

plot2=Plot[g[x],{x,-5,5}, PlotRange->{-10,10},ImageSize->250]

Show[plot1,plot2,Graphics[{PointSize[Large],Point[{0,-1}]}],ImageSize->250]

d) We can show several graphs of solution curves (called integral curves) together with the corresponding slope field. Here is an example of how this can be done.

Clear[y,x,h,a,b]
sola=DSolve[{y'[x]==f[x,y[x]],y[a]==b},y[x],x];
h[x_,a_,b_]=Simplify[sola[[1,1,2]]]

plot3=Plot[Evaluate[Table[h[x,a,b],{a,-3,3,2},{b, -3,3,2}]],{x,-5,5},PlotRange->{-10,10}];
Show[plot1,plot3,ImageSize->250]

9.3.2.  Euler's Method

The simplest numerical method for solving a first order differential equation is Euler's Method. This method approximates the solution by moving along tangent lines described by the slope field of the differential equation.  Here is a brief description.

Let y=ϕ(x) be the solution of the differential equation

y'=f(x,y), y((Subscript[x, 0]))=(Subscript[y, 0])

Then the equation of the line tangent to the graph of y=φ(x) at x=(Subscript[x, 0]) is given by

y=φ'((Subscript[x, 0]))(x-(Subscript[x, 0]))+φ((Subscript[x, 0]))

But when x=(Subscript[x, 0]), we have φ((Subscript[t, 0]))=(Subscript[y, 0]) and φ'((Subscript[x, 0]))=f((Subscript[x, 0]),(Subscript[y, 0])). Thus, when x is close to (Subscript[x, 0]), φ(x) can be approximated by

y≈f((Subscript[x, 0]),(Subscript[y, 0]))(x-(Subscript[x, 0]))+(Subscript[y, 0])

We now choose h>0 to be a small positive number, called the step size, and define (Subscript[x, 1])=(Subscript[x, 0])+h. Then φ((Subscript[x, 1])) is approximately equal to

(Subscript[y, 1])=(Subscript[y, 0])+f((Subscript[x, 0]),(Subscript[y, 0]))((Subscript[x, 1])-(Subscript[x, 0]))

or

(Subscript[y, 1])=(Subscript[y, 0])+h f((Subscript[x, 0]),(Subscript[y, 0]))

We repeat the above argument at the point ((Subscript[x, 1]),(Subscript[y, 1])) to get an approximation of φ((Subscript[x, 2])), where (Subscript[x, 2])=(Subscript[x, 1])+h=(Subscript[x, 0])+2h:

(Subscript[y, 2])=(Subscript[y, 1])+h f((Subscript[x, 1]),(Subscript[y, 1]))

Proceeding in this manner, we obtain Euler's Method:

(Subscript[y, n+1])=(Subscript[y, n])+h f((Subscript[x, n]),(Subscript[y, n]))  for n=0, 1, 2, 3, ....

where φ((Subscript[x, n]))≈(Subscript[y, n]).

If the approximated solution is calculated over an interval [a,b] and the step size h is specified, then the number of iterations (or steps) required is given by m=(b-a)/h, where (Subscript[x, 0])=a and (Subscript[x, n])=(Subscript[x, 0])+n h.

Here is a Mathematica program called Euler for evaluating Euler's Method in m steps (the option SetPrecision sets the precision of our calculations to 10 digits).

Clear[f,x,y,x0,y0,h, m]
Euler[f_,h_,m_]:=Module[{n},
Do[
y[n+1]=SetPrecision[N[y[n]+h*f[x[n],y[n]]],10];
x[n+1]=x[n]+h,
{n,0,m}]]

Example 9.7.  Use the Euler program to construct a table of solution values for the differential equation y'=(x^2)+2y, y(0)=1 with a step size of h=0.1 and for m=10 steps.

Solution: Here f(x,y)=(x^2)+2y, (Subscript[x, 0])=0, (Subscript[y, 0])=1.

f[x_,y_]:=(x^2)+2y
m=10;
x0=0;
y0=1;
h=0.1;
x[0]=x0;
y[0]=y0;
Euler[f,h,m]
TableForm[Table[{n,x[n],y[n]},{n,1,m}],TableHeadings->{{},{"n ","(Subscript[x, n])","(Subscript[y, n])" }}]

To see how accurate the above approximation is, we solve the differential equation for the exact solution and plot both the approximate and exact solutions on the same axes.

Clear[z,t,exact]
exact=DSolve[{z'[t]==f[t,z[t]],z[x0]==y0},z[t],t];
z[t_]=z[t]/.exact[[1]]

Clear[plot1,plot2]
plot1=Plot[z[t],{t,0,1} ];
plot2=ListPlot[Table[{x[n],y[n]},{n,0,m}],PlotStyle->PointSize[0.01] ];
Show[{plot1,plot2},ImageSize->250]

Observe that the approximations become less accurate as we move away from the initial point (0,1). This is typical of numerical methods such as Euler's Method.  However, we can increase the accuracy of our approximation by decreasing the step size.  For example, we recompute the solution using h=0.05 (this increases the number of steps to m=20):

h=0.05;
m=20;
Euler[f,h,m]
TableForm[Table[{n,x[n],y[n]},{n,1,m}],TableHeadings->{{},{"n ","(Subscript[x, n])","(Subscript[y, n])" }}]

The following plot of the two numerical solutions corresponding to h=0.1 (small blue dots) and h=0.05 (large red dots) clearly shows that the latter is more accurate in comparison to the exact solution (curve):

plot3=ListPlot[Table[{x[n],y[n]},{n,0,m}],PlotStyle->{PointSize[0.01],Red,PointSize[0.015] }];
Show[{plot1,plot2,plot3},ImageSize->250]

Here is a modification of the Euler progam that allows the user to input the endpoints a and b directly (instead of the step size h) and m.

Clear[f,x,y,h,a,b,m]
EulerEndpt[f_,a_,b_,m_]:=Module[{n,h},h=N[((b-a)/m)];
Do[
y[n+1]=SetPrecision[N[y[n]+h*f[x[n],y[n]]],10];
x[n+1]=x[n]+h,
{n,0,m}]]

Example 9.8.  For the differential equation y'=(x^2)+2y, y(0)=1, approximate its solution over the interval [0,2] using m=10 steps.

Solution: Again, we have f(x,y)=(x^2)+y, (Subscript[x, 0])=0, (Subscript[y, 0])=1.  However, we now input the interval [a,b]=[0,2] into EulerEndPt.

f[x_,y_]:=(x^2)+y
m=10;
x0=0;
y0=1;
x[0]=x0;
y[0]=y0;
a=0;
b=2;

EulerEndpt[f,0,2,m]
TableForm[Table[{n,x[n],y[n]},{n,1,m}],
TableHeadings->{{},{"n ","(Subscript[x, n])","(Subscript[y, n])" }}]

This time we numerically compare the approximate solution with the exact solution:

Clear[z,t,exact]
exact=DSolve[{z'[t]==f[t,z[t]],z[x0]==y0},z[t],t];
z[t_]=z[t]/.exact[[1]]
TableForm[Table[{n,x[n],y[n],N[z[x0+n(b-a)/m]]},{n,1,m}],
TableHeadings->{{},{"n ","(Subscript[x, n])","(Subscript[y, n])","y(n)" }}]

Exercises

In Exercises 1 through 4, plot the slope field of the given differential equations:
1.  y'=(x^2)+(y^2)		2.  y'=(t^2)y		3.  y'=sin(x+y)		4.  y'=x (e^(-y))

5. Consider the differential equation  y'=3y-2(y^2).
a) Draw the slope field for the differential equation.
b) Solve the differential equation.
c) Assume y(0)=2.  Plot the graph of the solution for this case and also the slope field on the same axes.  Discuss the behavior of the solution as x->∞.
d)  Redo part c) for the same differential equation but with initial condition given by y(a)=b (choose various values for a and b).

In Exercises 6 through 9, use Euler's Method to find a numerical solution to the given initial value problem along the stated interval and using the prescribed number of steps.  Also, find their exact solutions and compare the results.
6.  y'=(x^2)-y,  y(0)=1; [0,1]; m=10	7.  y'=(1-(x^2)) cos y,  y(1)=0; [1,2]; m=20	8.  y'-(y^2)=x,  y(0)=1; [0,5]; m=50		9.  y'=-3x/2+ln((x^2)+y),  y(1)=1; [1,2]; m=100

10. Heun's method is a numerical method that improves on Euler's method.  It uses the approximation from Euler's method as an auxiliary value (called a predictor), which we denote by (Subscript[y, n+1]^( * )):

(Subscript[y, n+1]^( * ))=(Subscript[y, n])+h f((Subscript[x, n]),(Subscript[y, n]))

The actual approximation (called the corrector) is then computed as the mean of (Subscript[y, n+1]^( * )) (based on the slope of the tangent line at ((Subscript[x, n]),(Subscript[y, n]))) and (Subscript[y, n+1]^( ** ))=(Subscript[y, n])+h f((Subscript[x, n+1]),(Subscript[y, n+1]^( * )))  (based on the slope of the tangent line at ((Subscript[x, n+1]),(Subscript[y, n+1]^( * )))):

(Subscript[y, n+1])=(1/2)[(Subscript[y, n+1]^( * ))+(Subscript[y, n+1]^( ** ))] =(Subscript[y, n])+(1/2)[h f((Subscript[x, n]),(Subscript[y, n]))+h f((Subscript[x, n+1]),(Subscript[y, n+1]^( * )))]

a) Apply Heun's method to Exercise 6 and the compare the results obtained by Euler's method with the exact solution.  How much more accurate is Heun's method?
b) Redo part a) using m=20.  How much more accurate is the solution compared to that for m=10?

9.4  The Logistic Equation

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

The differential equation

((d y)/(d t))=k y(1-(y/A))

is called the logistics equation. Here, k>0 and A is a constant called the carrying capacity.  This equation is useful for modeling the growth of a population where resources are limited and can only sustain a certain maximum population given by the carrying capacity.

Example 9.5.   The population p(t) of mosquito larvae growing in a tree hole increases according to the logistics equation with growth constant k=0.3 per day and carrying capacity A=1000.

a) Assuming that the initial population of the larvae is 50, find the population p(t) at any time t. 
b) After how many days will the larvae population exceed 500?
c) When does the larvae population reach 99% of the maximum capacity?

Solution:  
a) We use k=(3/10) and solve the corresponding differential equation in Mathematica:

Clear[y]
solde=DSolve[{y'[t]==(3/10) y[t](1-((y[t])/1000)), y[0]==50}, y[t],t]

NOTE:  Be careful with using a decimal approximation for k.  For example, try using k=0.3 and see what happens.

Next, for convenience we write the solution given in the previous output as

Clear[p,t]
p[t_]=solde[[1,1,2]]

Thus, the population of larvae at any time t is given by

p(t)=((1000 (e^(3 t/10)))/(19+(e^(3t/10))))

b) To find how long it takes for the larvae population to reach 500, we solve

NSolve[p[t]==500,t]

Thus, it takes about ten days for the larvae population to exceed 500.  Observe that p(10)≈513.887.

NOTE: We ignored the other two solutions in the previous output since they are complex-valued and not physically relevant.

c) We first plot the graph of p(t) to estimate the number of days required for the larvae population to reach 99% of the maximum capacity, that is, p(t)=999.

Plot[p[t], {t,0, 60},ImageSize->250]

It appears that the population reaches 999 larvae after t=30. We use the Table command to numerically confirm this.

TableForm[Table[{t,N[p[t],20]}, {t, 10, 50, 5}],TableHeadings->{{},{"Days     ", "Larvae Population"}}]

We can reasonably conclude from the table that the population reaches 999 larvae between 30 and 35 days. To obtain a more precise answer, we use Mathematica to solve p(t)=999 for t:

NSolve[p[t]==999,t]

Thus, the desired time is approximately t=33 days.

Exercises

1. A population of squirrels live in a forest with a carrying capacity of 3000. Assume logistic growth with growth constant k=0.8 per year.
a) Find the population of the squirrels at any time t assuming an initial population of P(0)=800.
b) How long will it take for the squirrel population to double?  Triple?

2. From 1960 to 2000, the world's population doubled from approximately 3 billion to 6 billion people.  Assuming that the human population follows logistic growth and that the earth has a carrying capacity of 100 billion people, determine the following:
a) Find the population at any time t.  What is the growth constant?
b) What will the population be in the year 2050?  How does this answer compare with projections from the United Nations?
c) Find the year in which the human population will reach half its carrying capacity?
d) When will the population grow the fastest, that is, the point on the graph where it changes from concave up to concave down (point of inflection)? What is the growth rate then?

3. In medicine, the logistics equation is used to model the growth of tumors in certain organs.  Suppose a patient is diagnosed with a tumor that has doubled in size to 2% of his liver when a year ago it only covered 1% of his liver.  How long will it take the tumor to grow to 10% of his liver when a transplant will most like by required to increase his chances of survival.

4. The current population of a herd of bison living inside a national park is 1000.  To ensure that the population does not reach more than 1500 bison in 50 years time and 2000 bison in 100 years time, what carrying capacity should the park maintain?  Assume that the bison population follows a logistics model.

Chapter 10 	Infinite Series

10.1 Sequences

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

Recall that a sequence is a function whose domain is the set of non-negative integers.

In Mathematica, we denote a sequence (Subscript[a, n]) as a function. Thus, instead of (Subscript[a, n  ])we write a(n). The limit of a sequence is evaluated by using the Limit command. When Limit[a[n], n->∞] is evaluated, Mathematica automatically assumes that n is a continuous variable (instead of a discrete variable). It employs various techniques to evaluate limits.

To plot the graph of a sequence, we use the ListPlot command. ListPlot[list] plots the graph of list, where list is a list of points (x,y), denoted in Mathematica by {x,y}. In our case, list will be the table of values of the form {n,a[n]}.  The corresponding plot command in this case would be ListPlot[Table[{n,a[n]},{n,min,max}].

Example 10.1.  Consider the sequence defined by

(Subscript[a, n])=((4n+1)/(3n+2))

a) Find the first few terms of the sequence.

b) Plot the graph of the sequence.

c) Make a conjecture for the limit based on the graph.

d) Find the limit of the sequence.

Solution:

a) We define the sequence as a function of n and use the Table command to generate the first ten terms of the sequence.

Clear[a,n]
a[n_]:= ((4 n+1)/(3 n+2))

TableForm[Table[{n,a[n]},{n,1,10}],
TableHeadings->{{},{"n","(Subscript[a, n])"}}]

To obtain decimal expressions of these values, we evaluate

TableForm[N[Table[{n,a[n]},{n,1,10}]],
TableHeadings->{{},{"n","(Subscript[a, n])"}}]

b) To plot the graph of the sequence, we use the ListPlot command. Here is a plot of the first 100 terms of the sequence.

ListPlot[Table[{n, a[n]}, {n, 1, 100}]]

c) The graph suggests that the limit is 1.333....  We can use the Table command to see this more clearly.

TableForm[N[Table[{n,a[n]},{n,1000,10000,1000}]],
TableHeadings->{{},{"n","(Subscript[a, n])"}}]

Hence, the limit seems to be 1.3333... or 4/3. Here is a plot of y=4/3 and the graph of the sequence for large values of n:

Clear[plot1,plot2]
plot1=ListPlot[Table[{n, a[n]}, {n, 1, 1000,10}]];
plot2=Plot[4/3, {x, 1, 1000}];
Show[plot1, plot2,PlotRange->{1.25,4/3}]

d) Finally, we confirm this in Mathematica by evaluating the limit as n goes to ∞.

Limit[a[n],n->Infinity]

Example 10.2.  Consider the sequence defined by

(Subscript[a, n])=((((-1))^n)/n)

a) Plot the graph of the sequence.

b) Does the sequence converge?

Solution:

a) Again, we use ListPlot to plot the graph.

Clear[a,n] 
a[n_]:=((((-1))^n)/n)

ListPlot[Table[{n, a[n]}, {n, 1, 100}]]

b) From the graph, it is clear that the sequence approaches 0 in the limit. We confirm this using the Limit command.

Limit[a[n],n->Infinity]

NOTE: There are instances where the sequence (Subscript[a, n]) may not be well-defined if n  is treated as a real variable (as opposed to an integer variable). In such cases, Mathematica may return the limit unevaluated or else gives an output that indicates the limit may not exist, as the following example illustrates.

Example 10.3.  Determine whether or not the sequence defined below converges:

(Subscript[a, n])=(((-1))^n)(n/(n+1))

Solution: First, we will plot the graph of the sequence.

Clear[a,n]
a[n_]:=(((-1))^n)(n/( n+1))

ListPlot[Table[{n, a[n]}, {n, 1, 100}]]

The graph clearly indicates the sequence does NOT converge (to a unique limiting value). We can see this by investigating the following tables of values. The first one lists the even terms while the second one lists the odd terms of the sequence.

TableForm[Table[{n,N[a[2n]]},{n,10,100,10}],
TableHeadings->{{},{"n","(Subscript[a, 2n])"}}]

TableForm[Table[{n,N[a[2n-1]]},{n,10,100,10}],
TableHeadings->{{},{"n","\!\(\*Cell[TextData[Cell[BoxData[
FormBox[
SubscriptBox["a", 
RowBox[{
RowBox[{"2", "n"}], "-", "1"}]], TraditionalForm]]]]]\)"}}]

Finally, let us evaluate the limit.

Limit[a[n],n->Infinity]

This output, specifically the notation Interval[{0, π}], means that the limit does not exist uniquely, but has subsequences whose limits take on the set of complex values (e^(2i x)) for all x∈[0,π].  This is because the variable n that appears in the Limit command is automatically assumed by Mathematica to be a complex variable.  In our case, for n an integer variable, we have two subsequences, (Subscript[a, 2n]) and (Subscript[a, 2n+1]) (even and odd, respectively), converging to different limits (1 and -1, respectively).  Thus, (Subscript[a, n]) diverges.

Example 10.4.  Consider the sequence {(Subscript[a, n])} defined recursively by (Subscript[a, 1])=1 and (Subscript[a, n+1])=(Sqrt[(Subscript[a, n])+1]).  Generate the first ten terms of this sequence and compute its limit.

Solution: Here is one method of defining a recursive sequence.

Clear[a,n]
a[1]=1
a[n_]:=a[n]=Sqrt[a[n-1]+2]

NOTE: The second occurrence of a[n] in the preceding command tells Mathematica to store all intermediate values of the recurrence in evaluating a[n].

Here are the first ten terms of the sequence:

TableForm[Table[{n,a[n]},{n,1,10}],
TableHeadings->{{},{"n","(Subscript[a, n])"}}]

The following table gives decimal expressions of the same first ten terms and reveals the limit to be equal to 2.

TableForm[Table[{n,N[a[n]]},{n,1,10}],
TableHeadings->{{},{"n","(Subscript[a, n])"}}]

NOTE: In general, Mathematica is not able to directly compute limits of sequences defined recursively.  Assuming (Subscript[a, n]) converges (prove this!), we then compute its limit, called L, say, by letting n->∞ in the recurrence formula for (Subscript[a, n]):

L=(lim_(n->∞))(Subscript[a, n])=(lim_(n->∞))(Sqrt[(Subscript[a, n-1])+2])=(Sqrt[(lim_(n->∞))(Subscript[a, n-1])+2])=(Sqrt[L+2])

Solving the equation L=(Sqrt[L+2]) then yields L=2 as the limit.

Solve[L==Sqrt[L+2],L]

Example 10.5.  Let (Subscript[a, 1])=1 and (Subscript[b, 1])=(Sqrt[2]).  Define two sequences recursively by

(Subscript[a, n+1])=(Sqrt[(Subscript[a, n])(Subscript[b, n])])  and (Subscript[b, n+1])=(((Subscript[a, n])+(Subscript[b, n]))/2)

a) Choose various values of (Subscript[a, 1]) and (Subscript[b, 1]) and calculate the first ten terms of the sequences {(Subscript[a, n])} and {(Subscript[b, n])}.

b)  Show that (Subscript[a, n])≤(Subscript[b, n]) for every positive integer n.

c) Show that both sequences converge to the same limit.  (NOTE: This common limit is called the arithmetic-geometric mean of (Subscript[a, 1])and (Subscript[b, 1]).)

Solution:

a) Here is a program that generates the first ten values of (Subscript[a, n]) and (Subscript[b, n]).

Clear[a,b,n]
a[1]=1
b[1]=10
a[i_]:= a[i]= (Sqrt[a[i-1]*b[i-1]]) ;
b[i_]:= b[i]= ((a[i-1]+b[i-1])/2) ;

TableForm[Table[{k,N[a[ k],10],N[b[ k],10]},{k, 1, 10} ],
TableHeadings->{{},{"n","a[n]","b[n]"} }]

b) The following table suggests that (Subscript[a, n])≤(Subscript[b, n]) for at least the first ten terms:

TableForm[Table[{k,N[a[ k],10],N[b[ k],10],N[b[k],10]-N[a[k],10]},{k, 1, 10} ],
TableHeadings->{{},{"n","a[n]","b[n]","b[n]-a[n]"} }]

For a better feel on this, let us plot the graphs on the same axes. To this end, we define two lists using the Table command and use the ListPlot command to plot the graphs.

plot1=ListPlot[Table[{k,a[k]},{k,1,10}],PlotStyle->{Blue}];
plot2=ListPlot[Table[{k,b[k]},{k,1,10}],PlotStyle->{Red}];
Show[plot1,plot2,PlotRange->{0,10}]

The above graph suggests that the two sequences converge to the same limit.  Unfortunately, Mathematica's Limit command cannot help us compute the limit of (Subscript[a, n]) and (Subscript[b, n]) due to their recursive nature. (Try this!)

NOTE: We encourage the reader to experiment with different initial values for (Subscript[a, 1]) and (Subscript[b, 1]) to see if the sequences (Subscript[a, n]) and (Subscript[b, n]) always converge to the same limit.

Example 10.6.  Consider the sequence

(Subscript[a, n])=((((n!))^(1/n))/n)

a) Show that if  (Subscript[b, n])=ln (Subscript[a, n]), then (Subscript[b, n])=((ln (n!)-n ln n)/n).

b)  Does (Subscript[b, n]) converge? If so, find the limit.

c)  Does (Subscript[a, n]) converge? If so, find the limit.

Solution:

a)  We define a sequence (Subscript[c, n])=((ln (n!)-n ln n)/n) and then show that (Subscript[b, n])=(Subscript[c, n]).

Clear[a,b,c]
a[n_]:=((((n!))^(1/n))/n)
b[n_]:=Log[a[n]]

c[n_]:=((Log[ n!]-n Log[n])/n)

TableForm[Table[{N[c[n]],N[b[n]],N[c[n],10]-N[b[n],10]}, {n, 2, 10}],
TableHeadings->{Automatic,{" (Subscript[c, n])"," (Subscript[b, n])"," (Subscript[c, n])-(Subscript[b, n])"}}]

The preceding table indicates that the two sequences are the same.  Here is a plot of both:

ListPlot[{Table[{n,b[n]}, {n, 1, 100}],Table[{n,c[n]}, {n, 1, 100}]},PlotRange->{-1,0.1},AxesOrigin->{0,0}]

This plot clearly shows that (Subscript[b, n])=(Subscript[c, n]), that is, ln((Subscript[a, n]))=ln(((((n!))^(1/n))/n))=((ln (n!)-n ln n)/n).  We leave it to the student to establish this equality using properties of the natural logarithmic function.

b) The previous plot indicates that the limit of (Subscript[b, n]) is -1.  To confirm this, we use the Limit command.

Limit[b[n], n->Infinity]

c) Since (Subscript[b, n])=ln ((Subscript[a, n])), it follows that (Subscript[a, n])=(e^(Subscript[b, n])) and hence (lim_(n-> ∞))(Subscript[a, n])=(e^(-1)).  Again, we verify this using the Limit command:

Limit[a[n], n->Infinity]

Exercises

In Exercises 1 though 3, determine the convergence of the given sequence. 
1.  (Subscript[a, n])=((3(n^2)+n+2)/(2(n^2)+1))			2. (Subscript[a, n])=ln(((2n+3)/(n+1)))	 			3. (Subscript[a, n])= (n^(1/n))

4.  Let   (Subscript[c, n])=(1/(n+1))+(1/(n+2))+(1/(n+3))+ ... + (1/(2n)).

a.  Find the first ten terms of the sequence.
b.  Plot the graph of the sequence.
c.  Is the sequence increasing? Bounded? Convergent? Prove each of your assertions.
d.   Find (lim_(n-> ∞))(Subscript[c, n]).

5. The nth harmonic number is defined to be the sum

(Subscript[H, n])=1+(1/2)+(1/3)+ ... + (1/n).

Let  (Subscript[a, n])=(Subscript[H, n])-ln n and (Subscript[b, n])=(∫_1^(n+1  )) (1/x)  dx.

a.  Show that (Subscript[H, n])≥(Subscript[b, n]) for n=1,2,3,...,10.  Prove that this holds for all positive integers n.

b.  Show that (Subscript[a, n])≥0 for n=1,2,3,...,10.  Prove that this holds for all positive integers n.

c.  Use the ListPlot command to plot the graph of (Subscript[a, n]).  Does the graph indicate that (Subscript[a, n]) is decreasing or increasing?

d.  Evaluate (lim_(n-> ∞))(Subscript[a, n]).

e.  The limit in part d) is called Euler's Constant and is denoted by γ. Compute γ accurate to 20 digits.

10.2  Infinite Series

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

10.2.1 Finite Sums

Sum[a[n], n, n1, n2] evaluates the finite sum of (Subscript[a, n]) as n goes from (Subscript[n, 1]) to (Subscript[n, 2]).  
Sum[a[n], n, n1, Infinity] evaluates the infinite series of (Subscript[a, n]) as n goes from (Subscript[n, 1]) to ∞.

Using the BasicMathInput Palette, we can also enter finite sums or infinite series as (∑_(n=n1)^n2)a[n] or (∑_(n=n1)^∞)a[n], respectively.

Example 10.7.  Compute the following finite sums:

a) (∑_(n=1)^10)((((-1))^n)/n)		b)  (∑_(k=1)^5)(k-1)(k+1)

c) (∑_(k=1)^30) (({{20}, {k}}))(2^k)	d)  (∑_(i=1)^n)(3i-2)	e)  (∑_(k=0)^10)(((k^2)+1)/((k^3)+2(k^2)+1))

Solution:

a)

(∑_(n=1)^10)((((-1))^n)/n)

b)

Sum[(k+1)(k-1), {k, 1,5}]

c) The binomial coefficient (({{n}, {m}}))=((n!)/(m!(n-m)!)) is expressed in Mathematica by the command Binomial[n, m].

(∑_(k=0)^30)Binomial[30,k] (2^k)

NOTE: The above number is the same as (3^30)=205891132094649. Verify this!

d)

(∑_(j=1)^n) (3j-2)

Simplify[%]

e)

(∑_(k=0)^10)(((k^2)+1)/((k^3)+2(k^2)+1))

10.2.2  Partial Sums and Convergence

Example 10.8.  Consider the series (∑_(n=1)^∞)(1/(4(n^2)-1)).   Let (Subscript[s, n ])denote its nth partial sum.

a)  Find (Subscript[s, 100]). 		
b)  Compute every 10th partial sum up to n=100.
c)  Compute every 1000th partial sum up to n =10,000.
d)  From the tables of values in parts a) and b) what do you infer about the convergence of the series?  Prove your assertion.

Solution:

a) First, we define (Subscript[s, n]) in Mathematica and then evaluate (Subscript[s, 100]).

Clear[s,n]
s[n_]:= (∑_(j=1)^n)(1/(4(j^2)-1))
s[100]

N[%]

b) Here, we use the command Table[s[n],{n,1,J,K}], which gives the list of every K-th value of (Subscript[s, n]), as n goes from 1 to J.  The command TableForm[N[Table[s[n],{n, 1, J, K }]]] lists the values in column form.

Table[s[n],{n,1,100,10}]

N[%]

TableForm[Table[{n,N[s[n]]},{n,10,100,10}],
TableHeadings->{{}, {"n", "(Subscript[s, n])"}}]

c)

TableForm[Table[{n,N[s[n]]},{n,1000,10000,1000}],
TableHeadings->{{}, {"n", " (Subscript[s, n])"}}]

d) It seems that the partial sums converge to 0.5. We  confirm this by evaluating

Limit[s[n], n->∞]

Can you prove this?  Hint: Use the method of partial fractions to decompose this series into a telescoping series as discussed in your calculus text.

Example 10.9.  Let (Subscript[s, n ])be the nth partial sum of the harmonic series

(∑_(k=1)^∞)(1/k).

a)  Find   (Subscript[s, 100]). 		
b)  Compute every 1000th partial sum up to n =10,000
c)  Plot the graphs of the partial sums.
d)  From the table of values in part (b) what do you infer? Prove your assertion.

Solution:  We will follow the method of the preceding example.  First, we define the nth partial sum.

Clear[s,n]
s[n_]:=Sum[1/k,{k, 1, n}]

a) Then (Subscript[s, 100]) is given by

s[100]

N[%]

b) Here is a table of values of every 1000th term in the sequence (Subscript[s, n]) for n less than or equal to 10, 000.

TableForm[Table[{n,N[s[n]]},{n,1000,10000,1000}],
TableHeadings->{{}, {"n", " (Subscript[s, n])"}}]

c) Here is a plot of (Subscript[s, n]).

ListPlot[Table[{n,s[n]},{n,1, 300,20}]]

The graph above indicates a slow growth that makes it difficult to reach a definitive conclusion regarding the convergence of the harmonic series.

d) The table in b) and the plot in c) both suggest that the sequence of the partial sums is increasing. To convince ourselves of this, we compare (Subscript[s, (2^n)]) and (n/2).

TableForm[Table[{n/2.,N[s[(2^n)]]},{n,1,10}],
TableHeadings->{{}, {"(n/2)", " (Subscript[s, (2^n)])"}}]

This table suggests that (Subscript[s, (2^n)])≥(n/2) for n≥2.  Use this fact (a proof of it can be found in your calculus text) to establish the divergence of the harmonic series.

Example 10.10.  Determine whether the following series converges or diverges.

a)   (∑_(n=1)^∞)((((-1))^n)/(n^2))		b)  (∑_(j=1)^∞)((j-1)/j)		c)  (∑_(n=1)^∞)((1/(Sqrt[n]))-(1/(Sqrt[n+1])))		d)  (∑_(n=1)^∞)(ln(n+1)-ln n)

Solution: In all cases, we let Mathematica attempt to evaluate the infinite sum. For those cases where Mathematica returns a numeric output, this is understood to mean that the series converges and that the sum of the series is the given value.

a)

(∑_(n=1)^∞)((((-1))^n)/(n^2))

Thus, the series converges to -((π^2)/12). To see this graphically, we plot the graph of the partial sums of the series using the ListPlot command, along with the horizontal line representing its sum s=-((π^2)/12)≈-0.822467.

Clear[s,n]
s[n_]=(∑_(k=1)^n)((((-1))^k)/(k^2));

plot1=ListPlot[Table[{n,s[n]}, {n, 1, 100}]];
plot2=Plot[-((π^2)/12), {x, 1, 100}];
Show[plot1, plot2]

b) Observe that (lim_(j->∞))((j-1)/j)=1≠0.  Hence, the series does not converge according to the Test for Divergence. This explains the following output message from Mathematica if we attempt to evaluate the series.

(∑_(j=1)^∞)((j-1)/j)

c) Since this is a telescoping series, it can be shown that the nth partial sum is given by (Subscript[s, n])=1-(1/(Sqrt[n+1])).  This can be seen in the following output:

s[n_]:=(∑_(k=1)^n)((1/(Sqrt[k]))-(1/(Sqrt[k+1])))

TableForm[Table[{n,s[n]},{n,1,10}],
TableHeadings->{{}, {"n", " (Subscript[s, n])"}}]

Hence, the series converges to 1, which we confirm with Mathematica.

(∑_(n=1)^∞)((1/(Sqrt[n]))-(1/(Sqrt[n+1])))

d) This, too, is a telescoping series with the nth partial sum given by (Subscript[s, n])=ln (n+1) (verify this).  Hence, the series diverges, as shown by the following output.

(∑_(n=1)^∞)(Log[n+1]-Log[n])

Exercises

1. Consider the series (∑_(n=1)^∞)(1/((n^2)+3n+2)).

a.  Use the Apart command to decompose the terms of the series, (Subscript[a, n])=(1/((n^2)+3n+2)), into partial fractions.

b.  Use part (a) to find a formula for the nth partial sum of the series.

c) Is the series convergent? If so, then find its sum.

In Exercises 2 through 5, determine if the given series is convergent.  If it is, then find its sum.

2.  (∑_(n=1)^∞)(1/(n(n+1)))				3.  (∑_(n=0)^∞)((((-1))^n)/(n!))				4.  (∑_(n=1)^∞)(((-1))^(n+1))

5. The sereis (∑_(n=0)^∞)a (r^n) is called a geometric series.

a.   Find the nth partial sum of the geometric series.
b.   For what values of r does the series converge? Diverge?
c.   Find the sum of the geometric series for those values where the series converges.

6.  Consider the series (∑_(n=1)^∞)(1/(n^(1/3))).

a.  Use the ListPlot command to plot the first ten partial sums of this series.

b.  Show that the series converges.

10.3  Tests for Convergence

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

10.3.1  Comparison and Limit Comparison Tests

The Comparison Test: Suppose 0≤(Subscript[a, n])≤(Subscript[b, n]) for all n>M, where M is some positive integer.

a) If (∑_(n==1)^∞)(Subscript[b, n]) is convergent, then (∑_(n=1)^∞)(Subscript[a, n]) is also convergent.

b) If (∑_(n==1)^∞)(Subscript[a, n]) is divergent, then (∑_(n=1)^∞)(Subscript[b, n]) is also divergent.

The Limit Comparison Test: Suppose (Subscript[a, n]) and (Subscript[b, n]) are both positive and  (lim_(n->∞))((Subscript[a, n])/(Subscript[b, n]))=l. If  0<l<∞ (i.e.,, if l is a finite positive number), then (∑_(n=1)^∞)(Subscript[a, n]) and (∑_(n=1)^∞)(Subscript[b, n]) both converge or both diverge.

To test convergence of a given series(∑_(n=1)^∞)(Subscript[a, n]) using the Limit Comparison Test,  it is important that the series (∑_(n=1)^∞)(Subscript[b, n]) easily be checked for convergence.

Example 10.11.  Discuss the convergence of the series

(∑_(n=1)^∞) (1/( (Sqrt[(n^2)+2])))

Solution:  Since (1/( (Sqrt[(n^2)+2])))<(1/(Sqrt[(n^2)]))=(1/n) and the harmonic series (∑_(n=1)^∞) (1/( n)) was shown to divergence in Example 10.8 of this text, it follows by the Comparison Test that our series diverges also.  This is verified by Mathematica:

(∑_(n=1)^∞)(1/(Sqrt[(n^2)+2]))

Example 10.12.  Discuss the convergence of the series

(∑_(n=1)^∞) ((3(n^3)+40(n^2)+4)/((n^5)+200(n^4)+1))

Solution: To find another series to compare ours with, we consider one with terms (Subscript[b, n])=(3/(n^2)).  This comes from considering lower powers of n in both the numerator and denominator of (Subscript[a, n]).

Clear[a,b,n]
a[n_]:=((3(n^3)+40(n^2)+4)/((n^5)+200 (n^4)+1))
b[n_]:=(3/(n^2))

Limit[((a[n])/(b[n])), n->Infinity]

Since the series (∑_(n=1)^∞)(3/(n^2)) is convergent (p-series) and (lim_(n->∞))((Subscript[a, n])/(Subscript[b, n]))=1, we conclude from the Limit Comparison Test that our series (∑_(n=1)^∞) ((3(n^3)+40(n^2)+4)/((n^5)+200(n^4)+1)) is also convergent.

Example 10.13.  Discuss the convergence of the series (∑_(n=1)^∞)[1-cos((1/n))].

Solution: We note that  (lim_(n->∞))[1-cos((1/n))]=0.  This is confirmed by Mathematica.

Limit[1-Cos[1/n],n->∞]

Thus, the necessary condition for convergence is satisfied. But this does not guarantee convergence.  We will use the ListPlot command to plot the graph of the partial sums to see if the series converges.

Clear[s]
s[n_]:=Sum[1-Cos[1/k], {k,1, n}]

ListPlot[Table[{n,s[n]},{n, 1, 100}],PlotRange->{0,1}]

The graph above clearly indicates convergence. To see that this is indeed true, we compare it with a series that is known to converge: (∑_(n=1)^∞)(1/(n^2)). To this end, let us define (Subscript[a, n]) and (Subscript[b, n]) as follows.

Clear[a,b,n]
a[n_]:=1-Cos[(1/n)]
b[n_]:=(1/(n^2))

Observe that both (Subscript[a, n]) and (Subscript[b, n]) are positive terms for all n. Hence, we can apply Limit Comparison Test:

Limit[((a[n])/(b[n])), n->Infinity]

Therefore, the given series, (∑_(n=1)^∞)[1-cos((1/n))], converges.

10.3.2  The Integral Test

The Integral Test.  Given an infinite series

(∑_(n=1)^∞)(Subscript[a, n])

we define f(x) so that f(n)=(Subscript[a, n]) . If f(x) is positive on the interval [1, ∞), decreasing on this interval, and if (lim_(x->∞))f(x)=0, then

(∫_1^∞)f(x)dx     and      (∑_(n=1)^∞)(Subscript[a, n])

both converge or both diverge.

Example 10.14.  Use the integral test to determine the convergence of the following series.

a)   (∑_(n=1)^∞)(1/(Sqrt[n])) 		c)    (∑_(j=1)^∞) j (e^(-(j^2)))		c)  (∑_(n=1)^∞)(1/((Sqrt[n])ln n))

Solution:

a) Here, (Subscript[a, n])=(1/(Sqrt[n])) and so we define f(n) in Mathematica:

Clear[f,x]
f[x_]:=(1/(Sqrt[x]))

f'[x]

Since f'(x)<0 for all x∈[1,∞), it follows that f is decreasing.  Clearly f is positive in value and  (lim_(x->∞))f(x)=0. Thus we can apply the Integral Test by evaluating (∫_1^∞)f(x)dx:

Integrate[f[x], {x, 1, Infinity}]

To confirm this, we evaluate this improper integral according to its limit definition:

Clear[F,b]
F[b_]:=Integrate[f[x], {x, 1, b}]

Limit[F[b], b->∞]

b) Here, we define f as

Clear[f,x]
f[x_]= x (E^(-(x^2)))

Plot[f[x],{x, 0, 5},PlotRange->{0,1}]

The graph clearly shows that the function is decreasing. We can confirm this by solving

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

f'[1]

N[1/Sqrt[2]]

Thus, f has critical points at ±(1/(Sqrt[2]))≈0.707.  Since f'(1)<0, we conclude that f  is decreasing on (1, ∞).

The graph also shows that (lim_(x->∞))f(x)=0. Again, we can confirm this by evaluating

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

Hence, the Integral Test can be used to determine if the series is convergent. That the series (∑_(j=1)^∞)j (e^(-(j^2))) is convergent follows from the fact that

(∫_1^∞)f[x]\[DifferentialD]x

Since the corresponding integral is convergent, it follows that the series (∑_(j=1)^∞)j (e^(-(j^2))) is also convergent.

c) In this case, we define f as

Clear[f,x]
f[x_]=(( 1)/((Sqrt[x])Log[x]))

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

We leave it for the reader to check that f satisfies all the conditions of the Integral Test, which we now apply.

(∫_2^∞)f[x]\[DifferentialD]x

Since the preceding output states that the integral is divergent, we conclude that the corresponding series is divergent also.

Example 10.15.  For what values of p does the series (∑_(n=2)^∞)(1/((n(ln n))^p)) converge?

Solution: We apply the Integral Test.  Toward this end, we define f(x) so that f(n)=(1/((n(ln n))^p)) and then verify that f(x) is positive and decreasing on the interval [a, ∞),  and that (lim_(x->∞))f(x)=0:

Clear[f,x,p]
f[x_]:=(1/(x (((Log[x]))^p)))

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

To confirm this limit, we will plot graphs of f(x) for some values of p

Plot[Evaluate[Table[f[x], {p, -4, 2, .5}]], {x, 2,100},PlotRange->{0,5}]

In the plot above, observe that some of the graphs are initially increasing, but then begin to decrease at a certain point.  Let us then find the interval over which the functionf(x) is decreasing for each  p. To this end, we compute the derivative f'(x) and solve f'(x)<0 for x.

f'[x]

Simplify[%]

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

Since (((ln x))^(-1-p))>0 for all x>1, we see that f'(x)<0 if ln x>-p, or equivalently, x=(e^(-p)).  Thus, f(x) is decreasing on [2, ∞) where a is the maximum of 2 and (e^(-p)).

To apply the Integral Test, we integrate fover the interval [2,∞).  This is easier than integrating over the interval [a,∞), and permissible since the integrals (∫_2^∞)f(x)dx and (∫_a^∞)f(x)dx either converge or diverge together.

Integrate[f[x],{x,2,∞}]

The preceding output shows that (∫_2^∞)f(x)dx is convergent for p>1.  However, the case p≤1 remains unsolved.  To evaluate the integral in this situation, we define its anti-derivative F(b)=(∫_2^b)f(x)dx and find the limit of F(b) as b-> ∞.

Clear[F,b]
F[b_]=Integrate[f[x], {x, 2, b}]

Since b is a real number and b>2 , the solution to our integral is the first one, that is, F(b)= (((((ln 2))^(1-p))-ln (((b))^(1-p)))/(1-p)), provided p≠1. But then for p<1, we see that (lim_(b->∞))F(b)=∞ since (lim_(b->∞))((ln(b))^(1-p))=∞.  For p>1, we have (lim_(b->∞))F(b)=((((ln 2))^(1-p))/(1-p)) , which we already knew from the second previous Mathematica output.  The following tables might be helpful to convince you about this.

Table[Limit[F[b], b->Infinity], {p, -3, .9, .5}]

Table[Limit[F[b], b->Infinity], {p, 1.1, 9, .5}]

For p=1, we make this substitution inside the integral and evaluate it directly:

p=1;
Integrate[f[x], {x, 2, ∞}]

Therefore, the infinite series (∑_(n=2)^∞)(1/((n(ln n))^p)) is convergent for p>1 and divergent for p≤1.

NOTE: To see how slow the growth of this series is for the value of p=1, we consider the following table of partial sums. Recall that f(n) is the nth term of the series and hence the nth partial sum is given by

Clear[p,s,n]
s[n_]=Sum[f[k], {k, 2, n}]

The following output shows that the sum of the first ten thousand terms is only about 3.01501088.

p=1;
N[s[10000]]

Here is a plot of the graph of the first ten thousand partial sums in steps of 1,000.

ListPlot[Table[{n, s[n]}, {n, 1000, 10000, 1000}]]

10.3.3  Absolute and Conditional Convergence

Suppose (Subscript[a, n])>0 for all n. The infinite series

(∑_(n=1)^∞)(((-1))^n)(Subscript[a, n])

is called an alternating series.  If the series (∑_(n=1)^∞)(((-1))^n)(Subscript[a, n]) is convergent but the series (∑_(n=1)^∞)(Subscript[a, n]) is divergent, then the alternating series is called conditionally convergent.  If (∑_(n=1)^∞)(Subscript[a, n]) is convergent, then the alternating series  (∑_(n=1)^∞)(((-1))^n)(Subscript[a, n]) is called absolutely convergent.

Alternating Series Test: If (Subscript[a, n]) is decreasing and (lim_(n->∞))(Subscript[a, n])=0, then the series (∑_(n=1)^∞)(((-1))^n)(Subscript[a, n]) is convergent.

Example 10.16.  Determine if the given series is conditionally or absolutely convergent.

a)   (∑_(n=1)^∞)((((-1))^n)/((n^2)+1)) 		c)    (∑_(n=2)^∞) ((((-1))^n)/(n ln n))

Solution:

a) We define (Subscript[a, n])=(1/((n^2)+1)) in Mathematica and check that (Subscript[a, n]) satisfies the conditions of the Alternating Series Test.

Clear[a,n]
a[n_]:=  (1/((n^2)+1))

Limit[a[n],n->∞ ]

f[x_]=a[x];
f'[x]

Thus, (Subscript[a, n]) is decreasing since f'(x)>0, where f(n)=(Subscript[a, n]).  Moreover, (Subscript[a, n]) converges to 0. Hence, the series (∑_(n=1)^∞)((((-1))^n)/((n^2)+1))   is convergent by the Alternating Series Test.

To check absolute convergence, we use the Limit Comparison Test with (Subscript[b, n])=(1/(n^2)).

Limit[((a[n])/(1/(n^2))), n->Infinity]

Since the series (∑_(n=1)^∞)(1/(n^2)) is convergent and the previous output shows (lim_(n->∞))((Subscript[a, n])/(Subscript[b, n]))=1, we conclude that the series (∑_(n=1)^∞)(Subscript[a, n])=(∑_(n=1)^∞)(1/((n^2)+1)) is also convergent.  Therefore, the alternating series (∑_(n=1)^∞)((((-1))^n)/((n^2)+1))  is absolutely convergent.

b) We procced as in part a).

Clear[a,n]
a[n_]:=  (1/( n Log[n]))

Limit[a[n],n->∞ ]

f[x_]=a[x];
f'[x]

For the same reasons we conclude that (Subscript[a, n]) is decreasing and converges to 0.  Hence, the series (∑_(n=2)^∞)((((-1))^n)/( n ln n))   is convergent by the Alternating Series Test.

To check absolute convergence, we apply the Intgeral Test to f(x):

Clear[m]
Limit[(∫_2^m)f[x]\[DifferentialD]x,m->Infinity]

From this, we conclude that the series is conditionally convergent.

Example 10.17.  Show that the series

(∑_(n=1)^∞)((((-1))^n)/(Sqrt[(n^2)+1]))

is conditionally convergent.  Find a value of n for which the partial sum (Subscript[s, n]) approximates the series by an error less than (10^(-5)).  Also, find the corresponding value for (Subscript[s, n]).

Solution: We leave it for the reader to check that the series converges conditionally as in the preceding example.  For the second part of the problem, we proceed by first defining the partial sums of the series.

Clear[s,a,n]
a[n_]:=(1/(Sqrt[(n^2)+1]))
s[n_]:=Sum[(((-1))^k) a[k], {k, 1, n}]

If S denotes the sum of the alternating series, it can be shown that |S-(Subscript[s, n])|<(Subscript[a, n+1]) (refer to your calculus text for a proof of this fact).  The following table of values gives some numerical evidence of this fact:

Table[{N[Abs[(∑_(n=1)^∞)((((-1))^n)/(Sqrt[(n^2)+1]))-s[m]]],N[a[m]]},{m,1,10 }]

Clear[S,n]
S=(∑_(n=1)^∞)((((-1))^n)/(Sqrt[(n^2)+1]))

The table below gives the values of (Subscript[a, n]) for large values of n.

Table[N[a[(10^n)] ], {n, 1,10  }]

Thus, n=(10^6) is a possible value. But solving (Subscript[a, n])=(10^(-5)) can give us a more accurate value.

NSolve[a[x]==(10^(-5)),x]

Thus, if n=100001, we have |S-(Subscript[s, n])|<(10^(-5)).  We confirm this with Mathematica:

N[S-s[100001]]

Can you find a smaller value of n for which |S-(Subscript[s, n])|<(10^(-5))?

10.3.4  Ratio Test

The Ratio Test:  Suppose (Subscript[a, n])>0 and let

r=(lim_(n->∞))((Subscript[a, n+1])/(Subscript[a, n])).

a) If r<1, the series (∑_(n=1)^∞)(Subscript[a, n]) converges. 
b) If r>1, the series (∑_(n=1)^∞)(Subscript[a, n]) diverges.
c) If r=1, no conclusion can be drawn about the convergence of the series (∑_(n=1)^∞)(Subscript[a, n]).  In other words, if r=1, then we must use another test to determine the convergence.

Example 10.18.  Use the Ratio Test to determine the convergence of the following series.

a)   (∑_(n=1)^∞)((n^n)/(n!)) 		c)    (∑_(j=2)^∞) (1/(j (((ln j))^3)))		c)  (∑_(n=1)^∞) ((3(n^3)+40(n^2)+4)/((n^5)+200(n^4)+1))

Solution: For each series, we define (Subscript[a, n]) to be its nth term and evaluate (lim_(n->∞))((Subscript[a, n+1])/(Subscript[a, n])).

a)

Clear[a,n]
a[n_]:= ((n^n)/(n!))

Limit[a[n+1]/a[n],n->∞ ]

Since e>1, the series (∑_(n=1)^∞)((n^n)/(n!)) converges by the Ratio Test.

b)

Clear[a,j]
a[j_]:= (1/(j(((Log[j]))^3)))
 Limit[a[j+1]/a[j],j->∞ ]

This output means that we must use a different test. However, this is an instance of Example 11.12 in this text with p=3.  Hence, the series converges by the Integral Test.

c)

Clear[a,n]
a[n_]:= ((3(n^3)+40(n^2)+1)/((n^5)+200(n^4)+1))

Limit[a[n+1]/a[n],n->∞ ]

Again, this output means we are forced to use a different test.  Therefore, we shall use the Limit Comparison Test instead. To this end, we define (Subscript[b, n])=(3/(n^2)):

Clear[b,n]
b[n_]:=(3/(n^2))

Limit[((a[n])/(b[n])), n->Infinity]

Since the series (∑_(n=1)^∞)(1/(n^2)) is convergent, we conclude that the series (∑_(n=1)^∞) ((3(n^3)+40(n^2)+4)/((n^5)+200(n^4)+1)) is also convergent.

10.3.5  Root Test

The Root Test:  Suppose (Subscript[a, n])>0 and let

r=(lim_(n->∞))((((Subscript[a, n])))^(1/n)).

a) If r<1, the series (∑_(n=1)^∞)(Subscript[a, n])converges. 
b) If r>1, the series (∑_(n=1)^∞)(Subscript[a, n]) diverges.
c) If r=1, no conclusion can be drawn about the convergence of the series (∑_(n=1)^∞)(Subscript[a, n]). In other words, if r=1, then we must use another test to determine the convergence.

Example 10.19.  Use the Root Test  to determine the convergence of the following series:

a)   (∑_(n=1)^∞)((((n/(2n+1))))^n) 		b)    (∑_(n=1)^∞) (1/(n  (3^n)+(n^2)))		c)  (∑_(n=1)^∞)((3n+1)/((n^2)+n+1))

Solution: For each series we define (Subscript[a, n]) to be its nth term and evaluate (lim_(n->∞))((((Subscript[a, n])))^(1/n)).

a)

Clear[a,n]
a[n_]:= ((((n/(2n+1))))^n)

Limit[(((a[n]))^(1/n)),n->∞ ]

Thus, the series (∑_(n=1)^∞)((((n/(2n+1))))^n) converges by Root Test.

b)

Clear[a,n]
a[n_]:=  (1/(n (3^n)+(n^2)))

Limit[(((a[n]))^(1/n)),n->∞ ]

Even though the preceding Limit command is returned as unevaluated, the N command reveals that it is approximately 1/3.

N[%]

To verify this, we use the Squeeze Theorem (discussed in your calculus text) with (Subscript[b, n])=(1/(2 n (3^n))) and (Subscript[c, n])=(1/(n (3^n))).  First, note that (Subscript[b, n])≤(Subscript[a, n])≤(Subscript[c, n]).  We can verify this using the following plot:

Plot[{((3^(-x))/(2x)), a[x],((3^(-x))/x)}, {x, 1, 10}, PlotStyle->{Green, Red, Blue}]

We now define (Subscript[b, n ])and (Subscript[c, n]) as and evaluate (lim_(n->∞))((((Subscript[c, n])))^(1/n))  and (lim_(n->∞))((((Subscript[b, n])))^(1/n)).

Clear[b, c, n]
b[n_]:=(1/(2 n (3^n)))
c[n_]:=(1/(n (3^n)))

Limit[(((b[n]))^(1/n)), n->Infinity]
Limit[(((c[n]))^(1/n)), n->Infinity]

Thus, we also have (lim_(n->∞))((((Subscript[a, n])))^(1/n))=(1/3) and hence the series converges by the Root Test.

c)

Clear[a,n]
a[n_]:= ((3n+2)/((n^2)-n+1))

Limit[ (((a[n]))^(1/n)),n->∞ ]

The Root Test fails. Let us try the Ratio Test:

Limit[((a[n+1])/(a[n])), n-> Infinity]

The Ratio Test fails as well. We can easily verify that the Integral Test is applicable. We will evaluate the integral

(∫_1^∞)a[x]\[DifferentialD]x

To confirm the divergence of the improper integral, we leave it to the reader to evalaute the function F(x) defined below for large values of x.

Clear[F,b]
F[b_]:=(∫_1^b)a[x]\[DifferentialD]x

Exercises

In Exercises 1 through 6, use the Comparison Test or the Limit Comparison Test to determine if the given series is convergent. If it is convergent, then find its sum.

1.  (∑_(n=1)^∞)(n/(Sqrt[(n^3)+1]))			2.  (∑_(n=2)^∞) ((ln n)/((n^2)+3 ln n))			3.  (∑_(n=1)^∞) (((n^4)+200(n^2)+1000n+2222)/((n^6)+5(n^4)+n+1))

4.  (∑_(n=1)^∞)((ln n)/( (n^2)))		   		5.  (∑_(n=2)^∞) (( 1 )/((n^(ln n)) ))				6.  (∑_(n=1)^∞) (1-(2^(-1/n)))

In Exercises 7 through 9, use the Integral Test to determine if the given series is convergent. If it converges, then find its sum.

7.  (∑_(n=1)^∞)(n/((n^2)+1))				8.  (∑_(n=2)^∞) (n/(2^n))				9.  (∑_(n=1)^∞)  ((((ln n))^3)/(n^2))

10. For what values of p does the series (∑_(n=1)^∞)(1/((n^p) ln n)) converge?

11. Consider the series (∑_(n=2)^∞)((((ln n))^k)/(n^p)).

a.   Fix a value of p (say, p=2 or p=1/2) and find all values of k for which the series converges.

b.   Fix a value of k (say, k=2 or k=-2) and find all values of p for which the series converges.

c.   Generalize the results of a) and b) to all values of p and k.

12.  Let f be  a positive valued function that decreases on [1, ∞) and let (Subscript[a, n])=f(n). It can be shown that

(∫_1^∞)f(x)dx≤(∑_(n=1)^∞)(Subscript[a, n])≤(Subscript[a, 1])+(∫_1^∞)f(x)dx .

a.  Use f(x)=(1/(x^1.1)) to verify this.

b.  Approximate (∑_(n=1)^∞)(1/(n^1.1)) using its nth partial sums with n=10, 100, 1000, 10000.

In Exercises 13 through 16, determine if each of the infinite series is absolutely convergent, conditionally convergent, or divergent. Justify your conclusions! 
13.  (∑_(n=1)^∞)(((((-1))^n)((n^2)-1))/((n^2)+1))		14. (∑_(n=1)^∞)((20(n^2)-n-1)/((n^3)+(n^2)+33))		15. (∑_(n=1)^∞)((((-2))^n)/(n!))		16.  (∑_(n=1)^∞)(((-1))^(n+1))[(Sqrt[n+1])-(Sqrt[n]) ]

17.  Discovery Exercise: 
a.  Determine the convergence or divergence of (∑_(n=2)^∞)(1/(n ln (((ln ln n))^0.5))), (∑_(n=2)^∞)(1/(n ln (((ln ln n))^( )))), and (∑_(n=2)^∞)(1/(n ln (((ln ln n))^2))).
b.  Generalize your work in part a) by determining for which real numbers p the series(∑_(n=2)^∞)(1/(n ln (((ln ln n))^p))) converges.

In Exercises 18 through 25, determine the convergence or divergence of the given infinite series using any of the convergence tests discussed in this section.

18. (∑_(n=1)^∞)((3n+1)/(4n+5)) 			19. (∑_(n=1)^∞)(n/(2(n^2)+1))	 	20. (∑_(n=1)^∞)((n+3)/(4(n^3)+5))  		21. (∑_(n=1)^∞)((n((2/3)))^n) 

22. (∑_(n=1)^∞)((n((3/2)))^n) 		23. (∑_(n=1)^∞)((n^n)/(n!))			24. (∑_(n=1)^∞)((((n!))^2)/((3n)!)) 			25. (∑_(n=0)^∞)(((-1))^n)(((1+(1/n)))^n)

26.  The Ratio Test proved to be inconclusive for some of the series in the previous exercise. Can you conjecture for what type of series the Ratio Test will fail in general? Use other tests to rework the problems in the first exercise where the Ratio Test failed.

27. Of the following four conditions, one guarantees that a series will diverge, two conditions guarantee that a series will converge, and one has no guarantee (the series can either converge or diverge).  Identify each one and explain your reasoning.

(lim_(n-> ∞))|((Subscript[a, n+1])/(Subscript[a, n]))|= 0
(lim_(n-> ∞))|((Subscript[a, n+1])/(Subscript[a, n]))|= (1/2)
(lim_(n-> ∞))|((Subscript[a, n+1])/(Subscript[a, n]))|= 1
(lim_(n-> ∞))|((Subscript[a, n+1])/(Subscript[a, n]))|= 2

28.  Identify the two series that are the same:

a. (∑_(n=1)^∞)((n((3/4)))^n)			b. (∑_(n=0)^∞)(n+1)  ((((3/4)))^n)			c. (∑_(n=1)^∞)((n((3/4)))^(n-1))

In Exercises 29 through 32, determine the convergence or divergence of the series: 

29.  (∑_(n=1)^∞)(2(n^(1/n))+1)n	 		30, (∑_(n=0)^∞)(e^(-n)) 			31. (∑_(n=1)^∞)(((((-2n)/(3n+1))))^(3n)) 			32. (∑_(n=1)^∞)((n/(2n+1)))n

33. Construct two examples of infinite series, the first convergent and the second divergent, for which the Root Test generates inconclusive information.

34. Use the Root Test to test for convergence or divergence of the series:

a. (1/(((ln 3))^3))+(1/(((ln 4))^4))+(1/(((ln 5))^5))+(1/(((ln 6))^6))+...

b. 1+ (2/3)+(3/(3^2))+(4/(3^3))+(5/(3^4))+(6/(3^5))+...

Hint: Write a formula for the general nth term in each case.

10.4  Power Series

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

10.4.1  Taylor Polynomials

The Taylor polynomial of a given function f at a point x=a is given by

(Subscript[T, n])(x)=f(a)+f'(a)(x-a)+((f''(a))/(2!))(((x-a))^2)+((f'''(a))/(3!))(((x-a))^3)+.... + (((f^((n)))(a))/(n!))(((x-a))^n).

The Mathematica Series[f,{x, a, n}] generates the nth Taylor polynomial (Subscript[T, n])(x) plus a term of the form ((O[x])^(n+1)).  To obtain the Taylor polynomial without this term, we use the command Normal[Series[f,{x, a, n}]].

The nth remainder (Subscript[R, n])(x) of f(x) at x=a is defined by

(Subscript[R, n])(x)=f(x)-(Subscript[T, n])(x).

Taylor's Theorem states that

(Subscript[R, n])(x)=(1/(n!))(∫_a^x)(f^((n+1)))(u)(((x-u))^n)du.

Here is a way to define the Taylor polynomial of fat x=a by defining (Subscript[T, n])(x) and the nth remainder (Subscript[R, n])(x) (using Taylor's Theorem for (Subscript[R, n])) without referring to Mathematica's built-in command Series.

Clear[a, x, f,T,R]
T[x_,a_, n_]:=(∑_(k=0)^n)((D[f[x],{x,k}]/.x->a)/(k!))(((x-a))^k)
 R[x_,a_, n_]:=(1/(n!))(∫_a^x)D[f[u],{u,n+1}]*(((x-u))^n) \[DifferentialD]u

Example 10.20.  Let f(x)=(e^x).  Find its 5th Taylor polynomial at x=0.

Solution: We use the Series command to obtain the answer:

Normal[Series[(E^x),{x,0,5}]]

Using the polynomial T[x,a,n], we defined above we get

Clear[f]
f[x_]:=(E^x)
T[x, 0, 5]

R[x,0,5]

Example 10.21.	 Find the nth Taylor polynomial of f(x) at x=a for various values of a and n.

a) f(x)=(Sqrt[x])	 	b)  f(x)=cos x

Solution:  a) We shall use the same function T[x,a,n] defined in the previous example (make sure you evaluate this function before you evaluate the table below).

Clear[a, x, f]
T[x_,a_, n_]:=(∑_(k=0)^n)((D[f[x],{x,k}]/.x->a)/(k!))(((x-a))^k)
R[x_,a_, n_]:=(1/(n!))(∫_a^x)D[f[u],{u,n+1}]*(((x-u))^n) \[DifferentialD]u

Clear[f]
f[x_]=(Sqrt[x])
TableForm[Table[ T[x, a, n] ,  {a,1, 5},{n, 1, 3}]  , 
TableHeadings->{{"at a=1", "at a=2","at a=3","at a=4","at a=5"},{"n=1","n=2","n=3"}}]

b) We proceed as in part a):

Clear[f]
f[x_]=Cos[x]
TableForm[Table[ T[x, a, n] ,  {a,0, 2Pi, Pi/2},{n, 1, 4}]  , 
TableHeadings->{{"at a=0", "at a=π/2","at a=π","at a=3π/2","at a=2π"},{"n=1","n=2","n=3","n=4"}}]

Example 10.22.  Let f(x)=(1/(2 +3(x^2))).

a) Find the Taylor polynomials (Subscript[T, n])(x) of f at  x=0 for n=1,2,..., 6.
b) Draw the graphs of the function f and its Taylor polynomials found in part a).
c) Over which interval does the nth Taylor polynomial gives a close approximation to f(x) if n=4, n=10, and n=20?

Solution:

a) Here are the Taylor polynomials up to order n=6.

Clear[f]
f[x_]=(1/(2+3(x^2)))
TableForm[Table[ {n,T[x, 0, n]} ,{n, 1, 6}]  , 
TableHeadings->{{},{"n", "(Subscript[T, n]) at a=0"}}]

b)  We first use the Plot command to plot the graphs of f and its Taylor polynomial at x=0 for the desired values of n.  We then use the Show command to plot both graphs on the same axes.

Clear[plot1,plot2]
plot1=Plot[f[x],{x,-3,3}, PlotStyle->  Red];
plot2=Plot[Evaluate[Table[T[x,0,n],{n, 1, 6}]], {x,-3,3}]  ;
Show[plot1,plot2]

c) We use the same commands as in part b) except that we do not use the Table command. The first one is for the case n=4.

Clear[plot1,plot2] 
plot1=Plot[f[x],{x,-3,3}, PlotStyle->  Red];
plot2=Plot[Evaluate[T[x,0,4]], {x,-3,3}]  ;
Show[plot1,plot2]

It seems that the two graphs are close to each other  if x is in the interval (-0.5, 0.5). To see this close up, we recommend that you change the range of values for x in both plots (plot1 and plot2) to the interval [-1,1]. We can confirm this by plotting the 4th remainder of f(x) at x=0.

Plot[Evaluate[R[x,0,4]],{x, -1,1}, PlotRange->{-1,1}]

We repeat the above with n=10.

Clear[plot1,plot2]
plot1=Plot[f[x],{x,-3,3}, PlotStyle->  Red];
plot2=Plot[Evaluate[T[x,0,100]], {x,-3,3}]  ;
Show[plot1,plot2]

The graph above clearly indicates the 10th Taylor polynomial gives a close approximation for f in the interval [-.6,.6]. Again, plotting  (Subscript[R, n]) will confirm this.

Plot[Evaluate[R[x,0,10]],{x, -1,1}, PlotRange->{-1,1}]

If we continue in this manner, we see that the Taylor polynomial  (Subscript[P, n]) for large values of n gives a better approximation of f in the interval [-1,1].  In fact, for n=20, we see that (Subscript[R, n])(x) is almost zero in the interval [-0.7,0.7], which is an improvement over the previous interval [-0.6,0.6] obtained for n=10.

Plot[Evaluate[R[x,0,20]],{x, -1,1}, PlotRange->{-1,1}]

10.4.2  Convergence of Power Series

A series of the form

(∑_(n=0)^∞)(((Subscript[a, n])(x-(Subscript[x, 0])))^n)=(Subscript[a, 0])+(Subscript[a, 1])(x-(Subscript[x, 0]))+(((Subscript[a, 2])(x-(Subscript[x, 0])))^2)+(((Subscript[a, 3])(x-(Subscript[x, 0])))^3)+ ....

is called a power series.

The set of all x for which the series converges is called the interval of convergence.

If the series converges for x=(Subscript[x, 0]) only, we say is radius of interval is R=0. In this case, its interval of convergence is {(Subscript[x, 0])}.

If the series converges for all real numbers x, we say its radius of convergence is R=∞. In this case, its interval of convergence is (-∞,∞).

If the series converges for some x≠(Subscript[x, 0]) and diverges for some y, then it can be shown that there exists R>0 such that the power series converges for all x for which |x-(Subscript[x, 0])|<R and diverges for all x for which |x-(Subscript[x, 0])|>R. The convergence at x=(Subscript[x, 0])-R and x=(Subscript[x, 0])+R needs to be checked.

When the radius of convergence R is a positive real number, there are four possiblities for the interval of convergence:

((Subscript[x, 0])-R, (Subscript[x, 0])+R) or [(Subscript[x, 0])-R, (Subscript[x, 0])+R) or ((Subscript[x, 0])-R, (Subscript[x, 0])+R] or [(Subscript[x, 0])-R, (Subscript[x, 0])+R]

depending on the convergence at the end points of the intervals.

The radius of convergence R of the power series (∑_(n=0)^∞)(((Subscript[a, n])(x-(Subscript[x, 0])))^n) can be found by using the Ratio or Root Test.  Let

r=(lim_(n->∞))|((Subscript[a, n+1])/(Subscript[a, n]))|    or    r=(lim_(n-> ∞))((|(Subscript[a, n])|)^(1/n))

a) If r=0, then R=∞. 
b) If r=∞, then  R=0 .
c) If 0<r<∞, then R=(1/r).

Example 10.23.  Find the radius and interval of convergence for the given power series.

a)   (∑_(n=0)^∞)(n/(2n+1)) (x^n) 		b)    (∑_(n=1)^∞) ((((x-3))^n)/(n (3^n)))		c)  (∑_(n=0)^∞)((((x+2))^n)/((n^2)+n+1))

d)   (∑_(n=0)^∞)(n^n) (x^n) 		e)    (∑_(n=0)^∞) (1/(n!))(((x-1))^n)

Solution:

a) Let us define (Subscript[s, m])(x) to be the mth partial sum of the series and plot the graph of some of these partial sums. We will plot every 100th partial sum up to 10,000 terms.

Clear[s,n,m]
s[x_,m_]:=(∑_(n=0)^m)(n/(2n+1))(x^n)

Plot[Evaluate[Table[s[x, m],{m,1, 1000, 100}]], {x, -2,2}]

This clearly indicates that the partial sums diverge outside (-1,1). Here is the plot over the interval (-1,1).

Plot[Evaluate[Table[s[x, m],{m,1, 1000, 100}]], {x, -1,1}]

We now use calculus. Here, note that (Subscript[a, n])=(n/(2n +1)) and (Subscript[x, 0])=0. We first define (Subscript[a, n]) in Mathematica and find the radius of convergence. We recall |a| (absolute value of a) is entered as Abs[a].

Clear[a,n,r]
a[n_]:=(n/(2n+1))

r= Limit[Abs[((a[n+1])/(a[n]))], n->Infinity]

Thus, the radius of convergence is R=(1/r)=(1/1)=1. The power series convrges on (-1, 1). To check convergence at the endpoints x=-1 and x=1, we note that the power series becomes (∑_(n=0)^∞)(n/(2n+1))(((-1))^n)and (∑_(n=0)^∞)(n/(2n+1))(((1))^n), both of which are divergent, since their nth terms do not converge to 0. Here, Mathematica confirms the divergence at the endpoints.

(∑_(n=0)^∞)(n/(2n+1))(((-1))^n)

(∑_(n=0)^∞)(n/(2n+1))(((1))^n)

Therefore, the interval of convergence is (-1,1).

b)   (∑_(n=1)^∞) ((((x-3))^n)/(n (3^n)))

Clear[a,r,n]
a[n_]:=(1/(n (3^n)))

r=Limit[((a[n+1])/(a[n])), n->Infinity]

Thus the radius of convergence is R=(1/r)=(1/(1/3))=3.

Since (Subscript[x, 0])=3, the power series converges on ((Subscript[x, 0])-R, (Subscript[x, 0])+R)=(3-3,3+3)=(0,6). We need to check the endpoints x=0 and x=6. We substitute these in the power series and evaluate

(∑_(n=1)^∞)((((x-3))^n)/(n (3^n)))/.x->{0,6}

Thus, the interval of convergence is [0,6).

c)  (∑_(n=1)^∞)((((x+2))^n)/((n^2)+n+1))

Clear[a,r,n]
a[n_]:=(1/((n^2)+n+1))

r=Limit[Abs[((a[n+1])/(a[n]))], n-> ∞]

Hence, the radius of convergence is R=(1/1)=1. Since (Subscript[x, 0])=-2, we see that the power series converges at least on the open interval (-2-1,-2+1)=(-3,-1). To determine the actual interval of convergence we need to check the endpoints. As in part c), we evaluate

(∑_(n=0)^∞)((((x+2))^n)/((n^2)+n+1))/.x->{-3,-1}

N[%]

Since this is not clear, we examine the series by plugging in by hand x=-3 and x=-1. When x=-3 the series becomes (∑_(n=1)^∞)((((-3+2))^n)/((n^2)+n+1))= (∑_(n=1)^∞)((((-1))^n)/((n^2)+n+1)), which is an alternating series. We leave it to the reader to verify that the Alternating Series Test applies in this case.  Thus, we have a convergent series.

Next, we substitute x=-1 to obtain the series (∑_(n=1)^∞)((((-1+2))^n)/((n^2)+n+1))= (∑_(n=1)^∞)(1/((n^2)+n+1)) to which we apply the Integral Test (verify that the conditions of the Integral Test are satisfied):

Integrate[(1/((x^2)+x+1)),{x,0,Infinity}]

Thus, the series converges in this case as well. Therefore, the interval of convergence for the power series is [-3,-1].

d)   (∑_(n=0)^∞)(n^n)(x^n)

Clear[a,r,n]
a[n_]:=(n^n)

r=Limit[Abs[((a[n+1])/(a[n]))],n-> ∞]

Thus, the radius of convergence is R=0 and the series converges for x=0 only.

e)    (∑_(n=0)^∞) (1/(n!))(((x-1))^n)

Clear[a,r,n]
a[n_]:=(1/(n!))

r=Limit[Abs[((a[n+1])/(a[n]))],n-> ∞]

Thus, the radius of convergence is R=∞ and the series converges for all real x.  Hence, the interval of convergence is (-∞,∞).

10.4.3  Taylor Series

The Taylor series for f(x) at x=a is given by the power series

(∑_(n=0)^∞)(((f^((n)))(a))/(n!))(((x-a))^n)=f(a)+f'(a)(x-a)+((f''(a))/2)(((x-a))^2)+((f'''(a))/6)(((x-a))^3)+.....

The Mathematica command Series[f,{x, a, n}] generates the power series of f at x=a to the order (((x-a))^n).  It is not possible to write all the terms explicitly since there are infinitely many.

Example 10.24.  Let f(x) =((1+x)/(1+(x^2))).

a) Find the first ten terms of the Taylor series of f at x =0.
b) Estimate the radius and interval of convergence of the Taylor series of f at x =0.

Solution:

a) We use the Series command to obtain the Taylor series as follows:

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

Series[f[x],{x, 0, 10}]

This output gives the Taylor series to order n=10.

b) To first gain intuition for the radius of convergence of the Taylor series, we define the nth Taylor polynomial of f(x) as a function of n (note our use of the Normal command to truncate the remainder term from the Taylor series).

Clear[T,x,n]
T[x_,n_]:=Normal[Series[f[x],{x, 0, n}]]

Here is a list of the first 20 of these polynomials.

Table[T[x,n],{n, 0, 10}]

Observe that each polynomial appears twice, that is, (Subscript[T, 2n])=(Subscript[T, 2n+1]), since f is an even function.  Next, we plot the graphs of some of these polynomials:

Clear[plot1]
plot1=Plot[Evaluate[Table[T[x,n],{n, 1, 20}]],{x,-5,3},PlotRange->{-10,10}]

To compare the graph of these polynomials, we plot the graph of f and use the Show command.

Clear[plot2]
plot2=Plot[f[x], {x,-5,3}, PlotRange->{-10,10}, PlotStyle->Red]

Show[{plot1, plot2}, PlotRange->{-10,10}]

Observe that the graphs of the Taylor polynomials in the preceding plot seem to give a good approximation to f only inside the interval (-2,2).  This suggests that the radius of convergence is 2.  This becomes more evident as we plot the graph of (Subscript[T, n]) for large values of n as shown in the following plot, where n=30,35,40,45,50.

Clear[plot3]
plot3=Plot[Evaluate[Table[T[x,n],{n, 30, 50,5}]],{x,-3,3}];
plot4=Plot[f[x], {x,-5,3}, PlotStyle->{Red, Thickness[0.002]}];
Show[{plot3, plot4}, PlotRange->{-10,10}]

To prove that the radius of convergence is indeed R=2, we first find a formula for the Taylor coefficients.  Based on the following table, it is clear that (Subscript[a, 0])=1/2 and (Subscript[a, n])=(((-1))^n)3/(2^(n+1)) (prove this for all n).

a[n_]:=D[f[x],{x,n}]/n!/.x->0
Table[a[n],{n,0,10}]

We now apply the Ratio Test on (∑_(n=0)^∞)(Subscript[a, n])(x^n).

Clear[a]
a[n_]=(-1)^n*3/2^(n+1)
r=Limit[Abs[((a[n+1])/(a[n]))],n-> ∞]

Hence, the radius of convergence is R=1/r=2.

Next, we determine whether the endpoints should be included in the interval of convergence.  For this, we evaluate our Taylor series at x=-2 and x=2.

(∑_(n=1)^∞)a[n](-2)^n
(∑_(n=1)^∞)a[n](2)^n

This shows that the Taylor series diverges at both endpoints.  Thus, the interval of convergence is (-2,2).

Example 10.25.  Let f(x)  =  sin x.

a) Find the Taylor series of f at x =0.
b) Find the radius and interval of convergence of the Taylor series.

Solution:

a) We repeat the steps in the previous example.

Clear[f]
f[x_]:=Sin[x]

Clear[T]
T[x_,n_]:=Normal[Series[f[x],{x, 0, n}]]

Table[T[x,n],{n, 0, 10}]

Observe that all terms of the Taylor polynomials are odd powers of x.  Can you explain why?

Here is a plot of the graphs of the first ten of these polynomials and the function f.

Clear[plot1,pl0t2]
plot1=Plot[Evaluate[Table[T[x,n],{n, 0, 10}]],{x,-3Pi,3Pi}];
plot2=Plot[f[x], {x,-3Pi,3Pi}, PlotStyle->Red];
Show[{plot1, plot2}, PlotRange->{-10,10}]

b) Observe that the higher the order of the Taylor polynomial the better it approximates f over a wider interval.  To see this more clearly, we plot (Subscript[T, n]) for n=20,40,60.

Clear[plot1,plot2]
plot1=Plot[f[x], {x,-40,40}, PlotStyle->Red,PlotRange->{-5,5}];
plot2=Plot[ Evaluate[T[x,20]]  ,{x,-40,40 }, PlotStyle->Blue,PlotRange->{-5,5}];
plot3=Plot[ Evaluate[T[x,40]]  ,{x,-40,40 }, PlotStyle->Blue,PlotRange->{-5,5}];
plot4=Plot[ Evaluate[T[x,60]]  ,{x,-40,40 }, PlotStyle->Blue,PlotRange->{-5,5}];
Show[{plot1, plot2}]

Show[{plot1, plot3}]

Show[{plot1, plot4}]

The preceding plots suggest that the radius of convergence for the Taylor series of sin x is R=∞.  To prove this, we first find a formula for the Taylor coefficients {(Subscript[a, n])}.  Again, based on the following table, it is clear that (Subscript[a, n])=sin(π n/2)/n! (prove this for all n).

a[n_]:=D[f[x],{x,n}]/n!/.x->0
Table[a[n],{n,0,10}]

We now apply the Root Test on (∑_(n=0)^∞)(Subscript[a, n])(x^n).

Clear[a,n,r]
a[n_]=Sin[Pi*n/2]/n!
Table[a[n],{n,0,10}]
r=Limit[Abs[a[n]]^(1/n),n-> ∞]

Hence, the radius of convergence is R=∞.

Exercises

In Exercises 1 through 6,  determine the radius and interval of convergence for the given power series.

1. (∑_(n=1)^∞)(((((-1))^(n+1))(x^n))/(4^n)) 			2. (∑_(n=0)^∞)(2n)!((x/2))n			3. (∑_(n=1)^∞)((n!(x^n))/((2n)!))
4. (∑_(n=0)^∞)(((-1))^n)((x^n)/(n+1))			5. (∑_(n=0)^∞)(((4x))^n)  				6. (∑_(n=0)^∞)((((2x))^n)/(n!))

7. Give examples of power series that have an infinite radius of convergence, a radius of convergence containing only the center, and a radius of convergence of one.

8. Find the Taylor series for f(x)=(e^(2x)) centered about c=0.

9. Find the Taylor series for f(x) = ln x centered about the point c = 1.

In Exercises 10 through 12, find the MacLaurin series for each of the given function.

10. f(x) =sin 2x			11. g(x)=sinh x			12. h(x)=(arc sin x)/x

13. Consider the function f(x)={({{(e^(-1/(x^2))) if x≠0}, {0             if x=0}}).  
a.  Plot the graph of this function using Mathematica.
b.  Use the limit definition of the derivative and L'Hopital's Rule to show that every higher-order derivative of f at x=0 vanishes.
c.  Find the MacLaurin series for f.  Does the series converge to f?

14. Use Taylor series to evalaute the following definite integral, which cannot be integrated via elementary means:

(∫_0^1)((sin x )/x)dx.

15. Find the following limit using the theory of Taylor series.

(Subscript[lim , x-> 0]) ((1-cos x)/x)

Chapter 11 	Parametric Equations, Polar Curves, and Conic Sections

11.1  Parametric Equations

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

Parametric equations are useful for describing curves not modeled by functions or motions parametrized by quantities such as time.  The standard form for a set of parametric equations is

x(t)=f(t)
y(t)=g(t)

where t is called the parameter.

11.1.1.  Plotting Parametric Equations

The Mathematica command for plotting a curve defined by parametric equations x=f(t) and y=g(t) for a≤t≤b is ParametricPlot[{f(t),g(t)},{t,a,b}].

Here are some examples:

Example 11.1.  Plot the curve described by the parametric equations x =cos t and y=sin t for 0≤t≤2 π.

Solution:

ParametricPlot[{Cos[t],Sin[t]},{t,0,2π},ImageSize->200]

NOTE: Recall that the above parametric equations represent the unit circle. However, Mathematica may produce a graph that, depending on its default settings, looks visually like an ellipse due to different scalings of the x- and y-axes.  In that case, the plot option AspectRatio can be used to specify the ratio of the height to the width for a plot.  For example, to stretch the plot above so that the circle becomes elliptical where the height is twice as long as the width, we can set AspectRatio equal to 2.

ParametricPlot[{Cos[t],Sin[t]},{t,0,2π},AspectRatio->2,ImageSize->200]

Example 11.2.  Plot the curve described by the parametric equations x =(t^2)-4 and y=t/2 for -2≤t≤3.

Solution: Here is a plot of the curve:

ParametricPlot[{t^2-4,t/2},{t,-2,3}]

Example 11.3.  Plot the curve (prolate cycloid) described by the parametric equations x =2θ-4sin θ and y=2-4cos θ for 0≤t≤2 π and determine its y-intercepts.

Solution: We first plot the curve:

Clear[f,g,θ]
f[θ_]=2θ-4Sin[θ];
g[θ_]=2-4Cos[θ];
ParametricPlot[{f[θ],g[θ]},{θ,-4Pi,4Pi},
PlotLabel->"Prolate cycloid"]

To find the y-intercepts (there appears to be two based on the graph), we solve f(θ)=0 for θ:

Solve[f[θ]==0,θ]

Observe that the Solve command here fails to give us an answer since the equation is non-algebraic.  However, note that the negative y-intercept is trivially located at y=-2 corresponding to θ=0.  The other (positive) y-intercept must be solved numerically using the FindRoot command (even the NSolve command fails in this case), where we provide a nearby location (θ=π/2) for our desired solution.

root=FindRoot[f[θ]==0,{θ,Pi/2}]

g[root[[1,2]]]

Thus, the second y-intercept is located approximately at y≈f(1.89549)=3.27609.

NOTE: Observe that we used of the option PlotLabel to print the label "Prolate cycloid" in the plot above. In general, the inside PlotLabel ->"text" inside a plot command prints the title text for the given plot.

11.1.2.  Parametric Derivatives

Recall that for a curve described by parametric equations x=f(t) and y=g(t), its derivative dy/dx can be expressed as a ratio between the parametric derivatives dy/dt and dx/dt (application of the Chain Rule):

(dy/dx)=((dy/dt)/(dx/dt))=((g'(t))/(f'(t)))

where it is assumed that f'(t)≠0.

Example 11.4.  Consider the following parametric equations (folium of Descartes):

x=((4t)/(1+(t^3))) and y=((4(t^2))/(1+(t^3)))

a) Plot the curve described by the parametric equations above (select an appropriate interval for t that captures all the salient features of the graph).
b) Find all points of horizontal tangency on the curve.
c) Find the derivative at the tip of the folium.

Solution:

a) Here is a plot of the folium of Descartes on the interval [0,20]:

Clear[f,g,t]
f[t_]=3t/(1+t^3);
g[t_]=3t^2/(1+t^3);
ParametricPlot[{f[t],g[t]},{t,0,20},PlotRange->All,AspectRatio->1,
PlotLabel->"Folium of Descartes",ImageSize->200]

NOTE: The plot above does not reveal the full graph of the folium.  A more complete graph is shown in the following plot.  The dashed line indicates an asymptote.  Can you generate a Mathematica plot of it?  Can you find an equation of the asymptote (see Exercise 7)?  Hint: Beware of the discontinuity at t=-1.

b) In order to find points of horizontal tangency, that is, points where the slope of the tangent line is equal to zero, it suffices to solve (dy/dx)=0, or equivalently, (dy/dt)=0 (assuming (dx/dt)≠0).  Hence, we evaluate

Solve[D[g[t],t]==0,t]

Since (dx/dt) does not vanish at t = 0 and t = (2^(1/3)) (we ignore the imaginary solutions), we conclude that there are two points corresponding to these values at which the tangent lines are horizontal, namely at (0,0) and ((2^(1/3)),(2^(2/3))):

{f[t],g[t]}/.t->0
{f[t],g[t]}/.t->(2^(1/3))

c) To locate the tip of the folium, we take advantage of the folium's symmetry to argue that the slope of the tangent at the tip must equal -1 (parallel to the asymptote of the folium).  Thus, we solve (dy/dx)=-1, or equivalently, g'(t)=-f'(t), for t:

sol=Solve[g'[t]==-f'[t],t]

f[sol[[1,1,2]]]
g[sol[[1,1,2]]]

Thus, the tip is located at (3/2,3/2).

11.1.3.  Arclength and Speed

The arc length of a curve described by parametric equations x=f(t) and y=g(t), a≤t≤b, is given by

s=(∫_a^b)(Sqrt[((((dx/dt)))^2)+((((dy/dt)))^2)])dt

Suppose (x(t),y(t)) now represent the position of a particle moving along a path at time t.  The distance traveled by the particle over the interval [(Subscript[t, 0]),t] is given by

s(t)=(∫_(Subscript[t, 0])^t)(Sqrt[((((dx/du)))^2)+((((dy/du)))^2)])du

and

(ds/dt)=(Sqrt[((((dx/dt)))^2)+((((dy/dt)))^2)])

represents its speed (length of the velocity vector (x'(t),y'(t))).

Example 11.5.  Find the arc length of the curve x = (e^(-t)) cos t,  y =(e^(-t)) sin t for 0≤t≤π/2.

Solution: Here is a plot of the curve:

Clear[x,y,t]
x[t_]=E^(-t)*Cos[t];
y[t_]=E^(-t)*Sin[t];
ParametricPlot[{x[t],y[t]},{t,0,Pi/2},ImageSize->250]

To find its arc length, we compute

(∫_0^(π/2))√((D[x[t],t])^2 +(D[y[t],t])^2)\[DifferentialD]t

N[%]

This answer makes sense based on the graph.

Example 11.5.  A particle moves along a path described by x = (t^2)-4,  y =t/2.
a) Find the distance traveled by the particle over the interval [-3,3].
b) What is the particle's minimum speed over the same interval?  When does this occur?

Solution:
a) The distance traveled is given by

Clear[x,y,t]
x[t_]=t^2-4;
y[t_]=t/2;
(∫_(-3)^3)√((D[x[t],t])^2 +(D[y[t],t])^2)\[DifferentialD]t

N[%]

a) We make a plot of the particle's speed:

speed=√((D[x[t],t])^2 +(D[y[t],t])^2)
Plot[speed,{t,-3,3},ImageSize->250]

This shows that the minimum speed is 1/2 and occurs at t=0.  Can you verify this using calculus techniques?

Exercises

In Exercises 1 through 3, sketch the curve represented by the given parametric equations.  Be sure to select an appropriate interval for the parameter that captures all the salient features of the curve.
1.  x=(t^3) , y = (t^2)/2		2.  x=2(θ-sin θ),  y= 1-cos θ		3.  x=3(cos^3)θ, y=3(sin^3)θ

4. Find all points of horizontal and vertical tangency to the curve x= cos θ + θ sin θ,  y= sin θ - θ cos θ,  0≤θ≤2π.

5. Consider parametric equations given by x= 3 cos (t/3) - cos t and y = 3 sin (t/3) - sin t.
a) Graph the curve represented by the parametric equations above.
b) Find the slope of the line tangent to the curve at the point where t = π/4.
c) Find the arc length of the curve from t=0 to t = 3π/2.

6. Consider a particle moving along a curve described by x=t-cos t and y=t-sin t with respect to time t.
a) Approximate the distance traveled by the particle over the interval [0,2π].  Hint: Use the NIntegrate command.
b) Find the minimum and maximum speeds of the particle over the same interval.  At what times do they occur?

7. Cornu's spiral (also known as Euler's spiral) is a curve defined by the following Fresnel integrals:

x(t)=(∫_0^t)cos((u^2))du, y(t)=(∫_0^t)sin((u^2))du

a) Plot Cornu's spiral for -10≤t≤10.
b) Compute the length of Cornu's spiral over the same interval.  Then find a formula for the length of Cornu's spiral over the interval a≤t≤b.
c) Determine the coordinates of the center of the two "eyes" that form Cornu's spiral.

8. Find the asymptote corresponding to the folium of Descartes (see Example 11.4) and plot the asymptote together with the folium of Descartes.

11.2   Polar Coordinates and Curves

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

Polar coordinates, expressed as (r,θ), represent the location of a point on the Cartesian plane in terms of distance r from the origin and angle θ with respect to the positive x-axis.

11.2.1.  Conversion Formulas

Conversion between Cartesian (rectangular) coordinates (x,y) and polar coordinates (r,θ) can be achieved by the following formulas:

(r^2)=(x^2)+(y^2)
θ=(tan^(-1))y/x		x=r cos θ
y=r sin θ

Example 11.6.  Perform the following conversions:
a) Convert the rectangular coordinates (3,4) into polar coordinates.
b) Convert the polar coordinates (7,π/3) into Cartesian coordinates.

Solution:

a) Using the first set of conversion formulas above, we find that

r=(Sqrt[(3^2)+(4^2)])
θ=N[ArcTan[4/3]]

b) This time, we use the second set of conversion formulas:

x=7*Cos[Pi/3]
y=7*Sin[Pi/3]

11.2.2.  Polar Curves

The Mathematica command for plotting a curve described by a polar equation in the form r=f(θ) for α≤θ≤β is PolarPlot[f(θ),{θ, α, β}].

Example 11.7.  Plot the graph of the limacon r=3-4cos θ.

Solution: Here is a plot of the limacon:

PolarPlot[3-4Cos[θ],{θ,-4Pi,4Pi},
	AspectRatio->Automatic,ImageSize->200]

Example 11.8.  Plot the graph of the six-leaf rose r=2cos(3θ/2).

Solution: Here is a plot of the six-leaf rose:

PolarPlot[2Cos[3θ/2],{θ,-4Pi,4Pi},
	PlotLabel->"A Six-Leaf Rose",AspectRatio->Automatic,ImageSize->200]

Can you can modify the function to generate a 12-leaf rose?

11.2.2.  Calculus of Polar Curves

Recall that the derivative of a polar equation in the form r=f(θ) for α≤θ≤β is given by

(dy/dx)=((f'(θ)sin θ+f(θ)cos θ)/(f'(θ)cos θ-f(θ)sin θ))

Moreover, the area A of the region bounded by a polar equation in the form r=f(θ) between α≤θ≤β is given by

A=(1/2)(∫_α^β)(f^2)(θ)dθ

Example 11.9.  Locate all horizontal and vertical tangents of the limacon r=2-sin θ.

Solution: We first plot the limacon to anticipate our solution points:

PolarPlot[1+Cos[θ],{θ,-2Pi,2Pi},ImageSize->200]

From the plot above, we should expect to find two horizontal tangents and three vertical tangents.

Next, we compute the derivative of the limacon:

Clear[f,θ]
f[θ_]=1+Cos[θ]

dydx=Simplify[(f'[θ]*Sin[θ]+f[θ]*Cos[θ])/(f'[θ]*Cos[θ]-f[θ]*Sin[θ])]

To obtain horizonal tangents, we solve dy/dx=0 for θ.

dydx==0
Solve[dydx==0,θ]

Therefore, our two horizontal tangents are located at θ=±π/3.

As for vertical tangents, we solve for where the reciprocal of the derivative is zero, that is, 1/(dy/dx)=0 for θ.

1/dydx
Solve[1/dydx==0,θ]

Since the solution above only gives us the principal solution θ=0 of -tan(3θ/2)=0, we need to additionally solve 3θ/2=±π for θ, which yields our two other solutions, θ=±2π/3.

NOTE: What is the derivative at θ=π?

Example 11.10.  Find the area of the region contained inside the circle r=3sin θ and outside the convex limacon r=2-sin θ.

Solution: We first plot the two polar curves on the same set of axes.

PolarPlot[{3Sin[θ],2-Sin[θ]},{θ,0,2π},
	AspectRatio->Automatic,ImageSize->200]

Next, we find their points of intersection by equating them and solving for θ:

Solve[3Sin[θ]==2-Sin[θ],θ]

Observe that Mathematica gives only the solution θ = π/6, which lies in the first quadrant since trigonometric inverse functions are involved.  We can see from the above graph that the other point of intersection must be at θ = 5 π/6 due to symmetry. Thus, the area of the enclosed region is given by the difference in areas enclosed by the circle and limacon between θ = π/6 and θ = 5 π/6:

(1/2)(Integrate[(3Sin[θ])^2,{θ,Pi/6,5Pi/6}] -Integrate[(2-Sin[θ])^2,{θ,Pi/6,5Pi/6}])

N[%]

NOTE: Using even symmetry of our region, it would have been enough to integrate between θ=π/6 and θ=π/2 and double the result.

Exercises

In Exercises 1 and 2, use Mathematica to perform the following conversions.
1. Convert the rectangular coordinates (-1,(Sqrt[3])) into polar coordinates.
2. Convert the polar coordinates (5,3π/4) into Cartesian coordinates.  What if we replace (5,3π/4) with (-5,3π/4)?

In Exercises 3 through 6, plot the graph of each of the given polar equations and find an interval for θ over which each graph is traced only once.
3.  r=3-4 cos θ    4.  r=2+sin θ   5.  r=3cos(3θ/2)  6.  r=5 sin 2θ

7. Generate the butterfly curve r = (e^(cos θ))-2 cos (4θ)+(sin^5) (θ/12).

8. Find all horizontal and vertical tangents of the lemniscate (r^2)=cos(2θ).  Plot its graph to confirm your answers.

9. Consider the rose curve r = cos (2θ) for -2π≤ θ≤2π.
a) Plot its graph.
b) Find the area of one petal of the curve.

In Exercises 10 through 12, graph and find the area of each of the given regions.
10. The common interior of r=3-2 sin θ and r=-3+2 sin θ.
11. Inside r=2 (1+cos θ) and outside r=2 cos θ.
12. Inner loop of r=3+4 sin θ.

In Exercises 13 and 14, find the length of the given curve over the specified interval.
13.  r=1+ sin θ, 0≤θ≤2π		14.  r=6 (1+cos θ),  0 ≤ θ≤2π

15. Consider the polar equations r = 4 sin θ and r = 2 ( 2-(sin^2) θ).
a) Graph the polar equations on the same axes.
b) Find the points of intersection of the curves.
c) Find the circumference of each curve.

11.3   Conic Sections

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

Conic sections refer to the three families of curves (ellipses, hyperbolas, parabolas) generated by intersecting a plane with a cone.  Recall the equations for describing each family of curves in standard position:

I. Ellipse

((((x/a)))^2)+((((y/b)))^2)=1

If b>a>0, then the ellipse has two foci located at (0,±c), where c=(Sqrt[(b^2)-(a^2)]).

II. Hyperbola

((((x/a)))^2)-((((y/b)))^2)=1

III. Parabola

y=(1/(4(c^2)))(x^2)

NOTE: These formulas assume that the "center" of the conic section is at the origin.  To translate the center to a different point, say ((Subscript[x, 0]),(Subscript[y, 0])), we replace x and y by x-(Subscript[x, 0]) and y-(Subscript[y, 0]), respectively.

The most useful command for plotting conic sections is ContourPlot[eqn,{x,a,b},{y,c,d}], where eqn is the equation of the conic.

Example 11.10.  Determine the family that each conic section below belongs to and then make a plot of each.
a) ((x^2)/9)+((y^2)/16)=1
b) y=(9/4)(x^2)
c) ((x^2)/4)-((y^2)/9)=1

Solution:

a) This conic is an ellipse.  To plot it, we evaluate

ContourPlot[x^2/9+y^2/16==1,{x,-4,4},{y,-4,4},Axes->True,Frame->False,ImageSize->200]

Observe that the length of semi-major and semi-minor axes are 4 and 3, respectively.  How would this change if we happen to switch the coefficients 9 and 16?

b) This conic is a parabola.  Since the equation here is solved for y, we merely use the Plot command:

Plot[(9/4)x^2,{x,-2,2},ImageSize->200]

c) This conic is a hyperbola.  Here is its plot:

ContourPlot[x^2/4-y^2/9==1,{x,-6,6},{y,-6,6},Axes->True,Frame->False,ImageSize->200]

Example 11.11.  Find an equation of an ellipse with center at (-1,3) and having semi-major and semi-minor axes of lengths (Sqrt[5]) and 1/2, respectively.

Solution: From the given data, we see that ((Subscript[x, 0]),(Subscript[y, 0]))=(-1,3), a=(Sqrt[5]), and b=1/2.  The equation of our ellipse is therefore:

((((x+1))^2)/5)+4(((y-3))^2)=1

To plot it, we evaluate

ContourPlot[(x+1)^2/5+4(y-3)^2==1,{x,-4,2},{y,2,4},AspectRatio->2/3,Axes->True,Frame->False,ImageSize->200]

Exercises

In Exercises 1 through 4, plot each of the given conic sections.  Can you determine the family that each conic section belongs to before plotting?  Also, what are the values of the parameters a and b (or c) in each conic section?
1.  ((x^2)/25)+((y^2)/4)=1		2.  ((y^2)/36)-((x^2)/16)=1		3.  y=3(x^2)		4.   ((((y-2))^2)/25)-((((x+1))^2)/49)=1

5. Consider the ellipse ((x^2)/9)+4(y^2)=1.
a) Make a plot of the ellipse.
b) What are the lengths of the semi-major and semi-minor axes?
c) Where are the foci located?
d) Compute the sum of the distances from the two foci to any point on the ellipse.  Do you recognize the answer?

6. Find an equation of an ellipse with center (1/2,-5) and having semi-major and semi-minor axes of lengths 3/4 and (Sqrt[7]), respectively.

7. Find all points on the hyperbola ((x^2)/25)-((y^2)/9)=1 where its slope equals 1.

8. Consider a polar curve of the form r=((d e)/(1+e cos θ)), where d and e are non-negative constants.

a) Plot this curve for d=3, and e=1/2.  Do you recognize this curve as a conic section?  Of which type?  Hint: Use the command PolarPlot.

b) Repeat part a) but this time use e=2 instead.  Do you recognize this curve as a conic section?  Of which type?

c) Repeat part a) but this time use e=1 instead.  Do you recognize this curve as a conic section?  Of which type?

d) Describe how the graph changes as we vary the values d and e.  What happens to the graph when e=0?  NOTE: The value e  is called the eccentricity of the conic section.

e) Assume 0<e<1.  Convert the polar equation r=((d e)/(1+e cos θ)) to that in standard form for an ellipse,  (((((x-(Subscript[x, 0]))/a)))^2)+(((((y-(Subscript[y, 0]))/b)))^2)=1, and determine formulas for its center, semi-major, and semi-minor axes.  Verify these formulas for the ellipse in part a).

Chapter 12	Vector Geometry

Useful Tip: If you are reading the electronic version of this publication formatted as a Mathematica Notebook, then it is possible to view 3-D plots generated by Mathematica from different perspectives.  First, place your screen cursor over the plot.  Then drag the mouse while pressing down on the left mouse button to rotate the plot.

12.1  Vectors

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

A vector is an object that has magnitude and direction.  In physics, these vectors are denoted by arrows, where the magnitude of the vector is represented by the length of the vector, and the way in which the arrow points indicates its direction.  In mathematics, these vectors are represented by points in two or three dimensions, where the vector is the arrow that starts at the origin and ends at the point.  For example, the point (2, 1, 3) could be considered both as a point in 3-D space and as a vector from (0, 0, 0) to (2, 1, 3). To distinguish a point from a vector, we will use the angled brackets ⟨ and ⟩ instead of parentheses. Thus, the point (2, 1, 3) is denoted (2, 1, 3) as usual, but the vector from the origin to that point is denoted ⟨2, 1, 3⟩.

The length or magnitude of a vector v is denoted ||v||, and is read as "norm v."  If  v = ⟨a, b, c⟩, then ||v|| = (Sqrt[(a^2) + (b^2) + (c^2)]).  In two dimensions, if v = ⟨a, b⟩, then ||v|| = (Sqrt[(a^2) + (b^2)]).

Vectors and matrices, in Mathematica, are simply lists.  A vector is a list of numbers within braces, with commas between numbers, while a matrix is a list of lists (vectors), with each vector list being a row of the matrix (for a complete description of lists in Mathematica, see Section 1.2.3 of this text).  Of course, all rows must be the same size.  For example, consider the vector a below:

a = {1,3 ,5}

The ith component of the vector a is denoted by (Subscript[a, i]), or in Mathematica, by a[[i]].  For instance the second component of a, which is 3, would be obtained by:

a[[2]]

All of the usual vector algebra operations are available to us:

Dot Product

The Dot Product of two vectors u=⟨(Subscript[u, 1,]) (Subscript[u, 2]), (Subscript[u, 3])⟩ and v=⟨(Subscript[v, 1,]) (Subscript[v, 2]), (Subscript[v, 3])⟩ is defined by 
u·v=(Subscript[u, 1])(Subscript[v, 1]) + (Subscript[u, 2])(Subscript[v, 2]) + (Subscript[u, 3])(Subscript[v, 3]).  For example:

a = {1, 3, 5}
b = {1, -2, 3}
a.b

or

Dot[a,b]

NOTE: We use the ordinary period symbol on the keyboard for the dot product.

Cross Product

The cross product of two vectors u=⟨(Subscript[u, 1,]) (Subscript[u, 2]), (Subscript[u, 3])⟩ and v=⟨(Subscript[v, 1,]) (Subscript[v, 2]), (Subscript[v, 3])⟩, is defined as a vector perpendicular to both u and v, and calculated by the following "right-hand" rule:

u × v = ⟨(Subscript[u, 2])(Subscript[v, 3]) - (Subscript[u, 3])(Subscript[v, 2]), (Subscript[u, 3])(Subscript[v, 1]) -  (Subscript[u, 1])(Subscript[v, 3]) , (Subscript[u, 1])(Subscript[v, 2]) - (Subscript[u, 2])(Subscript[v, 1])⟩

This calculation can be done in Mathematica in two ways.  The first is to use the Cross command:

Cross[a,b]

The second is by using the multiplication symbol "×".  This special symbol can be entered on the Basic Math Input Palette or by pushing the escape key, followed by typing the word "cross" and hitting the escape key again:  [esc]cross[esc]

a \[Cross] b

Recall that the cross product of 2 vectors, a and b creates a vector perpendicular to the plane of the vectors a and b.  In your Calculus text, the cross product is also defined as the determinant of a special matrix. We will look at this a little later.

Norm (Length) of a Vector

The norm or length of a vector can be calculated in Mathematica by the Norm command

Clear[x,y,z]

Norm[{x,y,z}]

Norm[a]

Norm [2a]

Vector Addition

The sum of two vectors u=⟨(Subscript[u, 1,]) (Subscript[u, 2]), (Subscript[u, 3])⟩ and v=⟨(Subscript[v, 1,]) (Subscript[v, 2]), (Subscript[v, 3])⟩ is defined to be u+v=(Subscript[u, 1])(Subscript[v, 1]) + (Subscript[u, 2])(Subscript[v, 2]) + (Subscript[u, 3])(Subscript[v, 3]).

2a - 3b +{1,1,1}

Example 12.1.  Let a=⟨1,2,3⟩.  Show that (a/(||a||))  is a unit vector.

Solution:

Norm[a/Norm[a]]

Example 12.2.  Find the equation of a line in 3-space passing through (Subscript[P, 0]) = (3,-1,4) in the direction of  v = ⟨2,7,1⟩ and graph it.

Solution: The line through (Subscript[P, 0]) =((Subscript[x, 0]),(Subscript[y, 0,])(Subscript[z, 0])) in the direction of v=⟨a,b,c⟩ is described in vector or parametric form by:

Vector form:  r(t)=⟨(Subscript[x, 0]),(Subscript[y, 0,])(Subscript[z, 0])⟩+t⟨a,b,c⟩
Parametric Form:  x=(Subscript[x, 0])+a t, y=(Subscript[y, 0])+b t, z=(Subscript[z, 0])+c t

Thus, the vector description of the line is

Clear[r,t];
r[t_]= {3,-1,4} + t {2,7,1}

To graph this line we use the ParametricPlot3D command:

ParametricPlot3D[{(Subscript[f, x]),(Subscript[f, y]),(Subscript[f, z])},{u,(Subscript[u, min]),(Subscript[u, max])}]
produces a three-dimensional space curve parametrized by a variable u which runs from (Subscript[u, min]) to (Subscript[u, max]).

ParametricPlot3D[r[t], {t,-3,3},ImageSize->{250},ImagePadding->{{15,15},{15,15}}]

NOTE: This plot command uses the option ImageSize to specify the size of graphics output.  Settings include Tiny, Small, Medium, Large, or {pt}, where pt is the number of points.

Example 12.3.  Give the description in vector form of the line that passes through the points P=(1,0,4) and Q=(3,2,1), then find the midpoint of the line segment (OverVector[PQ]) and plot this line segment.

Solution: The line through points P=((Subscript[a, 1]),(Subscript[b, 1]),(Subscript[c, 1])) and Q=((Subscript[a, 2]),(Subscript[b, 2]),(Subscript[c, 2])) has vector form r(t)=(1-t) ⟨(Subscript[a, 1]),(Subscript[b, 1]),(Subscript[c, 1])⟩+t ⟨(Subscript[a, 2]),(Subscript[b, 2]),(Subscript[c, 2])⟩.  In this parametrization, r(0) = P and r(1) = Q.  Thus,

r[t_] = (1-t) {1,0,4} + t {3,2,1}

The midpoint of the line segment (OverVector[PQ]) is

r[(1/2)]

The plot of the line segment is

ParametricPlot3D[r[t], {t,-0.1,1.1},ImageSize->{250},ImagePadding->{{15,15},{15,15}}]

Example 12.4.  Find the angle between the vectors v = ⟨3,6,2⟩ and w = ⟨6,3,6⟩.

Solution: Remember that the angle between two vectors, v and w, is given by θ, which is defined by θ=(cos^(-1))(((v.w)/(||v|| ||w||))) .  Therefore,

v= {3,6,2}
w = {6,3,6}

θ = ArcCos[((v.w)/(Norm[v]Norm[w]))]

N[%]

Therefore, θ = .7045 radians.

Exercises

1. Calculate the length of the vector v=⟨1,3,4⟩.

In Exerices 2 and 3, calculate the linear combinations.
2.   5⟨2,-2,5⟩+6⟨1,3,8⟩ 		3.   6 ⟨2, 0, -1⟩  - 3 ⟨8, 6, 9⟩

4. Find a vector parametrization for the line that passes through P=(1,2,-6) with direction vector v= ⟨2,1,5⟩.

In Exercises 5 and 6, determine whether the two given vectors are orthogonal (v ⊥ w iff  v.w = 0):
5.  ⟨1,1,1⟩,  ⟨1,-2, 3⟩		6.  ⟨1,1,1⟩,  ⟨-3,2,1⟩

In Exercises 7 and 8, find the angle between the vectors:
7.  ⟨1,2⟩,  ⟨5,7⟩			8.  ⟨2,4,1⟩,  ⟨1,-3,5⟩

12.2  Matrices and the Cross Product

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

In order to understand the alternate approach to the cross product alluded to above, we need to define the terms matrix and determinant.

Matrices

A matrix is a rectangular array of numbers consisting of n rows and m columns (denoted n × m).  We are especially interested in square matrices where m = n and, in particular, m = 2 or m=3.  For example:  A 3 × 3 matrix would be

(({{(Subscript[a, 11]), (Subscript[a, 12]), (Subscript[a, 13])}, {(Subscript[a, 21]), (Subscript[a, 22]), (Subscript[a, 23])}, {(Subscript[a, 31]), (Subscript[a, 32]), (Subscript[a, 33])}}))

but Mathematica would show this matrix as:

A = Table[10i+j,{i,3},{j,3}]

B = Table[i+j,{i,2},{j,2}]

To have Mathematica display a matrix in the traditional way, use the MatrixForm command:

MatrixForm[A]
MatrixForm[B]

Note that in the definition of the matrices A and B, Mathematica treats them as lists and when we use the command MatrixForm, we can see the matrices presented in the traditional way.

Determinants

The determinant is a function, Det, which assigns to each square matrix a number which is defined for 2 × 2 and 3 × 3 matrices as follows:

Clear[a,b];
F = {{a,b},{c,d}}
MatrixForm[F]

Det[F]

G= {{a1,a2,a3},{b1,b2,b3},{c1,c2,c3}}
MatrixForm[G]

Det[G]

Using these definitions, we can now define the cross product of two vectors by the formula

⟨(Subscript[b, 1]),(Subscript[b, 2]),(Subscript[b, 3])⟩×⟨(Subscript[c, 1]),(Subscript[c, 2]),(Subscript[c, 3])⟩=Det(({{i, j, k}, {(Subscript[b, 1]), (Subscript[b, 2]), (Subscript[b, 3])}, {(Subscript[c, 1]), (Subscript[c, 2]), (Subscript[c, 3])}}))

where i =⟨1,0,0⟩, j =⟨0,1,0⟩, and k =⟨0,0,1⟩.

Example 12.5.  Calculate the cross product of  v=⟨1,3,6⟩ and w=⟨-2,8,5⟩.

Solution:

Clear[i,j,k]
g = {i,j,k}
v= {1,3,6}
w = {-2,8,5}
A = {g,v,w}

MatrixForm[A]

v \[Cross] w
Det[A]

Observe that the two previous outputs are equivalent.

Exercises

1.  Calculate the determinants of (({{0, 5, 0}, {1, 3, 6}, {2, 5, 5}})) and of (({{3, 5}, {6, 2}})).

2.  Calculate the cross product of  v=⟨2,0,0⟩ and w=⟨-1,0,1⟩.  Do this using the Cross command as well as by the determinant approach.

3.  Calculate the area of the parallelogram spanned by the vectors v and w above. (Hint: look up the formula for this in your calculus textbook.)

4.  Calculate the volumn of the parallelepiped spanned by:
      u  =  ⟨2, 2, 1⟩,  v  =  ⟨1, 0, 3⟩,   and  w  =  ⟨0, -4, 2⟩

5.  Show that  v×w  = -w×v  and that  v×v = 0.

12.3  Planes in 3-Space

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

Note that a plane in 3-D space is defined as all points P(x,y,z) such that the line segment (OverVector[(Subscript[P, 0])P ])  is perpendicular to a given vector n, called the normal vector, where the initial point of n is (Subscript[P, 0])=((Subscript[x, 0]),(Subscript[y, 0]),(Subscript[z, 0])).  In vector notation, this is described by the equation n· (OverVector[(Subscript[P, 0])P ])  = 0, where  (OverVector[(Subscript[P, 0])P ]) = ⟨x-(Subscript[x, 0,]) y-(Subscript[y, 0]),z-(Subscript[z, 0])⟩.  Therefore, the equation of the plane through (Subscript[P, 0]) = ((Subscript[x, 0]),(Subscript[y, 0]),(Subscript[z, 0])) with nonzero normal vector n = ⟨a,b,c⟩ can be denoted by either of the following:

Vector form:			n·⟨x,y,z⟩=d
Scalor form: 			a x + b y + c z = d

Here, d=a (Subscript[x, 0])+b (Subscript[y, 0])+c (Subscript[z, 0])=n·⟨(Subscript[x, 0]),(Subscript[y, 0]),(Subscript[z, 0])⟩.

Example 12.6.  Find an equation of the plane determined by the points P=(1,0,-1), Q=(2,2,1), and R=(4,2,5).  Then plot the graph of the plane.

Solution: The vectors a=(OverVector[PQ ]) and  b=(OverVector[PR])  lie in the plane, so the cross product n=a×b is normal to the plane:

Clear[a, b, n]
a = {2, 2, 1} - {1, 0, -1}
b = {4, 2, 5} - {1, 0, -1}
n = a \[Cross] b
n . {x,y,z}==d

To compute the value of d, we choose any point on the plane, that is, we can choose either P, Q, or R, and then compute d=n·P, d=n·Q, or d=n·R.  Let us choose P=⟨1,0,-1⟩.

d = n . {1, 0, -1}

Therefore, the plane we want has equation 8x-4z=12  and the graph is obtained by using the ContourPlot3D command which has the form:

({{, ContourPlot3D[f,{x,(Subscript[x, min]),(Subscript[x, max])},{y,(Subscript[y, min]),(Subscript[y, max])},{z,(Subscript[z, min]),(Subscript[z, max])}]
which produces a three-dimensional contour plot of f as a function of x, y and z. 
or}, {, ContourPlot3D[f==g,{x,(Subscript[x, min]),(Subscript[x, max])},{y,(Subscript[y, min]),(Subscript[y, max])},{z,(Subscript[z, min]),(Subscript[z, max])}]
which plots the contour surface for which f=g. }})

ContourPlot3D[8x - 4z==12,{x,-2,2},{y,-2,2},{z,-2,2},ImageSize->{250}]

In order to see this plane more clearly from a different perspective, move your cursor over the plot.  Then drag the mouse while pressing and holding the left mouse button to rotate the plot.

Exercises

1.  Let PL be the plane with equation 7x-4y+2z=10.  Find an equation of the plane QL parallel to                       PL and passing through Q=(2,1,3) and graph it.

2.  Find the equation of the plane through the points P=(1,5,5), Q=(0,1,1), and R=(2,0,1) and     graph it.

3.  Find the angle between the two planes:  x+2y+z=3 and 4x+y+3z=2.  (Hint: The angle between two planes is the angle between their normal vectors.)

12.4  A Survey of Quadric Surfaces

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

A quadric surface is the three-dimensional equivalent of a conic section (i.e., ellipses, hyperbolas, and parabolas).  The basic types of quadric surfaces are ellipsoids, hyperboloids (of one or two sheets), paraboloids (elliptic or hyperbolic), and cones.

12.4.1  Ellipsoids

The standard ellipsoid is described by (((x/a))^2)+(((y/b))^2)+(((z/c))^2)=1. To help us visualize it, we are often interested in the mesh of curves called traces, obtained by intersecting our quadric surface with planes parallel to one of the coordinate planes. In the plot below, you can see that mesh, and also see that the traces of an ellipsoid are themselves ellipses.

Example 12.7.  Graph the ellipsoid above, with a=3, b= 4, and c = 5, and describe the traces of this ellipsoid.

Solution: The correct Mathematica command to use is ContourPlot3D.  This is shown following:

ContourPlot3D[(x/3)^2+(y/4)^2+(z/5)^2==1,{x,-6,6},{y,-6,6},{z,-6,6},AxesLabel->{x,y,z},ImageSize->{250}]

Again, note that the ellipsoid can be manually rotated to look at it from different perspectives. First, place your screen cursor over the plot.  Then drag the mouse while pressing down on the left mouse button to rotate the plot.  When you do this, you will note that, indeed, all of the traces are ellipses.

12.4.2  Hyperboloids

The three-dimensional hyperbolas are called hyperboloids, and come in two types: the hyperboloid of one sheet, with standard form (((x/a))^2)+(((y/b))^2)=(((z/c))^2)+1, and the hyperboloid of two sheets, with standard form (((x/a))^2)+(((y/b))^2)=(((z/c))^2)-1.  A limiting case of the hyperboloid is the elliptic cone, defined by the equation (((x/a))^2)+(((y/b))^2)=(((z/c))^2).

Example 12.8.  Describe the traces of the two hyperboloids: (((x/3))^2)+(((y/4))^2)=(((z/5))^2)+1 and (((x/3))^2)+(((y/4))^2)=(((z/5))^2)-1.

Solution: First we graph the hyperboloids:

ContourPlot3D[(x/3)^2+(y/4)^2   == (z/5)^2+ 1,{x,-6,6},{y,-6,6},{z,-6,6},AxesLabel->{x,y,z},ImageSize->{250}]

In this case, the traces parallel with the xy-axis are all ellipses, and the traces parallel wth the xz- and yz-axes are hyperbolas.

ContourPlot3D[(x/3)^2+(y/4)^2 ==(z/5)^2-1,{x,-30,30},{y,-30,30},{z,-30,30},AxesLabel->{x,y,z},ImageSize->{250}]

When we look at this plot, we see that the traces are the same as for the previous hyperboloid of one sheet.

Example 12.9.  Graph the cone with a=3, b=4, and c=5, and define its relationship to the hyperboloid of one sheet.

Solution: We get the graph by using the ContourPlot3D Command:

ContourPlot3D[(x/3)^2+(y/4)^2 ==(z/5)^2,{x,-30,30},{y,-30,30},{z,-30,30},AxesLabel->{x,y,z},ImageSize->{250}]

When we compare this plot with that of the hyperboloid of one sheet (see previous example), we can see clearly that this cone can be thought of as a limiting case of the hyperboloid of one sheet in which we pinch the waist down to a point.

12.4.3  Paraboloids

The final family of quadric surfaces that we want to consider are the paraboloids, of which there are two types: elliptic and hyperbolic. Their standard equations are z=(((x/a))^2)+(((y/b))^2) (elliptic paraboloid) and z=(((x/a))^2)-(((y/b))^2) (hyperbolic paraboloid).

Example 12.10.  Graph the two types of paraboloids for a=3 and b=4 and describe their traces.

Solution: Here is the graph of the elliptic paraboloid:

ContourPlot3D[(x/3)^2+(y/4)^2 ==z,{x,-30,30},{y,-30,30},{z,-30,30},AxesLabel->{x,y,z},ImageSize->{250}]

Observe that the traces in the direction of the xz- and yz-axes are both parabolas while those in the xy-direction are ellipses, which can be seen by dragging the plot in the appropriate directions.  Similarly, for the hyperbolic paraboloid:

ContourPlot3D[(x/3)^2-(y/4)^2 ==z,{x,-30,30},{y,-30,30},{z,-30,30},AxesLabel->{x,y,z},ImageSize->{250}]

Again, by dragging the plot above, we see that the traces in the yz-direction are parabolas while those in the xz-direction are hyperbolas.

12.4.4  Quadratic Cylinders

The last group of quadric surfaces we will look at are the quadratic cylinders. These are surfaces formed from a two-dimensional curve (in the xy-plane) along with all vertical lines passing through the curve:

Example 12.11.  Graph a selection of quadratic cylinders.

Solution:

a)  A circular cylinder of radius r:  (x^2)+(y^2)=(r^2).  For the graph, we will use r=3.

ContourPlot3D[x^2+y^2 ==3^2,{x,-5,5},{y,-5,5},{z,-30,30},AxesLabel->{x,y,z},ImageSize->{250}]

b)  An elliptic with equation (((x/a))^2)+(((y/b))^2)=1. We will use a=3 and b=6.

ContourPlot3D[(x/3)^2+(y/6)^2 ==1,{x,-5,5},{y,-8,8},{z,-20,20},AxesLabel->{x,y,z},ImageSize->{250}]

c) A hyperbolic cylinder with equation (((x/a))^2)-(((y/b))^2)=1.  We will use a=3 and b=6.

ContourPlot3D[(x/3)^2-(y/6)^2 ==1,{x,-10,10},{y,-10,10},{z,-20,20},AxesLabel->{x,y,z},ImageSize->{250}]

d) A parabolic cylinder with equation y =a (x^2) with a=3.

ContourPlot3D[y ==3x^2,{x,-3,3},{y,-1,8},{z,-10,10},AxesLabel->{x,y,z},ImageSize->{250}]

Exercises

In Exercises 1 through 5, state whether the given equation defines an ellipsoid, hyperboloid, or paraboloid, and of which type.  Then confirm your answer by graphing the quadric surface.
1.   (((x/5))^2)+(((y/7))^2)+(((z/9))^2)=1
2.   (((x/5))^2)-(((y/7))^2)+(((z/9))^2)=1
3.    (x^2)+5(y^2)-6(z^2)=1
4.    z=(((x/5))^2)+(((y/7))^2)
5.    z=(((x/5))^2)-(((y/7))^2)

In Exercises 6 through 8, state the type of  the quadric surface and graph it, and then describe the trace obtained by intersecting it with the given plane.
6.   (((x/5))^2)+(y^2)+(((z/9))^2)=1,  z=1/4
7.   y=2(x^2),    z=25
8.   (((x/5))^2)-(((y/7))^2)+(((z/9))^2)=1,  y=4

12.5  Cylindrical and Spherical Coordinates

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

12.5.1  Cylindrical Coordinates

In cylindrical coordinates, the point P=(x,y,z) is expressed as (r,θ,z) where r and θ are the polar coordinates of x and y.  The formulas for converting from (x,y,z) to (r,θ,z) are:

Cylindrical to Rectangular		Rectangular to Cylindrical
x=r cos θ				r=(Sqrt[(x^2)+ (y^2)])
y=r sin θ				tan θ=y/x
z=z					z=z

The commands in Mathematica to do these conversions must first be loaded into Mathematica from the "Vector Analysis" external package:

<<VectorAnalysis`

Example 12.12.  Convert (r,θ,z)=(2,3π/4,5) to rectangular coordinates.

Solution: We use the CoordinatesToCartesian command to convert from cylindrical to rectangular coordinates:

CoordinatesToCartesian[{2,3Pi/4,5}, Cylindrical]

N[%]

Example 12.13.  Convert (x,y,z)=(2,3,5) to cyclindrical coordinates.

Solution: We use the CoordinatesFromCartesian command to convert from rectangular to cylindrical coordinates:

CoordinatesFromCartesian[{2, 3, 5},Cylindrical]

N[%]

Of course, one very strong point for Mathematica is its graphing ability.  It will easily graph functions described in cylindrical coordinates. The command to do this is RevolutionPlot3D.

RevolutionPlot3D[(Subscript[f, z]),{t,(Subscript[t, min]),(Subscript[t, max])},{θ,(Subscript[θ, min]),(Subscript[θ, max])}]
takes the azimuthal angle θ to vary between (Subscript[θ, min]) and (Subscript[θ, max]).

Example 12.14.  Graph the cylindrical coordinate function z=((2(r^2)sin(5θ))/(1+(r^2))).

Solution:

Clear[r,θ];
RevolutionPlot3D[((2(r^2) Sin[5 θ])/(1+(r^2))),{r,0,5},{θ,0,2 π},ImageSize->{250}]

12.5.2  Spherical Coordinates

A point P=(x,y,z) is described in spherical coordinates by a triple (ρ,θ,ϕ) where ρ is the distance of P from the origin, θ is the polar angle of the projection (x,y,0), and ϕ is the angle between the z-axis and the ray from the origin through P. The formulas for converting between rectangular and spherical coordinates are:

Spherical to Rectangular		Rectangular to Spherical

x=ρ cos θ sin ϕ			ρ=(Sqrt[(x^2) + (y^2) + (z^2)])
y=ρ sin θ sin ϕ			tan θ=y/x
z=ρ cos ϕ				cos ϕ=z/ρ

These conversions are done in Mathematica using the same commands as with cylindrical coordinates, but with the word spherical replacing cylindrical.

Example 12.15.  Convert (ρ,θ,ϕ)=(2,3π/4,π/5) to rectangular coordinates.

Solution:

CoordinatesToCartesian[{2,3Pi/4,π/5}, Spherical]

N[%]

Example 12.16.  Convert (x,y,z)=(2,3,5) to spherical coordinates.

Solution:

CoordinatesFromCartesian[{2, 3, 5},Spherical]

N[%]

Again, the main use here of Mathematica is its graphing ability.  It will easily graph functions described in spherical coordinates. The command to do this is the SphericalPlot3D command.

SphericalPlot3D[r,{θ,(Subscript[θ, min]),(Subscript[θ, max])},{ϕ,(Subscript[ϕ, min]),(Subscript[ϕ, max])}] 
generates a 3D plot with a spherical radius r as a function of spherical coordinates θ and ϕ.

Example 12.17.  Graph the spherical coordinate function ρ=1+sin (6ϕ)/6.

Solution:

SphericalPlot3D[ ρ = 1+Sin[6ϕ]/6,{θ,0,Pi},{ϕ,0,2Pi},ImageSize->{250}]

Exercises

Convert from cylindrical to rectangular:
1.  (2,π/3,-4)  		2.  (1,π/2,3)

Convert from rectangular to cylindrical:
3.   (2,2,5)			4.   (4,(Sqrt[3]),8)

5.  Plot the surface (z^2)+(r^2)=25θ and describe it.

Convert from spherical to rectangular:
6.    (2,π/5,π/3)		7.    (4,π/6,5π/6)

Convert from rectangular to spherical:
8.   ((Sqrt[2]),2,3)			9.   (4,(Sqrt[3])/2,(Sqrt[8]))

10.  Plot the surface ρ sin ϕ=5 and describe it.

Chapter 13	Calculus of Vector-Valued Functions

Useful Tip: If you are reading the electronic version of this publication formatted as a Mathematica Notebook, then it is possible to view 3-D plots generated by Mathematica from different perspectives.  First, place your screen cursor over the plot.  Then drag the mouse while pressing down on the left mouse button to rotate the plot.

13.1.  Vector-Valued Functions

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

A vector-valued function is a vector where the components of the vector are themselves functions of a common parameter (or variable). For example, r is a vector-valued function if r(t) = ⟨x(t),y(t),z(t)⟩.  If we think of t as the time variable, the r(t) describes the motion of a particle through three-dimensional space over time.  What we want to do is to understand what path is taken.  We do this through graphing in three dimensions. Also, sometimes it is helpful to consider the projections of these curves onto the coordinate planes.  For example, the projection of r(t) on the xy-plane is ⟨x(t),y(t),0⟩.

Example 13.1. Trace the paths of each of the following vector functions and describe its projections onto the xy-, xz-, and yz-planes:
a)  r(t)=⟨t, (t^2), 2t⟩
b)  r(t)=⟨(cos^3)t, (sin^3)t,sin 2t⟩

Solution:  We use the ParametricPlot3D command to trace the path of each curve and to see its projection.

a) First, we look at the plot of r(t)=⟨t,(t^2), 2t⟩:

ParametricPlot3D[{t,(t^2), 2t},{t,-3,3},PlotStyle-> Red,ImageSize->{250}]

This curve looks very much like a parabola in 3-D space.  To see the projections, we look first at:

ParametricPlot3D[{t,(t^2), 0},{t,-3,3},PlotRange->{-1,1},PlotStyle-> Orange,ImageSize->{250}]

This is clearly a parabola in the xy-plane.

ParametricPlot3D[{t,0, 2t},{t,-3,3},Ticks->{Automatic,{-1,0,1},Automatic},PlotStyle-> Orange,ImageSize->{250},ImagePadding->{{15,15},{15,15}}]

And this clearly a line in the xz-plane.

ParametricPlot3D[{0,(t^2), 2t},{t,-3,3},Ticks->{{-1,0,1},Automatic,Automatic},PlotStyle-> Orange,ImageSize->{250}]

This last plot is also clearly a parabola, but in the yz-plane.

b)  Next, we look at r(t)=⟨(cos^3)t ,(sin^3) t,sin 2t⟩:

ParametricPlot3D[{((Cos[t])^3),((Sin[ t])^3),Sin[2t]},{t,-2π,2π},PlotStyle-> Orange,ImageSize->{250}]

Note that since both sine and cosine are periodic with period 2π, it is not necessary to extend the domain beyond -2π or +2π. The projection in the xy-plane is:

ParametricPlot3D[{((Cos[t])^3),((Sin[ t])^3),0},{t,-2π,2π},PlotPoints->100,ImageSize->{250}]

The projection in the xz-plane is:

ParametricPlot3D[{((Cos[t])^3),0,Sin[2t]},{t,-2π,2π},ImageSize->{250}]

Lastly, the projection in the yz-plane is:

ParametricPlot3D[{0,((Sin[ t])^3),Sin[2t]},{t,-2π,2π},ImageSize->{250}]

Note that the last two projections are almost exactly alike.  This is to be expected because the sine and cosine functions have the same graph, but π/2 radians apart.

Exercises

In Exercises 1 through 3,  graph r(t) and its three projections onto the coordinate planes.
1.  r(t)=⟨cos( 2t),cos t,sin t⟩		2.  r(t)=⟨t+15,(e^(0.08t))cos t,(e^(0.08t))sin t⟩
3.  r(t)=⟨t,t,25t/(1+(t^2))⟩

4. Which of the following curves have the same projection onto the xz-plane?  Graph the three projections to check your answer.
a.  (Subscript[r, 1])(t)=⟨t,(e^t),(t^2)⟩		b.  (Subscript[r, 2])(t)=⟨(e^t),t,(t^2)⟩		c.  (Subscript[r, 3])(t)=⟨t,cos t,(t^2)⟩

13.2.  Calculus of Vector-Valued Functions

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

Since vector-valued functions are differentiated and integrated component by component, Mathematica will handle this easily since it treats vectors as lists and automatically performs the indicated operation on each element of the list.

The derivative of a vector valued function r(t)=⟨x(t),y(t),z(t)⟩ is defined to be

r'(t)=⟨x'(t),y'(t),z'(t)⟩

while the integral of r(t) is

∫r(t)dt=⟨∫x(t)dt,∫y(t)dt,∫z(t)dt⟩.

Similarly, the limit is defined by

(lim_(t->a))r(t)=⟨(lim_(t->a))x(t),(lim_(t->a))y(t),(lim_(t->a))z(t)⟩.

Example 13.2.  Differentiate and integrate each of the following vector functions:
a) r(t)=⟨t, (t^2), 2t⟩
b) s(t) = ⟨(cos^3) t , (sin^3) t, sin 2t⟩

Solution:

(a)

Clear[r,s,t]

r[t_]:= {t,(t^2),2t}
s[t_]:= {((Cos[t])^3),((Sin[t])^3),Sin[2t]}

(∂_t) r[t]

∫r[t]\[DifferentialD]t

(b)

(∂_t) s[t]

∫s[t]\[DifferentialD]t

Limits are handled the same way both in the calculus of vector-valued functions and in Mathematica:

Example 13.3.  Evaluate (Underscript[limit, h->0]) ((r(t+h)-r(t))/h)  for r(t)=⟨t, (t^2), 2t⟩.

Solution:

Since r(t) has been defined in the previous example, we merely evaluate

Limit[((r[t+h]-r[t])/h),h->0]

As we would expect, this limit gives us the same answer for r'(t) as in the previous example.

Example 13.4.  Evaluate (Underscript[limit, t->3])⟨(t^2),4t,(1/(t^3))⟩.

Solution:

Limit[{(t^2), 4t,(1/(t^3))},t->2]

Derivatives of Dot and Cross Products

Using the formulas of the derivative of the dot and cross products for vector-valued functions is simple in Mathematica. As a reminder, the formulas are:

(d/dt)(r(t)·s(t))=r(t)·s'(t)+r'(t)·s(t) and (d/dt)(r(t)×s(t))=r(t)×s'(t)+r'(t)×s(t)

Example 13.5.  Evaluate (d/dt)(r(t)·s(t)) and (d/dt)(r(t)×s(t)) for r(t)=⟨t,(t^2),2t⟩ and s(t) = ⟨(cos^3) t ,(sin^3) t,sin 2t⟩.

Solution:

(∂_t)(r[t].s[t])

(∂_t)(r[t]\[Cross]s[t])

Tangent Lines

Example 13.6.  Find the vector parametrization of the tangent line to r(t)=⟨1-(t^2),5t,(t^3)⟩ at the point t=1 and plot it along with r(t).

Solution: Recall that the tangent line at (Subscript[t, 0]) has vector parametrization L(t)=r((Subscript[t, 0]))+t r'((Subscript[t, 0])):

r[t_]= {1-(t^2),5t,(t^3)}
r'[t]
L[t_]=r[1]+t*r'[1]

Here is a plot of the curve and the tangent line.

ParametricPlot3D[{r[t],L[t]},{t,-2,4},ImageSize->Small]

NOTE: Recall that the plot can be rotated to better view it from different perspectives.

Exercises

In Exercises 1 and 2 evaluate the limits
1.  (lim_(t->π))⟨sin 2t,cos t,tan 4t⟩ 		2.  (lim_(t->0))⟨(1/(t+1)),(((e^t)-1)/t),4t⟩

In Exercises 3 and 4 compute the derivative and integral.
3.  r(t)=⟨tan t,4t-2,sin t⟩			4.  r(t)=⟨(e^t),(e^(2t))⟩

5.  Find a parametrization of the tangent line at the point indicated and plot both the vector-valued curve and the tangent line on the same set of axes.

6.  Evaluate (d/dt)r(g(t)) for r(t)=⟨4 sin 2t,2 cos 2t⟩ and g(t)=(t^2).

13.3.  Arc Length

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

The arc length of a path r(t)=⟨x(t),y(t),z(t)⟩ for a≤t≤b is given by

L=(∫_a^b)||r'(t)||dt=(∫_a^b)(Sqrt[(((x'(t)))^2) + (((y'(t)))^2) + (((z'(t)))^2)])dt

and like the one-dimensional version is difficult to evaluate by hand.  Thus Mathematica is the perfect tool for calculating this.

Example 13.7.  Compute the arc length of r(t)=⟨1-(t^2),5t,2 (t^3)⟩  over the interval 1≤t≤2.

Solution:

r[t_] := {1-(t^2), 5t,2 (t^3)} 
L = (∫_1^2)Norm[r'[t]] \[DifferentialD]t

Note that the above output indicates that Mathematica cannot find an antiderivative for the integrand, and thus we need to find another technique to evaluate this integral.  Hence, we next try the numerical integrate command, NIntegrate, which does give us our result:

L = NIntegrate[Norm[r'[t]],{t,1,2}]

Speed

The vector r'(t) is also known as the velocity vector as it points in the (instantaneous) direction of motion described by r(t).  Its length or norm, ‖r'(t)‖, gives the speed at time t.

Example 13.8.  Compute the speed of r(t)=⟨1-(t^2),5t,2 (t^3)⟩ when t=1, 1.5, and 2.

Solution:

The following output gives a list of speeds of r'(t) at the three given times using the Norm command, which calculates the norm of a vector:

r[t_] := {1-(t^2), 5t,2 (t^3)} 
Speed = {Norm[r'[1]], Norm[r'[1.5]], Norm[r'[2]]}

N[%]

Observe that the speed is increasing as we move along the path of r(t) from t=1 to t=2.  This can be seen graphically by plotting the speed:

Norm[r'[t]]
Plot[Norm[r'[t]],{t,1,2}]

NOTE: Observe how the Norm command inserts absolute values around each vector component in the formula for ‖r'(t)‖, which seems redundant since each component is squared.  This is done because in Mathematica vector components are allowed to be complex-valued, in which case absolute values are needed to refer to their magnitudes.

Exercises

In Exercises 1 and 2, compute the length of curve over the given interval.
1.  r(t)=⟨2 sin t,6t,2cos t⟩,   -6≤t≤6		2.  r(t)=⟨12 t,8(t^(3/2)),3 (t^2)⟩,   0≤t≤1

In Exercises 3 and 4, find the speed of a particle moving along the curve r(t) at the given value of t.
3.  r(t)=⟨(e^(t-2)),15 t,5/t⟩,    t=1			4.  r(t)=⟨sin 2t,cos 4t,sin 6t⟩,   t=π/2

5. Compute s(t)=(∫_0^t)||r'(u)||du for r(t)=⟨(t^2),2(t^2),(t^3)⟩ and interpret Mathematica's result.

6. For r(t)=⟨4t,1-3t,(Sqrt[24])t⟩, compute s(t) as in the previous exercise.  Then use s(t) to find an arc length parametrization of r(t), that is, find φ(s)=t, where φ is the inverse of s(t), and check to see that r(φ(s)) has unit speed, that is, ||r'(φ(s))||=1.  Lastly, plot r(t) and r(φ(s)) and compare them.

7.  Consider the helix r(t)=⟨a sin t,a cos t,c t⟩. 
a. Find a formula for the arc length of one revolution of r(t).
b. Suppose a helix has radius 10, height 5, and makes three revolutions.  What is its arc length?

8. The Cornu spiral is defined by r(t)=⟨x(t),y(t)⟩, where x(t)=(∫_0^t)sin(((u^2)/2))du and y(t)=(∫_0^t)cos(((u^2)/2))du.
a.  Plot the Cornu spiral over various intervals for t.
b.  Find a formula for its arc length along the interval -a≤t≤a, where a is a positive real number.
c.  What is its arc length in the limit as a->∞?

13.4.  Curvature

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

Vector tools previously studied including arc length enables one to study the idea of curvature, which serves as a measure of how a curve bends, that is, the rate of change in direction of a curve.  In arriving at a definition of curvature, consider a path in vector form and parametrized by

r(t) = ⟨x(t), y(t), z(t)⟩

The parametrization is classified as regular if r' (t) ≠  0 for all  values of t and for which r (t) is defined.  Assume then that r(t) is regular and define the unit tangent vector in the direction of r' (t), denoted T (t), as follows:

T(t)=((r'(t))/(||r'(t)||)).

This unit tangent vector T at any point enables us to determine the direction of the curve at that point, so one may define the curvature κ (Greek letter kappa) at a point as

κ=||((dT)/ds)||=((||T'(t)||)/(||r'(t)||)),

which represents the magnitude of the rate of change in the unit tangent vector with respect to arc length. One denotes the vector dT/ds as the curvature vector.  Its scalar length therefore measures curvature.  For example, a straight line has κ=0 (zero curvature) as one would expect.  For a circle of radius ρ, we have κ=1/ρ (reciprocal of ρ).  This makes sense since a larger circle should have smaller curvature.  In general, if we were to secure a circle, called the osculating circle, that best fits a curve at a specific point on the curve, then curvature of the curve at such a point should agree with the curvature of the osculating circle, that is,

κ=(1/ρ)

Moreover, the radius ρ of this circle is called the radius of curvature. Note that the equations linking κ and ρ illustrate their inverse relationship:

κ=(1/ρ) and ρ=(1/κ)

Example 13.9.  Compute the curvature κ for a circle of radius ρ defined by

r(t)=⟨ρ cos t,ρ sin t⟩

Solution: We first compute the unit tangent vector T using the formula T(t)=((r'(t))/(||r'(t)||)):

Clear[r,T,t,ρ]

r[t_]={ρ Cos[t],ρ Sin[t]}
r'[t]
T[t_]=r'[t]/Simplify[Norm[r'[t]]]

Observe that in this output Mathematica is not able to reduce the expression inside the radical, which simplifies to ρ as a result of the fundamental trigonometric identity (cos^2)x+(sin^2)x=1.  This is due to the Norm command, which employs absolute values.  To remedy this, we use the formula ‖r'(t)‖=(Sqrt[r'(t)·r'(t)]) instead of the Norm command.

T[t_]=r'[t]/Sqrt[Simplify[r'[t].r'[t]]]

We then compute the curvature using the formula κ=((||T'(t)||)/(||r'(t)||)):

κ=Sqrt[Simplify[T'[t].T'[t]]/Simplify[r'[t].r'[t]]]

Since the radius ρ is assumed to be positive, we conclude that κ=(Sqrt[(1/(ρ^2))])=|(1/ρ)|=(1/ρ) as expected.

Example 13.10.  Compute the curvature κ for the curve defined by f(x)=(x^2) at the point (3,9).

Solution: Observe that the graph of a function y=f(x) can be parametrized by x=t and y=f(t) and hence r(t)=⟨t,f(t)⟩. In this case the formula for curvature reduces to

Clear[r,t,f]
r[t_]={t,f[t]}

T[t_]=((r'[t])/(Sqrt[r'[t].r'[t]]))
κ= Sqrt[Simplify[T'[t].T'[t]]/Simplify[r'[t].r'[t]]]

which is the same as κ=((|f''(x)|)/(((1+(((f'(x)))^2)))^(3/2))). With f(x)=(x^2), we get

f[t_]=(t^2)
κ

At x=t=3, the curvature becomes

κ/.t->3

Here is a plot of the curvature along with the function.

Plot[{f[t],κ}, {t,0,3}]

Example 13.10.  Compute the curvature κ and the radius of curvature ρ for the curve defined by

r(t)=⟨1-t,(t^2)+1, (2/3)(t^3)+1⟩ at t=1/2.

Solution: Again we begin by computing the unit tangent vector T:

Clear[r,T,t,κ]

r[t_]={1-t,t^2+1,(2/3)t^3+1}
r'[t]
T[t_]=r'[t]/Sqrt[Simplify[r'[t].r'[t]]]

We then compute the curvature using the same formula as in the previous example and evaluate it at t=1/2:

κ=Sqrt[Simplify[T'[t].T'[t]]/Simplify[r'[t].r'[t]]]
κ/.t->1/2

Hence, the curvature κ=8/9 at t=1/2 and the corresponding radius of curvature is ρ=1/κ=9/8.

Curvature Formula (Cross Product)

There is an alternative formula for calculating the curvature of space curves that involves the cross product and eliminates the need to compute the unit tangent vector function:

κ=((|| r''(t) × r'(t) ||)/(|| r'(t) ((||)^3)))=((|| a(t) × v(t) ||)/(|| v(t) ((||)^3)))

Example 13.11.  Compute the curvature κ(t) and the radius of curvature for the helix defined by r(t)=⟨cos t,sin t,t⟩ for any real number t.

Solution: We first find the derivative of the unit tangent vector with respect to t.

Clear[r,T,t,κ]
r[t_]={Cos[t], Sin[t],t}
r'[t]
r''[t]

κ[t_]=Sqrt[Simplify[Cross[r''[t],r'[t]].Cross[r''[t],r'[t]]]]/((Sqrt[Simplify[r'[t].r'[t]]])^3)

It follows that κ=(1/2) and ρ=2 for all values of t.  Hence, our helix is a curve of constant curvature.

Exercises

In Exercises 1 and 2, find r'(t) and T(t) and evaluate T(2).
1.  r(t)=(3+2t)i+(2-5t)j+9t k			2. v(t)=⟨sin t,cos t,1⟩

3. Use Mathematica to find the curvature function k(x) for y=cos x. Also plot κ(x) for 0≤x≤1. Where does the curvature assume its maximum value?

4. Determine the unit normal vectors to r(t)=[t i+sin t j] at t=(π/4) and t=((3π)/4).

5. Determine the curvature of the vector-valued function r(t)=(3+2t)i+6t j+(5-t)k.

6. Find a formula for the curvature of the general helix r(t)=a cos t i+a sin t j+c t k.

13.5.  Motion in Three Space

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

Recall that the velocity vector is the rate of the change of the position vector with respect to time while the acceleration vector represents the rate of change of the velocity vector with respect to time.  Moreover, speed is defined to be the absolute value of the velocity vector. In short, we have the following:

v(t)=r'(t), s(t)=‖v(t)‖ and a(t)=v'(t)=r''(t)

One can secure the velocity vector and the position function if the acceleration vector is known via integration.  More specifically:

v(t)=(∫_0^t)a(u)du+(Subscript[v, 0]) where (Subscript[v, 0]) represents the initial velocity vector and r(t)=(∫_0^t)v(u)du+(Subscript[v, 0])t+(Subscript[r, 0]) where (Subscript[r, 0]) is the initial position.

Example 13.12.  Find the velocity vector, the speed, and the acceleration vector for the vector-valued function r(t)=(t^3)i+(1-t)j+4(t^2)k at time t=1.

Solution:

Clear[r,v,s,a]
r[t_]={t^3,1-t,4t^2}
v[t_]=r'[t]
s[t_]=Sqrt[v[t].v[t]]
a[t_]=r''[t]
v[1]
s[1]
a[1]

Thus, v(1)=r'(1)=3i-j+8k, s(1)=(Sqrt[74]), and a(1)=6i+8k.

Example 13.13.  Find r(t) and v(t) if a(t)=t i+4j subject to the initial conditions v(0)=3i-2j and r(0)=0.

Solution: We first solve for v(t) by integrating a(t):

Clear[r,v,a]
a[t_]={t,4}
v[t_]=Integrate[a[u],{u,0,t}]+{v01,v02}

Here, the constant vector of integration (Subscript[v, 0])=⟨(Subscript[v, 01]),(Subscript[v, 02])⟩=⟨3,-2⟩ equals the initial velocity:

Solve[v[0]=={3,-2},{v01,v02}]

Thus, v(t)=((t^2)/2)i+4t j+(3i-2j).

v[t_]=v[t]/.{v01->3,v02->-2}

Next, we solve for r(t) by integrating v(t):

r[t_]=Integrate[v[u],{u,0,t}]+{r01,r02}

Again, the constant vector of integration (Subscript[r, 0])=⟨(Subscript[r, 01]),(Subscript[r, 02])⟩=⟨0,0⟩ equals the initial position:

Solve[r[0]=={0,0},{r01,r02}]

Hence, r(t)=(((t^3)/6)+3t)i+(2(t^2)-2t)j.

Components of Acceleration

There are two components of acceleration: tangential and normal.  More precisely, the acceleration vector a can be decomposed as a=(Subscript[a, T])T+(Subscript[a, N])N, where (Subscript[a, T])=(((d^2)s)/(dt^2))=((a · v)/(|| v ||)) is the tangential component and (Subscript[a, N])=((κ((ds/dt)))^2)=((|| a × v ||)/(|| v ||)) is the normal component.  Moreover, one has (Subscript[a, T]^2)+(Subscript[a, N]^2)=((‖a‖)^2) so that (Subscript[a, N])=(Sqrt[||a((||)^2)-((Subscript[a, T])^2)]) and (Subscript[a, T])=(Sqrt[||a((||)^2)-((Subscript[a, N])^2)]).

Example 13.14.  Determine the tangential and normal components of acceleration for the vector function r(t)=⟨(t^3),(t^2),t⟩.

Solution:

Clear[r,v,s]
r[t_]={t^3,t^2,t}
r'[t]
r''[t]

speed=Simplify[Sqrt[r'[t].r'[t]]]

The result in the last output represents the speed at time t.  In order to secure the tangential component of the acceleration, we differentiate the previous output:

at=D[speed,t]

The normal component of the acceleration is

an=(Sqrt[r''[t].r''[t]-(at^2)])

Simplify[an]

NOTE: The components of acceleration can also be found through the formulas (Subscript[a, T])=((a · v)/(|| v ||)) and (Subscript[a, N])=((|| a × v ||)/(|| v ||)), confirmed using Mathematica as follows:

at=r''[t].r'[t]/Sqrt[r'[t].r'[t]]
an=Sqrt[Cross[r''[t],r'[t]].Cross[r''[t],r'[t]]]/Sqrt[r'[t].r'[t]]

Exercises

In Exercises 1 and 2, calculate the velocity and acceleration vectors and the speed at the time indicated:
1.  r(t)=(t^2)i+(1-t)j+(5(t^2))k, t=2.		2.  r(t)=cos t i+sin t j+tan (2t)k,t=(π/6).

3.  Sketch the path r(t)=(1-(t^2))i+(1-t)j for -3≤t≤3 and compute the velocity and acceleration vectors at t=0, t=1, and t=2.

4.  Find v(t) given a(t) and the initial velocity (Subscript[v, 0]).
a.  a(t)=t i+3j,v(0)=(1/2)i+2j 			b.  a(t)=(e^(2t))i+0j+(t+2)k,v(0)=i-3j+2k

5.  Find r(t) and v(t) given a(t) together with the initial velocity and position at rest:
a.  a(t)=(e^(3t))i+4t j+(t-2)k,v(0)=0i+0j+k,r(0)=0i+3j+4k
b. a(t)=0i+0j+sin t k,v(0)=i+j,r(0)=i.

6.  Find the decomposition of a(t) into its tangential and normal components at the indicated point:
a.  r(t)=(3-4t)i+(t+1)j+(t^2)k at t=1
b.  r(t)=t i+(e^(-t))j+t (e^(-t))k at t=0

7.  Show that the tangential and normal components of acceleration of the helix given by r(t)=(cos t) i+(sin t) j +t k are equal to 0 and 1, respectively.

Chapter 14	 Differentiation in Several Variables

Useful Tip: If you are reading the electronic version of this publication formatted as a Mathematica Notebook, then it is possible to view 3-D plots generated by Mathematica from different perspectives.  First, place your screen cursor over the plot.  Then drag the mouse while pressing down on the left mouse button to rotate the plot.

14.1  Functions of Two or More Variables

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

14.1.1 Plotting Level Curves using ContourPlot

We begin with plotting level curves f(x,y)=c of a function of two variables. The command to plot level curves is ContourPlot[f,{x,a,b},{y,c,d}].

Most of the options for ContourPlot are the same as those for Plot.  In the following example, we consider the option ImageSize.

Example 14.1.  Plot the level curves of f(x,y)=(x^2)+x y -(y^2) .

Solution:  Let us first plot the level curves using the default settings of Mathematica.

Clear[x,y,f]
f[x_,y_]:=(x^2)+x y -(y^2)

ContourPlot[f[x,y],{x,-5,5},{y,-5,5},ImageSize->{250}]

To get the level curves on the xy-plane without the shading, the colors, and the frame, but with the coordinate axes, we use the following options of ContourPlot.

ContourPlot[f[x,y],{x,-5,5},{y,-5,5},Frame->False,Axes->True,ContourShading->False,ImageSize->{250}]

Contours is an option of ContourPlot that can be used in two different ways: Contour->n displays n equally spaced contour curves while Contour->list plots level curves f(x,y)=c where c is an element of the list list.

To plot 15 level curves, we evaluate

ContourPlot[f[x,y],{x,-1,1},{y,-1,1}, Contours->15,ImageSize->{250} ]

Here is an example when list={-10,-5,-2, -1, 0,1, 2,  5, 10}.

ContourPlot[f[x,y],{x,-5,5},{y,-5,5},Contours->{-10,-5,-2,-1, 0, 1, 2, 5, 10},ImageSize->{250}]

14.1.2  Plotting Surfaces using Plot3D

Plot3D is the three-dimensional analog of the Plot command. Given an expression in two variables and the domain for the variables, Plot3D produces a surface plot.

The basic syntax to plot the graph of a function of two variables is Plot3D[ f,{x, a, b},{y, c, d}], where f is a function of x and y  with  a≤x≤b and c≤y≤d.

The command to plot the graphs of two or more functions on the same coordinate axes is Plot3D[{f, g, h, .... }, {x, a, b}, {y, c, d}], where f, g, h, ...  are the functions to be plotted.

We will begin with the default settings of plotting a graph of a function of two variables.

Example 14.2.  Plot f(x,y)=sin(x-cos y).

Solution:

Plot3D[Sin[x-  Cos[y]],{x,-3,3},{y,-3,3}]

Example 14.3.  Plot the graphs of f(x,y)=3x+4y-3 and g(x,y) =10 sin(xy) on the same axes.

Solution:  We will use red color for the graph of f and blue for that of g. This is given using the option PlotStyle.

Plot3D[{3x+4y-3,10Sin[x y]},{x,-5,5},{y,-5,5},PlotStyle->{Green,Blue},ImageSize->{250}]

NOTE: One of the most significant improvements of Mathematica 7.0 over the previous editions is its graphics capability.  Plot3D has many options.  Evaluate the command Options[Plot3D] to see the many options you have to plot a nice graph.

We will discuss some of these options below.

ViewPoint

In Mathematica 7.0, we can rotate the graph of a function of two variables by simply clicking on the graph and dragging the mouse around to see the graph from any point of view.

The option ViewPoint specifies the point in space from which the observer looks at a graphics object. The syntax for choosing a view point of a surface is Plot3D[f[x, y], {x, a, b}, {y, c, d}, ViewPoint->{A, B, C} ]. The default value for {A, B, C}  is {1.3,-2.4,2.0}. This may be changed by entering values directly.

To view a graph from directly in front {0, -2,0}; in front and up {0, -2,2}; in front and down {0, -2,-2}; left hand corner {  -2,-2,0};  directly above  {0, 0,2}.

Plot3D[ f[x, y], {x, a, b}, {y, c, d}, ViewPoint -> view ] produces a plot viewed from view. The possible values of view are Above (along positive z-axis), Below (along negative z-axis), Front (along negative y-axis), Back (along  positive y-axis), Left  (along the negative x-axis), and Right (along the positive x-axis).

Example 14.4.  Plot f(x,y)=cos x sin y using ViewPoint option to view the graph from various view points.

Solution: We leave it to the reader to navigate all of the above choices. We will consider a few of them.

Clear[f]
f[x_,y_]=Cos[x]  Sin[y]

Here is a plot of the graph using the default setting for ViewPoint:

Plot3D[ f[x,y],{x,-2Pi,2Pi},{y,-2Pi,2Pi} ,PlotRange->All,
ImageSize->{250} ]

View from directly in front:

Plot3D[ f[x,y],{x,-2Pi,2Pi},{y,-2Pi,2Pi},ViewPoint->Front ,
PlotRange->All ,ImageSize->{250}]

View from in front and up:

Plot3D[ f[x,y],{x,-2Pi,2Pi},{y,-2Pi,2Pi},ViewPoint->{0,-2,2},
PlotRange->All,ImageSize->{250}]

View from in front and down:

Plot3D[ f[x,y],{x,-2Pi,2Pi},{y,-2Pi,2Pi},ViewPoint->{0,-2,-2},
PlotRange->All,ImageSize->{250}]

View from directly above:

Plot3D[ f[x,y],{x,-2Pi,2Pi},{y,-2Pi,2Pi},ViewPoint->Above,
PlotRange->All,Ticks->{Automatic,Automatic,{-1,0,1}},
ImageSize->{250}]

View from the right:

Plot3D[ f[x,y],{x,-2Pi,2Pi},{y,-2Pi,2Pi},ViewPoint->Right,
PlotRange->All,ImageSize->{250}]

NOTE: As we pointed out earlier, we can also select different viewpoints by clicking on the graph and dragging the mouse around until we get the desired viewpoint.

Mesh, MeshStyle, MeshShading

The option Mesh specifies the type of mesh that should be drawn.

The option MeshStyle specifies the style in which a mesh should be drawn.

The option MeshShading is an option for specifying a list of colors to be used between mesh divisions.

We illustrate some uses of these options in the example below.

Example 14.5.  Plot f(x,y)=cos x sin y using various options involving Mesh.

Solution:

Clear[f]
f[x_,y_]=Cos[x]  Sin[y]

To plot a graph without a mesh we use the setting Mesh->None.

Plot3D[ f[x,y],{x,-2Pi,2Pi},{y,-2Pi,2Pi} , Mesh->None,
ImageSize->{250} ]

Mesh->n plots a surface with only n×n meshes.

Plot3D[ f[x,y],{x,-2Pi,2Pi},{y,-2Pi,2Pi} , Mesh->8 ,
ImageSize->{250}]

We can choose the color of the mesh using MeshStyle.

Plot3D[ f[x,y],{x,-2Pi,2Pi},{y,-2Pi,2Pi} , MeshStyle->
{Red,Black},ImageSize->{250} ]

Here is another use of MeshStyle:

Plot3D[ f[x,y],{x,-2Pi,2Pi},{y,-2Pi,2Pi} , MeshStyle->
{Dashing[0.01],None},ImageSize->{250} ]

To display a plot with selected colors between meshes we use MeshShading:

Plot3D[f[x,y],{x,-2Pi, 2Pi},{y,-2Pi,2Pi},MeshShading->{{Blue, Red, White},{Purple,Green,Black}},ImageSize->{250} ]

Here is a neat example in Mathematica 7.0:

Plot3D[(x^2-y^2)/(x^2+y^2)^2,{x,-1.5,1.5},{y,-1.5,1.5},BoxRatios->Automatic,PlotPoints->25,MeshFunctions->{#3&},MeshStyle->Purple,MeshShading->{None,Green,None,Yellow},ImageSize->{250}]

BoxRatios

The option BoxRatios specifies the ratio of the lengths of the sides of the box. This is analogous to specifying the AspectRatio of a two-dimensional plot.  For Plot3D, the default setting is BoxRatios->Automatic.

Example 14.6.  Plot f(x,y)=(e^(1-(x^2)-(y^2))) using the BoxRatio option.

Solution:

Clear[f]
f[x_,y_]= (E^(1-(x^2)- (y^2)))

Plot3D[ f[x,y],{x,-2,2},{y,-2,2},ImageSize->{250}]

Plot3D[ f[x,y],{x,-2,2},{y,-2,2},BoxRatios->{1,1,0.62`},
ImageSize->{250}]

AxesLabel

The option AxesLabel  is a command used to label the axes in plotting.

Example 14.7.  Plot f(x,y)=(Sqrt[9-(x^2)-(y^2)]) using the AxesLabel option.

Solution:

Clear[f]
f[x_,y_]= (Sqrt[9-(x^2)-(y^2)])

Plot3D[f[x,y],{x,-3,3},{y,-3,3},AxesLabel->{"x ","y ","z "},
ImageSize->{250},ImagePadding->{{15,15},{15,15}}]

NOTE: To label a graph, use the PlotLabel option as shown following:

Plot3D[f[x,y],{x,-3,3},{y,-3,3}, AxesLabel->{"x ","y ","z "},
PlotLabel->"Upper hemisphere",BoxRatios->Automatic,ImageSize->{250},
ImagePadding->{{15,15},{15,25}}]

ColorFunction

The option ColorFunction specifies a function to apply to the values of the function being plotted to determine the color to use for a particular region on the xy-plane. It is an option for Plot3D, ListPlot3D, DensityPlot, and ContourPlot.  The default setting for ColorFunction is ColorFunction->Automatic.  ColorFunction->Hue yields a range of colors.

Example 14.8.  Plot f(x,y)=sin((x^2)+(y^2)) +(e^(1- ((x )^2)-(y^2)))  in various colors using the ColorFunction option.

Solution:

Clear[f,x,y]
f[x_,y_]= Sin[(x^2)+(y^2)]+ (E^(1-(x^2)- (y^2)))

Plot3D[f[x,y],{x,-Pi,Pi},{y,-Pi,Pi},ColorFunction->Hue,
ImageSize->{250}]

Here are other ways to use ColorFunction.

Plot3D[f[x,y],{x,-Pi,Pi},{y,-Pi,Pi},ColorFunction-> "Rainbow",
ImageSize->{250} ]

Plot3D[f[x,y],{x,-Pi,Pi},{y,-Pi,Pi},ColorFunction->
"BlueGreenYellow",ImageSize->{250}]

NOTE: We can use PlotStyle option to select color for graphs. The plot below uses this option.

Plot3D[f[x,y],{x,-Pi,Pi},{y,-Pi,Pi},PlotStyle-> Yellow,
ImageSize->{250} ]

RegionFunction

The option RegionFunction specifies the region to include in the plot drawn.

Example 14.9.  Plot f(x,y)={({{10sin(3x-y),, if  (x^2)+(y^2)<4;}, {(x^2)+(y^2)-5,    , otherwise}}).

Solution: We will use the command RegionFunction to specify the domain (x^2)+(y^2)<4 as follows.  Note that we have used Show to display the graphs.

Clear[plot1,plot2] 
plot1 =Plot3D[10Sin[3x-y],  {x,-4,4},{y,-4,4},PlotStyle->Blue,
 RegionFunction->Function[{x,y,z}, x^2+y^2<4]];
plot2 =Plot3D[  (x^2)+(y^2) -5,{x,-4,4},{y,-4,4},PlotStyle->Red, 
 RegionFunction->Function[{x,y,z}, x^2+y^2 ≥4]];
Show[plot1,plot2,ImageSize->{250}]

If we want to focus on a particular part of a surface defined by a function, we can use the option RegionFunction. The following example shows this point.

Example 14.10.  Plot the graph of f(x,y) =(x^2)-3x y-2(y^2)  and show the portion of the surface direclty above the unit circle centered at the origin.

Solution: We will use the option ViewPoint.

Clear[plot1,plot2,f, x,y]
f[x_,y_]=(x^2) -3 x y -2(y^2) 
plot1 =Plot3D[f[x,y],  {x,-4,4},{y,-4,4},PlotStyle->Blue,
 RegionFunction->Function[{x,y,z},x^2+y^2<1 ]];
plot2 =Plot3D[f[x,y] ,{x,-4,4},{y,-4,4},PlotStyle->Red,
RegionFunction->Function[{x,y,z}, x^2+y^2>1 ]]; 
Show[plot1,plot2 ,ViewPoint->Front,ImageSize->{250} ]

14.1.3  Plotting Parametric Surfaces using ParametricPlot3D

ParametricPlot3D is a direct analog of ParametricPlot.  Depending on the input, ParametricPlot3D  produces a space curve or a surface. ParametricPlot3D[{f, g, h}, {t, a, b }] produces a three-dimensional space curve parametrized by the variable t, which runs from  a to b. ParametricPlot3D[{f, g, h}, {t, a, b },{u, c, d}] produces a two-dimensional surface parametrized by t and u. Options are given to ParametricPlot3D the same way as for  Plot3D. Most of the options are the same.

Example 14.11.  Plot the curve that is parametrized by x=sin t, y=cos t and z=t/3 with 0≤t≤2π.

Solution:

ParametricPlot3D[{Sin[t],Cos[t],(t/3)},{t,0,2 π},ImageSize->{250},
ImagePadding->{{15,15},{15,15}}]

Example 14.12.  Plot the surface that is parametrized by  x = u cos u (4 + cos(u + v)), y = u sin u (4 + cos(u + v)), and z = u sin(u + v).

Solution:

ParametricPlot3D[{u Cos[u] (4+Cos[u+v]),u Sin[u] (4+Cos[u+v]),u Sin[u+v]},{u,0,4 π},{v,0,2 π},ImageSize->{250}]

14.1.4  Plotting Level Surfaces using ContourPlot3D

ContourPlot3D is the command used to plot level surfaces of functions of three variables.  Its syntax is ContourPlot3D[f,{x,a,b}, {y,c,d},{z,e,f}].  Most of the Options for ContourPlot3D are the same as those of Plot3D.  Below we will consider the option Contours of ContourPlot3D.

Example 14.13.  Plot level surfaces of f(x,y,z)=(x^2)+(y^2)+(z^2).

Clear[x,y,z,f]
f[x_,y_,z_]=(x^2)+(y^2)+(z^2)
ContourPlot3D[f[x,y,z],{x,-3,3},{y,-3,3},{z,-3,3},ImageSize->{250}]

The following displays five (5) equally spaced contour surfaces of f.

ContourPlot3D[f[x,y,z],{x,-3,3},{y,-3,3},{z,-3,3},
Contours->5,ImageSize->{250}]

The following  displays three level surfaces f(x,y,z)=c, where c=1, 4, 9.

ContourPlot3D[f[x,y,z],{x,-3,3},{y,-3,3},{z,-3,3},
Contours->{1,4,9},ImageSize->{250}]

Notice that we only see one sphere. The other two are enclosed in the sphere of radius 3 corresponding to c=9.  One way to remedy this is to plot the level surfaces one by one. For this we use the GraphicsArray command. First, let us define the level surfaces as function of c:

Clear[c,plot]
plot[c_]:=ContourPlot3D[f[x,y,z],{x,-3,3},{y,-3,3},{z,-3,3},
Contours->{c}]

Here are the three level surfaces corresponding to c=1, 4, 9.

Show[GraphicsArray[{plot[1],plot[4],plot[9]}]]

Exercises

In Exercises 1 through 4, plot the level curves and the graphs of the given functions.
1.  f(x,y)=x (y^5)-(x^5)y for -10≤x≤10, -10≤y≤10
2.  f(x,y)=(((x^2)+2y)/(1+(x^2)+(y^2))) for -10≤x≤10, -10≤y≤10
3.  f(x,y)=(sin y )(e^(cos x)) for -2π≤x≤2π, -2π≤y≤2π
4.  f(x,y)= sin(x+sin(y)) for -4π≤x≤4π, -4π≤y≤4π

In Exercises 5 through 7, use at least two nondefault options to plot the given functions.
5.  f(x,y)=sin (x-2y)(e^(1/(y-x))) for  -2π≤x≤2π, -2π≤y≤2π
6.  f(x,y)=4-3|x|-2|y| for -10≤x≤10, -10≤y≤10
7.  f(x,y)=(tanh^(-1))(x/y) for -5≤x≤5, -5≤y≤5

8.  Plot f(x,y)={({{(x^2)+(y^2)-4      if (x^2)+(y^2)<4}, {4-(x^2)+3(y^2)         otherwise }})

9.  Plot the portion of the helicoid (spiral ramp) that is defined by:
x = u cos v,  y = u sin v, z = v for 0 ≤ u ≤ 3  and  -2π ≤ v ≤2 π

10. Use ContourPlot3D to plot the level surfaces of the function f(x,y,z)=9-(x^2)-(y^2)-(z^2).

14.2  Limits and Continuity

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

14.2.1  Limits

If f(x,y) is a function of x and y, and if the domain of f contains a circle around the point (a,b), we say that the limit of f at (a,b) is L if and only if f(x,y) can be arbitrarily close to L for all (x,y) arbitrarily close (a,b).

More precisely, for a given ϵ>0, there exists a δ>0 such that for every (x,y) is in the domain of f,

0<(Sqrt[(((x-a))^2)+(((y-b))^2)])<δ  ⟹ |f(x,y)-L|<ϵ

If this is the case, we write

(lim_((x,y)->(a,b)))f(x,y)=L

The Limit command of Mathematica is restricted to functions of one variable. However, we can use it twice to find the limit of function of two variables provided the limit exists.

Example 14.14.  Find (lim_((x,y)->(3,4)))((x^2)+(y^2)).

Solution: We can easliy determine that the limit exists. We can find the limit by evaluating

Limit[Limit[(x^2)+(y^2),x->3],y->4]

The plot following confirms this.

Clear[plot1,plot2]
plot1=Plot3D[(x^2)+(y^2),{x, 1,4},{y, 3, 5}];
plot2=Graphics3D[{Red,PointSize[.025],Point[{3,4,25}]}];
Show[plot1,plot2,ImageSize->{250},ImagePadding->{{15,15},{15,15}}]

Example 14.15.   Find (lim_((x,y)->(4,1)))((3x+(y^2))/(x-4y)).

Solution: We will evaluate the limit in two different orders. The limit in which we use limit with x first and then with y is

Clear[f,x,y]
f[x_,y_]=((3x+(y^2))/(x-4y))

The limit in which we use limit with x first and then with y is

Limit[Limit[f[x,y],x->4],y->1]

The limit in which we use limit with y first and then with x is

Limit[Limit[f[x,y],y->1],x->4]

Here is the plot of the graph near the point (4,1). Observe that the graph of the function is in green and the point (4,1,0) is in red. For a better comaprison, we have colored the xy-plane light blue. You may need to rotate the graph to see the point (4,1,0) on the xy-plane and see how the graph behaves when (x,y) is close to (4,1).

Clear[plot1,plot2]
plot1=Plot3D[{f[x,y],0},{x,3,5},{y, 0, 2},PlotStyle->{Green, LightBlue},PlotPoints->100];
plot2=Graphics3D[{Red,PointSize[.025],Point[{4,1,0}]}];
Show[plot1,plot2,ImageSize->{250},
ImagePadding->{{15,15},{15,15}}]

Here is the animation with x as the animation parameter.

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[Plot[f[x,y],{y, 0,3},PlotRange->{-20,20}],{x,3, 5}]

Example 14.16.  Find (lim_((x,y)->(0,0)))((sin x sin y)/(x y)).

Solution: We will evaluate the limit in two different orders.

Clear[f,x,y]
f[x_,y_]=((Sin[x  y])/(x y))

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

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

Here is the plot of the graph and the point (0,0,1).

Clear[plot1,plot2]
plot1=Plot3D[f[x,y],{x,-1,1},{y, -1, 1},PlotStyle-> Green];
plot2=Graphics3D[{Red,PointSize[.02],Point[{0,0,1}]}]; 
Show[plot1,plot2,ImageSize->{250}]

If we rotate this graph to a suitable position, we notice that the limit exists.  Here are animations with x and y as animation parameters, respectively.

Animate[Plot[f[x,y], {x, -2,2},PlotRange->{0,1}], {y, -2, 2}]

Animate[Plot[f[x,y], {y, -2,2},PlotRange->{0,1}], {x, -2, 2}]

Example 14.17.  Find (lim_((x,y)->(0,0))) x ln y.

Solution:

Clear[f,x,y]
f[x_,y_]=x Log[y]

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

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

Clear[plot1,plot2]
plot1=Plot3D[{f[x,y],0},{x,-1,1},{y, -1, 1},PlotStyle->{ Green,LightBlue}];
plot2=Graphics3D[{Red,PointSize[.025],Point[{0,0,0}]}];
Show[plot1,plot2,ImageSize->{250},
ImagePadding->{{15,15},{15,15}}]

Here is the animation with x as the animation parameter.

Animate[Plot[f[x,y], {y, -2,2},PlotRange->{-10,10}], {x, -2, 2}]

Example 14.18.  Consider the function f(x,y)=((x (y^2))/((x^2)+(y^4))). Show that (lim_((x,y)->(0,0)))f(x,y) does not exist.

Solution:

Clear[f,x,y]
f[x_,y_]=((x (y^2))/((x^2)+(y^4)))

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

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

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

However, note that the limit along the curve y=(Sqrt[x]) is

Limit[Limit[f[x,y],y->  (Sqrt[x])], x->0]

Hence, the limit does not exist.  Here is the plot of the function:

Plot3D[f[x,y],{x,-1,1},{y, -1, 1},ImageSize->{250}]

14.2.2  Continiuty

Recall that a function f of two variables x and y is continuous at the point (a,b) if and only if (Subscript[limi, (x,y)->(a,b)])f(x,y)=f(a,b).

Example 14.19.  Let f(x,y)={({{1-(x^2)-(y^2), if (x^2)+(y^2)<1}, {0,                 if (x^2)+(y^2)≥1}}).  Is f continuous?

Solution: Clearly, f is continuous at all points inside and outside the circle of radius 1.  To check continuity on the unit circle, we let x=r cos t and y=r sin t. We then let r->1.

Clear[x,y,r,s,t,f] 
f[x_,y_]=1-(Sqrt[(x^2)+(y^2)])

x=r Cos[t]
y=r Sin[t]

Simplify[f[x,y]]

Limit[f[x,y],r->1]

The command below evaluates f on the circle.

Simplify[f[x,y]/.r->1]

Thus, the limit and the value of f are equal at all points on the unit circle. Hence, f is continuous everywhere.  Here is the graph.

Clear[plot1,plot2]
plot1=Plot3D[f[x,y],{x,-5,5},{y,-5,5},PlotStyle->Red, 
 RegionFunction->Function[{x,y,z},x^2+y^2<1],Mesh->None];
plot2=Plot3D[  0,{x,-5,5},{y,-5,5},PlotStyle->LightBlue,
 RegionFunction->Function[{x,y,z}, x^2+y^2 ≥1],Mesh->None];
Show[plot1,plot2,ImageSize->{250}]

Exercises

In Exercises 1 through 4, find the limit, if it exists.
1.  (lim_((x,y)->(1,-1)))(2(x^2)y +x (y^2))		2. (lim_((x,y)->(1,1)))((3(x^2)+(y^2))/((x^2)-y))
3.   (lim_((x,y)->(0,0)))((tan x sin y)/(x y))	 		4.  (lim_((x,y)->(0,0))) sin x ln y

5. Consider the function f(x,y)=(((x^2) +(y^2))/((x^2)+(y^4))). Show that (lim_((x,y)->(0,0)))f(x,y) does not exist.

6.  Let f(x,y)={({{(x^2)-(y^2), if x+y<0}, {2x+y,  if x+y≥0}}).
Is f continuous?

7.  Let f(x,y)=((x y)/((x^2)+(y^2))). The domain of f is the whole plane without the origin. Is it possible to define f(0,0) so that f is continuous everywhere? Plot the graph of f to support your conclusions.

8.  The domain of f(x,y)=((x y)/(x+y))  is the whole plane without the line y=-x.   Is it possible to define f(0,0) so that f is continuous everywhere? Plot the graph of f to support your conclusions.

14.3  Partial Derivatives

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

Recall that the Mathematica command for the partial derivative of a function f with respect to x is D[f, x], and D[f,{x,n}] gives the nth partial derivative of f with respect to x. The multiple (mixed) partial derivative of f with respect to (Subscript[x, 1]),(Subscript[x, 2]),(Subscript[x, 3]),... is obtained by D[f,(Subscript[x, 1]),(Subscript[x, 2]),(Subscript[x, 3]),...].  We can access this command from  BasicMathInput. The symbols are (∂_□) □ and (∂_(□,□))□ .

Example 14.20.  Find the first partial derivatives of (x^3)+(y^2) with respect to x and (y^( )).

Solution:  We give two methods of input.

Method 1: We can type all the inputs and the command as follows:

Clear[x,y]
D[x^3+y^2,x]

D[x^3+y^2,y]

Method 2:  We can use the BasicInput palette to enter the inputs.

(∂_x) ((x^3)+(y^2))

(∂_y) ((x^3)+(y^2))

Example 14.21.  Find the four second partial derivatives of (x^3)sin(y)+(e^(x y)).

Solution: Let z=(x^3)sin y+(e^(x y)).  We again demonstrate two methods of input.

Method 1:

We can find (Subscript[z, xx]) by

Clear[x,y]
D[x^3*Sin[y]+E^(x*y),{x,2}]

We can find (Subscript[z, yy]) by

D[x^3*Sin[y]+E^(x*y),{y,2}]

We can find (Subscript[z, xy]) by

D[x^3*Sin[y]+E^(x*y),x,y]

(Subscript[z, yx])  is given by

D[x^3*Sin[y]+E^(x*y),y,x]

NOTE: Clairaut's Theorem states that if the mixed partial derivatives (Subscript[f, x y]) and (Subscript[f, y x]) are continuous at a point (x,y), then they are equal: (Subscript[f, x y])=(Subscript[f, y x]).  The last two outputs confirm Clairaut's Theorem for this particular example.

Method 2: Here is the input using the palette symbol (∂_(□,□))□:

Clear[x,y]
(∂_(x,x))((x^3)*Sin[y]+(E^(x*y)))   
(∂_(y,y))((x^3)*Sin[y]+(E^(x*y)))
(∂_(x,y))((x^3)*Sin[y]+(E^(x*y)))
(∂_(y,x))((x^3)*Sin[y]+(E^(x*y)))

Example 14.22.  Evaluate the first partial derivatives of x y+y (z^2)+x z at (-1,2,3).

Solution: Recall that Expr /.{(Subscript[x, 1])->(Subscript[a, 1,])(Subscript[x, 2])->(Subscript[a, 2,])(Subscript[x, 3])->(Subscript[a, 3,])... } is the command for substituting (Subscript[x, 1]) by (Subscript[a, 1]), (Subscript[x, 2]) by (Subscript[a, 2]), (Subscript[x, 3]) by (Subscript[a, 3]), .... , in Expr.

Clear[x,y,z]
D[x*y + y*z^2 + x*z,x]/.{x-> -1, y->2, z->3}

D[x*y + y*z^2 + x*z,y]/.{x->-1, y->2, z->3}

D[x*y+y*z^2+x*z,z]/.{x->-1, y->2, z->3}

Example 14.23.  Let f(x,y,z)=y (e^x)+x (e^(-y))ln z. Find   (Subscript[f, x x x]), (Subscript[f, x y z]), (Subscript[f, x z z]), (Subscript[f, z x z ]), and (Subscript[f, z z x]).

Solution: First, we define f(x,y,z) in Mathematica. We can use the (∂_(□,□))□ notation. Since the palette gives only two boxes for the variables, we need to add one more box. This can be done by using CTRL +, (comma), that is, hold the CONTROL key and press the COMMA button.  Note also that the command D[f[x,y,z],x,y,z] gives (Subscript[f, xyz]). We demonstrate both methods.

Clear[x,y,z,f]
f[x_,y_,z_]:=y*(E^x)+x *Log[z]*(E^(-y))

(∂_(x,x,x)) f[x,y,z]

(∂_(x,y,z)) f[x,y,z]

(∂_(x,z,z)) f[x,y,z]

D[f[x,y,z],z,x,z]

D[f[x,y,z],z,z,x]

Example 14.24.  Let f(x, y) = x y (((x^2)-(y^2))/((x^2)+(y^2))) if (x,y)≠(0,0) and f(0,0)=0. 
a) Find (Subscript[f, x])(x,y) and (Subscript[f, y])(x,y) for (x,y)≠(0,0).
b) Use the limit definition to find (Subscript[f, x])(0,0) and (Subscript[f, y])(0,0).
c) Find (Subscript[f, x y]) (x,y) and (Subscript[f, y x])(x,y) for (x,y)≠(0,0).
d) Use the limit definition to find (Subscript[f, x y])(0,0) and (Subscript[f, y x])(0,0).

Solution: We will first define f using the If command.

Clear[x,y,f,fx,fy,fxy,fyx]
f[x_,y_]=If[{x,y}≠{0,0}, x y (((x^2)-(y^2))/((x^2)+(y^2))),0]

a)  Let fx and fy denote the partial derivatives with respect to x and y, respectively. Then

fx[x_,y_]=D[f[x,y],x]
fy[x_,y_]=D[f[x,y],y]

If we use the FullSimplify command to simplify the preceding output, we get

FullSimplify[fx[x,y]]
FullSimplify[fy[x,y]]

Thus, (Subscript[f, x])(x,y)=((y((x^4)+4(x^3)(y^2)-(y^4)))/((((x^2)+(y^2)))^2)) and  (Subscript[f, y])(x,y)=((x((x^4)-4(x^2)(y^2)-(y^4)))/((((x^2)+(y^2)))^2)) if (x,y)≠(0,0).

b) We use the limit definition (Subscript[f, x])(0,0)=(lim_(h->0 ))((f(0+h,0)-f(0,0))/h)and (Subscript[f, y])(0,0)=(lim_(k->0 ))((f(0,0+k)-f(0,0))/k)  to find the partial derivatives at (0,0).

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

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

Hence, (Subscript[f, x])(0,0)=0 and (Subscript[f, y])(0,0)=0.

c) To find the mixed second partial derivatives, we use fx and fy from the outputs in part a).  Note that the FullSimplify command is used to to get a simplified form of the mixed partial derivatives.

fxy[x_,y_]=FullSimplify[D[fx[x,y],y]]
fyx[x_,y_]=FullSimplify[D[fy[x,y],x]]

Thus, (Subscript[f, x y])=(((x-y)(x+y)((x^4)+10(x^2)(y^2)+(y^4)))/((((x^2)+(y^2)))^3)) and (Subscript[f, y x])=(((x-y)(x+y)((x^4)+10(x^2)(y^2)+(y^4)))/((((x^2)+(y^2)))^3)) for (x,y)≠(0,0). Note that these two functions are equal for (x,y)≠(0,0) in conformity with Clairaut's Theorem, since both are continuous when (x,y)≠(0,0).

d) We use the limit definition of a partial derivative to compute (Subscript[f, xy])(0,0) and (Subscript[f, yx])(0,0).  Recall that we have defined (Subscript[f, x]) as fx[x,y] and (Subscript[f, y]) as fy[x,y].

Then (Subscript[f, xy])(0,0) is given by

Limit[((fx[0 ,0+k]-fx[0,0])/k),k->0]

and (Subscript[f, yx])(0,0) is given by

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

Thus, (Subscript[f, xy])(0,0)=-1and (Subscript[f, yx])(0,0)=1.  Note that this implies that the mixed partial derivatives are not continuous at (x,y)=(0,0).  To see this graphically, first consider the following graph of f, which confirms that f has partial derivatives everywhere.

Plot3D[f[x,y],{x,-3,3},{y,-3,3},ImageSize->{250}]

Here are the graphs of (Subscript[f, x]) and (Subscript[f, y]), which now show why the second mixed partials at the origin are not equal.

Clear[plot1,plot2]
plot1= Plot3D[fx[x,y],{x,-3,3},{y,-3,3}, PlotStyle->Red,AxesLabel->{"Graph of z=(Subscript[f, x])", None, None}] ;
plot2= Plot3D[fy[x,y],{x,-3,3},{y,-3,3}, PlotStyle->Blue,AxesLabel->{"Graph of z=(Subscript[f, y])", None, None}] ;
Show[GraphicsArray[{plot1,plot2}],ImageSize->{420}]

In addition, the graphs of (Subscript[f, xy]) and (Subscript[f, yx]) show the mixed partials are not continuous at the origin. This is the main reason why the inequalities of the mixed partials at the origin does not contradict Clairaut's Theorem.

Clear[plot1,plot2]
plot1=Plot3D[fxy[x,y],{x,-3,3},{y,-3,3}, PlotStyle->Red, AxesLabel->{"Graph of z=(Subscript[f, xy])", None, None}];
plot2=Plot3D[fyx[x,y],{x,-3,3},{y,-3,3}, PlotStyle->Blue, AxesLabel->{"Graph of z=(Subscript[f, yx])", None, None}];
Show[GraphicsArray[{plot1,plot2}],ImageSize->{420}]

Exercises

1. Let f(x,y)=((((x-y))^2)/((x^2)+(y^2))).  Find:  
a. (Subscript[f, x]) (1,0)	b. (Subscript[f, y])(1,0)	c. (Subscript[f, xy])		d. (Subscript[f, yx])		e.  (Subscript[f, xxy])

2. Find the first partial derivatives of z=(x^3)(y^2) with respect to (x^( ))and y.

3. Find the four second partial derivatives of (x^2)cos(y) +tan(x (e^y)).

4. Evaluate the first partial derivatives of f(x,y,z)=(e^(-z))xy +(yz^2)+xz at (-1,2,3).

5. Let f(x,y,z)=(((x^4)(y^3))/((z^2)+sin x)).  Find (Subscript[f, xxx]), (Subscript[f, xyz]), (Subscript[f, xzz]), (Subscript[f, zxz ]), and (Subscript[f, zzx]).

6. Let f(x, y) = ((x (y^2))/((x^2)+(y^4))) if (x,y)≠(0,0) and f(0,0)=0. 
a.  Find (Subscript[f, x])(x,y) and (Subscript[f, y])(x,y) for (x,y)≠(0,0).
b.  Use the limit definition to find (Subscript[f, x])(0,0) and (Subscript[f, y])(0,0).
c.  Find (Subscript[f, xy]) (x,y) and (Subscript[f, yx])(x,y) for (x,y)≠(0,0).
d.  Use the limit definition to find (Subscript[f, xy])(0,0) and (Subscript[f, yx])(0,0).

14.4  Tangent Planes

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

Let z=f(x,y) be a function of two variables.  The equation of the tangent plane at the point (a,b,f(a,b)) is given by

z=(Subscript[f, x])(a,b)(x-a) +(Subscript[f, y])(a,b)(y-b)+f(a,b)

Example 14.25.  Let f(x, y) =  (x^2)+(y^2).
a) Find the equation of the tangent plane to the graph of f at the point (2,1,3).
b) Plot the graph of f and its tangent plane at (2,1,3).

Solution: Here, a=2, b=1.
a)

Clear[f,x,y,z]
f[x_,y_]=(x^2)+(y^2)

Thus, the equation the of the tangent plane is

A=(∂_x) f[x,y] /.{x->2,y->1};
 B=(∂_y) f[x,y] /.{x->2,y->1};
z=A (x-2) + B(y-1)+f[2,1];
Simplify[z]

b) Here is a plot of the graph of f:

plot1=Plot3D[{f[x,y],z},{x,-10,10},{y, -10, 10},PlotStyle-> {Blue,Green}];
plot2=ListPointPlot3D[{ {2,1,3}},PlotStyle-> {Red,PointSize[Large]}  ];
Show[plot1,plot2,ImageSize->{250},ImagePadding->{{15,15},{15,15}}]

Example 14.26.  Let f(x, y) =(x^2) y-6 x (y^2)+3y.  Find the points where  the tangent plane to the graph of f is parallel to the xy-plane.

Solution:  For the tangent plane to be parallel to the xy-plane, we must have (Subscript[f, x])=0 and (Subscript[f, y])=0.

Clear[f,x,y ]
f[x_,y_]= (x^(2 ))y-6 x (y^2)+3y

A tangent plane is parallel to the xy-plane at

Solve[{ D[f[x,y],x] ==0,  D[f[x,y],y] ==0}]

Rotate the following graph to see the points of tangencies.

Plot3D[{f[x,y],f[-1,-1/3],f[1,1/3]},{x,-1,1},{y,-1,1},PlotStyle-> {LightBlue,Green,Red},PlotRange->All,ImageSize->{250},ImagePadding->{{15,15},{15,15}}]

Exercises

1. Let  f(x,y)=(x^(3 ))y +x (y^2)-3x +4.
a) Find a set of parametric equations of the normal line and an equation of the tangent plane to the surface at the point (1, 2).
b) Graph the surface, the normal line, and the tangent plane found in a).

2. Let f(x, y) =  (x^2)+(y^2).
a. Find the equation of the tangent plane to the graph of f at the point (2,1,5).
b. Plot the graph of f and its tangent plane at (2,1,5).

3.  Let f(x, y) =  (e^(-y/x)).
a. Find the equation of the tangent plane to the graph of f at the point (1,0,1).
b. Plot the graph of f and its tangent plane at (1,0,1).

4.  Let f(x, y) =cos (x y).  Find the points where  the tangent plane to the graph of f is parallel to the xy-plane.

14.5  Gradient and Directional Derivatives

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

Recall that the notation for a vector such as u=2i +5j -6k in Mathematica is {2,5,-6}.  The command for the dot product of two vectors u and v is obtained by typing u.v.

The gradient of f, denoted by  ∇f, at (a,b) can be obtained by evaluating ∇f(a,b)=⟨(∂_x)f(a,b), (∂_y)f(a,b)⟩.

The directional derivative of f at (a,b) in the direction of a unit vector u is given by (Subscript[D, u])f=∇f(a,b)·u.

Example 14.27.  Find the gradient and directional derivative of f(x,y)=(x^2)sin 2y at the point  (1,(π/2),0)   in the direction of v=⟨(3/5),-(4/5)⟩.

Solution:

Clear[f,v]
f[x_,y_]:=(x^2) *Sin[2y]
v={(3/5),((-4)/5)}

The gradient of f at (1,(π/2))  is

∇f ={(∂_x) f[x,y],(∂_y) f[x,y]}/.{x->1,y->(π/2)}

Since v is a unit vector, the directional derivative is given by

direcderiv=v.∇f

Example 14.28.  Find the gradient and directional derivative of  f(x,y,z)=x y+y z+x z at the point  (1, 1, 1)  in the direction of v=2i+j-k.

Solution:

Clear[x,y,z]
w=x*y+y*z+x*z
v={2,1,-1}

We normalize v:

unitvector=v/Norm[v]

The gradient of w=f(x,y,z) at (1,1,1) is

∇w={D[w,x],D[w,y],D[w,z]}/.{x->1,y->1,z->1}

Hence, the directional derivative is given by

direcderiv=unitvector.∇w

Example 14.29.  Plot the gradient vector field and the level curves of the function f(x,y)=(x^2)sin 2y.

Solution:

Clear[f,fx,fy,x,y]
f[x_,y_]= (x^2)-3x y+y-(y^2)
fx=D[f[x,y],x]
fy=D[f[x,y],y]

Thus, the gradient vector field is ∇f(x,y)=⟨ 2x-3y,1-3x-2y⟩.  To plot this vector field, we need to download the package VectorFieldPlots, which is done by evaluating

Needs["VectorFieldPlots`"]

Here is a plot of some level curves and the gradient field.

Clear[plot1,plot2]
plot1=ContourPlot[f[x,y],{x, -5,5},{y,-4,4},Axes->True,Frame->False,Contours->15, ColorFunction->Hue] ;
plot2=VectorFieldPlot[{fx,fy},{x, -5,5},{y,-4,4},Axes->True,Frame->False];
Show[plot1, plot2,ImageSize->{250}]

Example 14.30.  Let the temperature T at a point (x,y) on a metal plate be given by  T(x,y)=(x/((x^2)+(y^2))). 
a) Plot the graph of the temperature. 
b) Find the rate of change of temperature at (3,4), in the direction of v=i-2j.
c) Find the unit vector in the direction of which the temperature increases most rapidly at (3,4).
d) Find the maximum rate of increase in the temperature at (3,4).

Solution: 
a)  Here is the graph of T.

T[x_,y_]=(x/((x^2)+(y^2)))

graphofT=Plot3D[T[x,y],{x,-5,5},{y,-5,5},BoxRatios->{1,1,1},ImageSize->Small]

b) Let u=(v/(‖v‖)).  Then u is a unit vector and the rate of change in temperature at (3,4) in the direction of v is given by (Subscript[D, u])T(3,4)=∇f(3,4)·u.

∇T={D[T[x,y],x],D[T[x,y],y]}
v={1,-2}
u=(v/(Sqrt[v.v]))
u.∇T/.{x->3,y->4}//N

Thus, the rate of change at (3,4) in the direction v is 0.0393548.  NOTE: The command //N in the last line of the previous input converts the output to decimal form.

c) The unit vector in the direction of which the temperature increases most rapidly at (3,4) is given by

((∇T)/(Norm[∇T]))/.{x->3,y->4}

d) The maximum rate of increase in the temperature at (3,4) is the norm of the gradient at this point. This can be obtained by:

Norm[∇T]/.{x->3,y->4}

Exercises

1. Find the gradient and directional derivative of  f(x,y)=(sin^(-1))(x y) at the point  (1,1,(π/2))   in the direction of v=⟨1,-1⟩.

2. Let  T(x,y)=(e^(x y -(y^2))).
a. Find ∇ T(x, y).
b. Find the directional derivative of  T(x,y) at the point (3,5) in the dierection of u = 1/2 i  + (Sqrt[3])/2j.
c. Find the direction of greatest increase in T from the point (3,5).

3.  Plot the gradient vector field and the level curves of the function a f( x , y ) = cos x ((sin )^2)y.

4.  Find the gradient and directional derivative of  f(x,y,z) =  x y (e^( y z))+ sin (x z) at the point (1,1,0)  in the direction of v=i-j-k.

14.6  The Chain Rule

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

Example 14.31.  Let x=(t^2)+s ,y=t+(s^(2 )) and  z=x sin y.  Find the first partial derivatives of z with respect to s and t.

Solution:

Clear[x,y,z,s,t]
x=(t^2)+s
y=t+(s^2)
z=x Sin[y]

D[z,s]

D[z,t]

Example 14.32.  Find the partial derivatives of z with respect to x and y assuming that the equation (x^2)z-y (z^2)=x y defines z as a function of x and y.

Solution:

Clear[x,y,z,r,t,s]
eq= (x^2)z[x,y] -y ((z[x,y])^2)==x y

Solve[D[eq,x],D[z[x,y],x]]
Solve[D[eq,y],D[z[x,y],y]]

Example 14.33.  Let f(x,y,z)=F(r), where r=(Sqrt[(x^2)+(y^2)+(z^2)]) and F is a twice differentiable function of one variable. 
a) Show that ∇f=F'(r) (1/r)(x i +y j+z k).
b) Find the Laplacian of f.

Solution: 
a)

Clear[x,y,z,r,f,F]
f[x_,y_,z_]=F[r]

r=(Sqrt[(x^2)+(y^2)+(z^2)])

Here is the gradient of f:

gradf={D[f[x,y,z],x],D[f[x,y,z],y],D[f[x,y,z],z]}

With r=(Sqrt[(x^2)+(y^2)+(z^2)]), the preceding output becomes

∇f(x,y,z)=⟨  ((x F'(r))/r), ((y F'(r))/r),((z F'(r))/r)⟩=F'(r)(1/r)⟨ x ,y ,z ⟩

which proves part a).

b) Recall that the Laplacian of f, denoted by Δ f, is defined by Δ f=(Subscript[f, xx])+(Subscript[f, yy])+(Subscript[f, zz]).

D[f[x,y,z],{x,2}]+D[f[x,y,z],{y,2}]+D[f[x,y,z],{z,2}]

We simplify this to get

Simplify[%]

which is the same as (2/r)F'[r]+F''[r].

Exercises

1. Let x=(u^2)+sin v, y=u (e^(v/u)), and z=(y^3)ln x  .  Find the first partial derivatives of z with respect to u and v.

2. Find the partial derivatives of z with respect to x and y assuming that the equation (x^2)z-y (z^2)=x y defines z as a function of x and y.

3. Find an equation of the tangent plane to the surface x z +2 (x^2)y +(y^2)(z^3)=11 at (2,1,1).

14.7  Optimization

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

Second Derivative Test: Suppose (Subscript[f, x])(a,b)=0 and (Subscript[f, y])(a,b)=0.  Define

D(x,y)=(Subscript[f, x x])(Subscript[f, y y ])-((((Subscript[f, x y])))^2)

The function D is called the discriminant function.

i)   If D(a,,b)>0 and (Subscript[f, x x])(a,b)>0, then f(a,b) is a local minimum value.
ii)   If D(a,,b)>0 and (Subscript[f, x x])(a,b)<0, then f(a,b) is a local maximum value.
iii)  If D(a,,b)<0, then (a,b,f(a,b)) is a saddle point on the graph of f.
iv)  If D(a,b)=0, then no conclusion can be drawn about the the point (a,b).

Example 14.34.  Let f(x,y)=(x^4)-4 x y+2(y^2). 
a)  Find all critical points of f.
b)  Use the second derivative test to classify the critical points as local minimum, local maximum, saddle point, or neither.

Solution: Since D is used in Mathematica as the command for derivative, we will use disc for the discriminant function D.

Clear[f,x,y]
f[x_,y_]=(x^4)-4x y +2(y^2)

a) The critical points are given by

cp=Solve[{D[f[x,y],x]==0,D[f[x,y],y]==0}]

b)

Clear[fxx,disc]
fxx[x_,y_]=D[f[x,y],{x,2}]
disc[x_,y_]=D[f[x,y],{x,2}]*D[f[x,y],{y,2}]-(((D[D[f[x,y],x],y]))^2)

TableForm[Table[{ cp[[k,2,2]],   cp[[k,1,2]] ,  disc[cp[[k,2,2]],cp[[k,1,2]]], fxx[cp[[k,2,2]],cp[[k,1,2]]],f[cp[[k,2,2]],cp[[k,1,2]]]},{k,1,Length[cp]}],
TableHeadings->{{},{"x ", "y  ",  "  D(x,y) ","  (Subscript[f, xx])  ","f(x,y)"}}]

By the second derivative test, we conclude that f has a local minimum value of -1 at (-1,-1) and (1,1), and a saddle point at (0,0).

Here is the graph of f and the relevant points.

Clear[plot1,plot2]
plot1=Plot3D[f[x,y],{x,-2,2},{y, -2,2},PlotStyle-> LightBlue,PlotRange-> 10];
plot2=Graphics3D[{PointSize[Large], Red, Point[Table[{ cp[[k,2,2]],   cp[[k,1,2]] ,  f[cp[[k,2,2]],cp[[k,1,2]]]},{k,1,Length[cp]}]]}, PlotRange->10];
Show[plot1,plot2,ImageSize->{250}]

Example 14.35.  Let f(x,y)=(x^3)+(y^4)-6x-2(y^2). 
a)  Find all critical points of f.
b)  Use the second derivative test to classify the critical points as local minimum, local maximum, saddle point, or neither.

Solution: Again, we will use disc to denote the discriminant function D since the letter D is used in Mathematica for the derivative command.

Clear[f,x,y]
f[x_,y_]=(x^3)+(y^4)-6 x -2(y^2)

a) The critical points are given by

cp=Solve[{D[f[x,y],x]==0,D[f[x,y],y]==0}]

b)

Clear[fxx,disc]
fxx[x_,y_]=D[f[x,y],{x,2}]
disc[x_,y_]=D[f[x,y],{x,2}]*D[f[x,y],{y,2}]-(((D[D[f[x,y],x],y]))^2)

TableForm[Table[{ cp[[k,2,2]],   cp[[k,1,2]] ,  disc[cp[[k,2,2]],cp[[k,1,2]]], fxx[cp[[k,2,2]],cp[[k,1,2]]],f[cp[[k,2,2]],cp[[k,1,2]]]},{k,1,Length[cp]}],
TableHeadings->{{},{"x ", "y  ",  "  D(x,y) ","  (Subscript[f, xx])  ","f(x,y)"}}]

By the second derivative test we conclude that f has local maximum value of 4(Sqrt[2]) at (-(Sqrt[2]),0), local minimum value of -1-4(Sqrt[2]) at ((Sqrt[2]),-1) and ((Sqrt[2]),1), and saddle points at (-(Sqrt[2]),-1), ((Sqrt[2]),0), and  (-(Sqrt[2]),1).

Here is the graph of f and the relevant points.

Clear[plot1,plot2]
plot1=Plot3D[f[x,y],{x,-2.5,2.5},{y, -2.5, 2.5},PlotStyle-> LightBlue,PlotRange-> 10];
plot2=Graphics3D[{PointSize[Large], Red, Point[Table[{ cp[[k,2,2]],   cp[[k,1,2]] ,  f[cp[[k,2,2]],cp[[k,1,2]]]},{k,1,Length[cp]}]]}, PlotRange->10];
Show[plot1,plot2,ImageSize->{250}]

Example 14.36.  Let f(x,y)=2(x^2)-3x y-x+y+(y^2) and let R be the rectangle in the xy-plane whose vertices are at (0,0), (2,0), (2,2), and  (0,2). 
a) Find all relative extreme values of f inside R.
b) Find the maximum and minimum values of f on R.

Solution:

Clear[f,x,y,disc]
f[x_,y_]=2(x^2)-3x*y-x+y+(y^2)+5

Solve[{(∂_x) f[x,y]==0,(∂_y) f[x,y]==0},{x,y}]

disc[x_,y_]= (∂_(x,x))f[x,y]*(∂_(y,y))f[x,y]-((((∂_(x,y))f[x,y]))^2)

(∂_(x,x))f[x,y]/.{x->1,y->1}
disc[x,y]/.{x->1,y->1}

Thus, (1,1) is the local minimum point of f inside R and its local minimum value is f(1,1)=5. Next, we find the extreme values of f on the boundary of the rectangle. This is done by considering f as a function of one variable corresponding to each side of R.  Let (Subscript[f, 1])=f(x,0), (Subscript[f, 2])=f(x,2), for x between 0 and 2, and (Subscript[f, 3])=f(0,y) and (Subscript[f, 4])=f(2,y), for y between 0 and 2.   We now proceed as follows:

Clear[f1,f2,f3,f4]
f1=f[x,0]
f2=f[x,2]
f3=f[0,y]
f4=f[2,y]

Solve[D[f1,x]==0 ]

Solve[D[f2,x]==0 ]

Solve[D[f3,y]==0 ]

Solve[D[f4,y]==0 ]

Thus, points on the boundary of R that are critical points of f are ((1/4),  0) and ((7/4), 2).  Observe that the points (0, -1/2) and (2,(5/2)) are outside the rectangle R. The four vertices of R at (0,0), (2,0), (0,2) and (2,2) are also critical points.  Can you explain why?  We now evaluate f at each of these points and at (1,1) (the relative minimum point found earlier) using the substitution command and compare the results.

f[x,y]/.{{x->(1/4),y->0},  {x->(7/4),y->2},
		{x->0,y->0},{x->2,y->0},{x->0,y->2},{x->2,y->2},{x->1,y->1}}

Thus, the minimum value of f is 39/8, which occurs at (1/4,0) and also at (7/4,2).  The maximum value of f is 6, which is attained at (2,0) and also at (0,2).  Here is the graph of f over the rectangle R.

Clear[plot1,plot2,plot3]
plot1=Plot3D[{f[x,y],0},{x,0,2},{y,0,2},PlotStyle->{Green,Blue},PlotRange->All];
plot2=Graphics3D[{PointSize[Large], Red , Point[{ {1/4,0,f[1/4,0]},{7/4,2,f[7/4,2]} }]}, PlotRange->All ];
plot3=Graphics3D[{PointSize[Large],Black , Point[{  {2,0,f[2,0]},{0,2,f[2,0]}}]}, PlotRange->All ];
Show[plot1,plot2 ,plot3,ImageSize->{250},ImagePadding->{{15,15},{15,15}}]

Exercises

1. Let f(x,y)=(x^4)-4 x y+2(y^2). 
a. Find all critical points of f.
b. Use the second derivative test to classify the critical points as local minimum, local maximum, saddle point, or neither.
c. Plot the graph of f and the local extreme points and saddle points, if any.

2. Let f(x,y)= (x+y)ln((x^2)+(y^2)), for (x,y)≠(0,0). 
a. Find all critical points of f.
b. Use the second derivative test to classify the critical points as local minimum, local maximum, saddle point, or neither.
c. Plot the graph of f and the local extreme points and saddle points, if any.

3. Let f(x,y)=2(x^2)-3x y-x+y+(y^2) and let R be the rectangle in the xy-plane whose vertices are at (0,0), (2,0), (2,2), and (0,2). 
a. Find all relative extreme values of f inside R.
b. Find the maximum and minimum values of f on  R.
c. Plot the graph of f and the local extreme points and saddle points, if any.

14.8  Lagrange Multipliers

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

Example 14.37.   Let f(x,y)=x y and g(x,y)=(x^2)+(y^2)-4.
a) Plot the level curves of f and g as well as their gradient vectors. 
b) Find the maximum and minimum values of f subject to the constraint g(x,y)=0.

Solution: 
a) We will define f and g and compute their gradients. Recall that we need to evaluate the command Needs["`VectorFieldPlots`"] before we plot the gradient fields.

Clear[f,g,fx,fy,gx,gy,x,y]
f[x_,y_]=2x+3y
g[x_,y_]=(x^2)+(y^2)-4
fx=D[f[x,y],x]
fy=D[f[x,y],y]
gx=D[g[x,y],x]
gy=D[g[x,y],y]

Needs["VectorFieldPlots`"]

Clear[plot1,plot2,plot3,plot4]
plot1=ContourPlot[(x^2)+(y^2)-4,{x,-2,2},{y,-2,2},Frame->False,Axes->True, ContourShading->False,PlotRange->All];
plot2= ContourPlot[2x+3y,{x,-2,2},{y,-2,2},Frame->False,Axes->True, ContourShading->False,PlotRange->All];
plot3=VectorFieldPlot[{fx,fy},{x,-2,2},{y,-2,2},Axes->True,Frame->False, ColorFunction->Hue];
plot4=VectorFieldPlot[{gx,gy},{x,-2,2},{y,-2,2},Axes->True,Frame->False, ColorFunction->Hue];
 Show[plot1, plot2,plot3,plot4,ImageSize->{250}]

b) Let us use l for λ. To solve ∇f=l ∇g we compute

Solve[{fx==  l gx,fy==l gy, g[x,y]==0} ]

Thus, (-(4/(Sqrt[13])),-(6/(Sqrt[13]))) and ((4/(Sqrt[13])),(6/(Sqrt[13]))) are the critical points. We evaluate f at these points to determine the absolute maximum and the absolute minimum of f on the graph of g(x,y)=0.

f[ -(4/(Sqrt[13])),-(6/(Sqrt[13]))]
f[(4/(Sqrt[13])),(6/(Sqrt[13]))]

Hence, f attains its absolute minimum value of -2(Sqrt[13]) at (-(4/(Sqrt[13])),-(6/(Sqrt[13]))) and absolute maximum value of -2(Sqrt[13]) at ((4/(Sqrt[13])),(6/(Sqrt[13]))).

Here is a combined plot of the gradients of f (in black) and g (in red) at the critical points.

Clear[plot1,plot2,plot3, plot4,plot5,plot6]
plot1= ContourPlot[g[x,y],{x,-3,3}, {y, -3,3}, Contours->{0},Frame->False,Axes->True, ContourShading->False];
plot2=ListPlot[{{ -(4/(Sqrt[13])),-(6/(Sqrt[13]))}, {(4/(Sqrt[13])),(6/(Sqrt[13]))}}];

plot3=Graphics[Arrow[{{ -(4/(Sqrt[13])),-(6/(Sqrt[13]))},{ -(4/(Sqrt[13])),-(6/(Sqrt[13]))} +{fx,fy}/.{x->  ((-4)/(Sqrt[13])),y->((-6)/(Sqrt[13]))}  }]];

plot4=Graphics[Arrow[{ {(4/(Sqrt[13])),(6/(Sqrt[13]))} ,{(4/(Sqrt[13])),(6/(Sqrt[13]))}+{fx,fy}/.{x->  (4/(Sqrt[13])),y->(6/(Sqrt[13]))}  }]];

plot5=Graphics[{Red,Arrow[{{ -(4/(Sqrt[13])),-(6/(Sqrt[13]))} ,{ -(4/(Sqrt[13])),-(6/(Sqrt[13]))}+ {gx,gy}/.{x->  ((-4)/(Sqrt[13])),y->((-6)/(Sqrt[13]))} }]}];

plot6=Graphics[{Red,Arrow[{ {(4/(Sqrt[13])),(6/(Sqrt[13]))} ,{(4/(Sqrt[13])),(6/(Sqrt[13]))}+{gx,gy}/.{x->  (4/(Sqrt[13])),y->(6/(Sqrt[13]))} }]}];

Show[plot1,plot2,plot3,plot4, plot5,plot6,PlotRange->All,AspectRatio->Automatic,ImageSize->{250}]

Exercises

1.  Let f(x,y)=4(x^2)+9(y^2) and g(x,y)=x y-4.
a. Plot the level curves of f and g as well as their gradient vectors. 
b. Find the maximum and minimum values of f subject to g(x,y)=0.

2.  Find the maximum and minimum values of f(x,y,z)=(x^3)-3(y^2)+4z subject to the constraint g(x,y,z)=x +y z-4=0.

3.  Find the maximum area of a rectangle that can be inscribed in the ellipse ((x^2)/(a^2))+((y^2)/(b^2))=1.

4.  Find the maximum volume of a box that can be inscribed in the sphere (x^2)+(y^2)+(z^2)=4.

Chapter 15	Multiple Integration

Useful Tip: If you are reading the electronic version of this publication formatted as a Mathematica Notebook, then it is possible to view 3-D plots generated by Mathematica from different perspectives.  First, place your screen cursor over the plot.  Then drag the mouse while pressing down on the left mouse button to rotate the plot.

15.1  Double Integral over a Rectangle

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

Integration can be generalized to functions of two or more variables.  As the integral of a single-variable function defines area of a plane region under the curve, it is natural to consider a double integral of a two-variable function that defines volume of a solid under a surface.  This definition can be made precise in terms of double Riemann sums where rectangular columns (as opposed to rectangles) are used as building blocks to approximate volume (as opposed to area).  The exact volume is then obtained as a limit where the number of columns increases without bound.

15.1.1  Double Integrals and Riemann Sums

Let f(x,y) be a function of two variables defined on a rectangular domain R=[a,b]×[c,d] in (ℝ^2).  Let P={a=(Subscript[x, 0])<(Subscript[x, 1])<...<(Subscript[x, m])=b,c=(Subscript[y, 0])<(Subscript[y, 1])<...<(Subscript[y, n])=d} be an arbitrary partition of R into a grid of m·n rectangles, where m and n are integers.  For each sub-rectangle (Subscript[R, ij])=[(Subscript[x, i-1]),(Subscript[x, i])]×[(Subscript[y, j-1]),(Subscript[y, j])] denote by (Subscript[ΔA, ij]) its area and choose an arbitrary base point ((Subscript[x, ij]),(Subscript[y, ij]))∈(Subscript[R, ij]), where (Subscript[x, ij])∈[(Subscript[x, i-1]),(Subscript[x, i])] and (Subscript[y, ij])∈[(Subscript[y, j-1]),(Subscript[y, j])].  The product f((Subscript[x, ij]),(Subscript[y, ij]))(Subscript[ΔA, ij]) represents the volume of the ij-rectangular column situated between the surface and the xy-plane.  We then define the double Riemann sum (Subscript[S, p]) of f(x,y) on R with respect to P to be the total volume of all these columns:

(Subscript[S, P])=(∑_(i=1)^m)(∑_(j=1)^n)f((Subscript[x, ij]),(Subscript[y, ij]))(Subscript[ΔA, ij])

Define ||P|| to be the maximum dimension of all the sub-rectangles.  The double integral of f(x,y) on the rectangle R is then defined as the limit of (Subscript[S, P]) as ||P||->0:

∫(∫_R)f(x,y)dA=(lim_(||P||->0))(∑_(i=1)^m)(∑_(j=1)^n)f((Subscript[x, ij]),(Subscript[y, ij]))(Subscript[ΔA, ij])

If the limit exists regardless of the choice of partition and base points, then the double integral is said to exist.  Otherwise, the double integral does not exist.

MIDPOINT RULE (Uniform Partitions): Let us consider uniform partitions P, where the points {(Subscript[x, i])} and {(Subscript[y, j])} are evenly spaced, that is,  (Subscript[x, i])=a+i Δ x, (Subscript[y, j])=b+j Δ y for i=0,1,...,m and j=0,1,...,n, and with Δx=(b-a)/m and Δy=(d-c)/n.  Then the corresponding double Riemann sum is

(Subscript[S, m,n])=(∑_(i=1)^m)(∑_(j=1)^n)f((Subscript[x, ij]),(Subscript[y, ij]))Δ x Δ y

Here is a subroutine called MDOUBLERSUM that calculates the double Riemann sum (Subscript[S, m,n]) of f(x,y) over a rectangle R for uniform partitions using the center midpoint of each sub-rectangle as base point, that is, (Subscript[x, ij])=((Subscript[x, i-1])+(Subscript[x, i]))/2=a+(i-1/2)Δ x and (Subscript[y, ij])=((Subscript[y, j-1])+(Subscript[y, j]))/2=c+(j-1/2)Δ y.

Clear[f]
MDOUBLERSUM[a_,b_,c_,d_,m_,n_]:=Sum[f[a+(i-1/2)*(b-a)/m,c+(j-1/2)*(d-c)/n]*(b-a)/m*(d-c)/n,{i,1,m},{j,1,n}]

Example 15.1.  Approximate the volume of the solid bounded below the surface f(x)=(x^2)+(y^2) and above the rectangle R=[-1,1]×[-1,1] on the xy-plane using a uniform partition with m=10 and n=10 and center midpoints as base points.  Then experiment with larger values of m and n and conjecture an answer for the exact volume.

Solution: We calculate the approximate volume for m=10 and n=10 using the subroutine MDOUBLERSUM:

f[x_,y_]=x^2+y^2;
MDOUBLERSUM[-1,1,-1,1,10,10]

N[%]

Table[MDOUBLERSUM[-1,1,-1,1,10*k,10*k],{k,1,10}]

N[%]

It appears that the exact volume is 8/3.  To prove this, we evaluate the double Riemann sum (Subscript[S, m,n]) in the limit as m,n->∞:

Clear[S,m,n];
S[m_,n_]=Simplify[MDOUBLERSUM[-1,1,-1,1,m,n]]

Limit[Limit[S[m,n],m->Infinity],n->Infinity]

To see this limiting process visually, evaluate the following subroutine, called DOUBLEMIDPT, which plots the surface of the function corresponding to the double integral along with the rectangular columns defined by the double Riemann sum considered in the previous subroutine MDOUBLERSUM.

Clear[f];
DOUBLEMIDPT[f_,{a_,b_,m_},{c_,d_,n_}]:=Module[
{dx,dy, i,j, xstar,ystar,mrect, plot},
dx=N[(b-a)/m];
xstar=Table[a+i* dx, {i,0,m}]; 
dy=N[(d-c)/n];
ystar=Table[c+j* dy, {j,0,n}]; 
mcolumn=Table[Cuboid[{xstar[[i]],ystar[[j]],0}, {xstar[[i+1]],ystar[[j+1]],f[(xstar[[i]]+xstar[[i+1]])/2,(ystar[[j]]+ystar[[j+1]])/2]}],{i,1,m},{j,1,n}];
plot=Plot3D[f[x,y],{x,a,b},{y,c,d},Filling ->Bottom];
Show[plot,Graphics3D[mcolumn],ImageSize->{300}]]

f[x_,y_]:=(x^2)+y^2;
DOUBLEMIDPT[f,{-1,1,10},{-1,1,10}]

Here is an animation that demonstrates how the volume of the rectangular columns approach that of the solid in the limit as m,n->∞:

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[DOUBLEMIDPT[f,{-1,1,a},{-1,1,a}] ,{a,5,50,5 }]

15.1.2  Double Integrals and Iterated Integrals in Mathematica

The Mathematica command for evaluating double integrals is the same as that for evaluating integrals of a single-variable function, except that two limits of integration must be specified, one for each independent variable.  Thus:

Integrate[f[x,y],{x,a,c},{y,c,d}] analytically evaluates the double integral ∫(∫_R)f(x,y)dA over the rectangle R=[a,b]×[c,d].

NIntegrate[f[x,y],{x,a,c},{y,c,d}] numerically evaluates the double integral ∫(∫_R)f(x,y)dA over the rectangle R=[a,b]×[c,d].

Iterated Integrals: In practice, one does not actually use the limit definition in terms of Riemann sums to evaluate double integrals, but instead apply Fubini's Theorem to easily compute them in terms of iterated integrals:

Fubini's Theorem: (Rectangular Domains) If R={(x,y):a≤x≤b,c≤y≤d}, then

∫(∫_R)f(x,y)dA=(∫_a^b)(∫_c^d)f(x,y)dydx=(∫_c^d)(∫_a^b)f(x,y)dxdy

Thus, Mathematica will naturally apply Fubini's Theorem whenever possible to analytically determine the answer.  Depending on the form of the double integral, Mathematica may resort to more sophisticated integration techniques, such as contour integration, which are beyond the scope of this text.

Example 15.2.  Calculate the volume of the solid bounded below by the surface f(x)=(x^2)+(y^2) and above the rectangle R=[-1,1]×[-1,1].

Solution: The volume of the solid is given by the double integral ∫(∫_R)f(x,y)dA.  To evaluate it, we use the Integrate command:

f[x_,y_]:=x^2+y^2;
Integrate[f[x,y],{x,-1,1},{y,-1,1}]

This confirms the conjecture that we made in the previous example for the exact volume.

NOTE: Observe that we obtain the same answer by explicitly computing this double integral as an integrated integral as follows.  Moreover, for rectangular domains, the order of integration does not matter.

Integrate[Integrate[f[x,y],{x,-1,1}],{y,-1,1}]
Integrate[Integrate[f[x,y],{y,-1,1}],{x,-1,1}]

Example 15.3.  Compute the double integral ∫(∫_R)x (e^(-(y^2)))dA on the rectangle R=[0,1]×[0,1].

Solution: Observe that the Integrate command here gives us an answer in terms of the non-elementary error function Erf:

Integrate[x*E^(-y^2),{x,0,1},{y,0,1}]

This is because the function f(x,y)=x (e^(-(y^2))) has no elementary anti-derivative with respect to y due to the Gaussian factor (e^(-(y^2))) (bell curve).  Thus, we instead use the NIntegrate Command to numerically approximate the double integral:

NIntegrate[x*E^(-y^2),{x,0,1},{y,0,1}]

Exercises

1. Consider the function f(x,y)=16-(x^2)-(y^2) defined over the rectangle R=[0,2]×[-1,3].
a. Use the subroutine MDOUBLERSUM to compute the double Riemann sum (Subscript[S, m,n]) of f(x,y) over R for m=2 and n=2.
b. Repeat part a) by generating a table of double Riemann sums for m=10k and n=10k where k=1,2,...,10.  Make a conjecture for the exact value of ∫(∫_R)f(x,y)dA. 
c. Find a formula for (Subscript[S, m,n]) in terms of m and n.  Verify your conjecture in part b) by evaluating (lim_(m,n->∞))(Subscript[S, m,n]).
d. Directly compute ∫(∫_R)f(x,y)dA using the Integrate command.

2. Repeat Exercise 1 but with f(x,y)=(1+x)(1+y)(1+x y) defined over the rectangle R=[0,1]×[0,1].

3. Evaluate the double integral ∫∫(Sqrt[(x^4)+(y^4)])dA over the rectangle R=[-2,1]×[-1,2] using both the Integrate and NIntegrate commands.  How do the two answers compare?

4. Calculate the volume of the solid lying under the surface z=(e^(-y))(x+(y^2)) and over the rectangle R=[0,2]×[0,3].  Then make a plot of this solid.

5. Repeat Exercise 4 but with z=sin((x^2)+(y^2)) and rectangle R=[-(Sqrt[π]),(Sqrt[π])]×[-(Sqrt[π]),(Sqrt[π])].

6. Evaluate the double integral ∫(∫_R)f(x,y)dA where f(x,y)=x y cos((x^2)+(y^2)) and R=[-π,π]×[-π,π].  Does your answer make sense?  Make a plot of the solid corresponding to this double integral to intuitively explain your answer.  HINT: Consider symmetry.

7. Find the volume of solid bounded between the two hyperbolic paraboloids (saddles) z=1+(x^2)-(y^2) and z=3-(x^2)+(y^2) over the rectangle R = [-1,1]×[-1,1].

8. Find the volume of the solid bounded by the planes z=2x, z=-3x+2, y=0, y=1, and z=0.

15.2  Double Integral over More General Regions

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

For domains of integration that are non-rectangular but still simple, that is, bounded between two curves, Fubini's Theorem continues to hold.  There are two types to consider:

Fubini's Theorem: (Simple Domains)

Type I (Vertically Simple): If D={(x,y):a≤x≤b,α(x)≤y≤β(x)}, then

∫(∫_D)f(x,y)dA=(∫_a^b)(∫_(α(x))^(β(x)))f(x,y)dydx

The corresponding Mathematica command is Integrate[f[x,y],{x,a,b},{y,α[x],β[x]}].

Type II (Horizontally Simple): If D={(x,y):c≤y≤d,α(y)≤x≤β(y)}, then

∫(∫_D)f(x,y)dA=(∫_c^d)(∫_(α(y))^(β(y)))f(x,y)dxdy

The corresponding Mathematica command is Integrate[f[x,y],{y,c,d},{x,α[y],β[y]}].

Warning: Be careful not to reverse the order of integration prescribed for either type.  For example, evaluating the command Integrate[f[x,y],{y,α[x],β[x]},{x,a,b}] for Type I (x and y are reversed) will lead to incorrect results.

Example 15.4.  Calculate the volume of the solid bounded below by the surface f(x,y)=1-(x^2)+(y^2) and above the domain D bounded by x=0, x=1, y=x, and y=1+(x^2).

Solution: We observe that x=0 and x=1 represent the left and right boundaries, respectively, of D.  Therefore, we plot the graphs of the other two equations along the x-interval [0,2] to visualize D (shaded in the following plot):

Clear[x,y]
plot1=Plot[{x,1+x^2},{x,0,1},Filling->{1->{2}},ImageSize->250]

Here is a plot of the corresponding solid situated over D:

f[x_,y_]=1-x^2+y^2;
plot3=Plot3D[f[x,y],{x,0,1},{y,x,1+x^2},Filling->Bottom,ViewPoint->{1,1,1},PlotRange->{0,4},ImageSize->{250}]

To compute the volume of this solid given by ∫(∫_D)f(x,y)dA, we describe D as a vertically simple domain where 0≤x≤1 and x≤y≤1+(x^2) and apply Fubini's Theorem to evaluate the corresponding iterated integral (∫_0^1)(∫_x^(1+(x^2)))f(x,y)dydx (remember to use the correct order of integration):

Integrate[f[x,y],{x,0,1},{y,x,1+(x^2)}]

Example 15.5.  Evaluate the double integral ∫(∫_D)sin ((y^2))dA, where D is the domain bounded by x=0, y=2, and y=x.

Solution: We first plot the graphs of  x=0, y=2, and y=x to visualize the domain D:

plot1=ContourPlot[{x==0,y==2,y==x},{x,-0.5,2.5},{y,-0.5,2.5},ImageSize->{250}]

It follows that D is the triangular region bounded by these graphs, which we shade in the following plot to make clear:

plot2=Plot[x,{x,0,2},Filling->2];
Show[plot1,plot2,ImageSize->{250}]

To compute the given double integral, we describe D as a horizontally simple domain, where 0≤y≤2 and 0≤x≤y and apply Fubini's Theorem to evaluate the corresponding iterated integral (∫_0^2)(∫_0^y)sin((y^2))dxdy (again, remember to use the correct order of integration):

Integrate[Sin[y^2],{y,0,2},{x,0,y}]

N[%]

NOTE: It is also possible to view D as a vertically simple domain, where 0≤x≤2 and x≤y≤2.  The corresponding iterated integral (∫_0^2)(∫_x^2)sin((y^2))dydx gives the same answer, as it should by Fubini's Theorem:

Integrate[Sin[y^2],{x,0,2},{y,x,2}]

Observe that it is actually impossible to evaluate this iterated integral by hand since there is no elementary formula for the anti-derivative of sin((y^2)) with respect to y.  Thus, if necessary, Mathematica automatically switches the order of integration by converting from one type to the other.

Exercises

In Exercises 1 through 4, evaluate the given iterated integrals and plot the solid corresponding to each one.
1. (∫_0^1)(∫_0^(x^2))(4-(x^2)+(y^2))dydx		2. (∫_0^4)(∫_0^(Sqrt[2-(y^2)]))(x^2) ydxdy
3. (∫_0^π)(∫_0^(sin θ))(r^2)cosθdrdθ		4. (∫_0^1)(∫_0^x)(y/(1+x y))dydx

In Exercises 5 through 8, evaluate the given double integrals and plot the solid corresponding to each one.
5. ∫(∫_D)(x+y)dA,  D={(x,y):0≤x≤3,0≤y≤(Sqrt[x])}
6. ∫(∫_D)(Sqrt[x+y])dA,  D={(x,y):0≤x≤1-(y^2),0≤y≤1}
7. ∫(∫_D)(e^(x+y))dA, where D={(x,y):(x^2)+(y^2)≤4}
8. ∫(∫_D)(y/(x+1))dA, where D is the following shaded diamond region:

In Exercises 9 through 12, calculate the volume of the given solid S:
9. S is bounded under the paraboloid z=16-(x^2)-(y^2) and above the region bounded between the line y=x and the parabola y=6-(x^2).
10. S is bounded under the right circular cone z=(Sqrt[(x^2)+(y^2)]) and above the disk (x^2)+(y^2)≤1.
11. S is bounbed between the plane z=5+2x+2y and the paraboloid z=12-(x^2)-(y^2).  HINT: Equate the two surfaces to obtain the equation of the domain.

12. S is bounded between the cylinders (x^2)+(y^2)=1 and (y^2)+(z^2)=1.

15.3  Triple Integrals

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

Once the notion of a double integral is well established, it is straightforward to generalize it to triple (and even higher-order) integrals for functions of three variables defined over a solid region in space.  Here is the definition of a triple integral in terms of triple Riemann sums for a function f(x,y,z) defined on a box region B={(x,y,z):a≤x≤b,c≤y≤d,p≤z≤q} (refer to your calculus text for details):

∫∫(∫_B)f(x,y)dV=(lim_(||P||->∞))(∑_(i=1)^m)(∑_(j=1)^n)(∑_(k=1)^p)f((Subscript[x, ijk]),(Subscript[y, ijk]))(Subscript[ΔV, ijk])

where the notation is analogous to that used for double integrals in Section 15.1 of this text.  Of course, Fubini's Theorem also generalizes to triple integrals:

Fubini's Theorem: (Box Domains) If B={(x,y,z):a≤x≤b,c≤y≤d,p≤z≤q}, then

∫∫(∫_B)f(x,y)dV=(∫_a^b)(∫_c^d)(∫_p^q)f(x,y)dzdydx

The corresponding Mathematica commands are:

Integrate[f[x,y,z],{x,a,c},{y,c,d},{z,e,f}] analytically evaluates the triple integral ∫∫(∫_B)f(x,y)dV over the box B=[a,b]×[c,d]×[e,f].

NIntegrate[f[x,y],{x,a,c},{y,c,d},{z,e,f}] numerically evaluates the triple integral ∫∫(∫_B)f(x,y)dV over the rectangle B=[a,b]×[c,d]×[e,f].

NOTE: For box domains, the order of integration does not matter so that it is possible to write five other versions of triple iterated integrals besides the one given in Fubini's Theorem.

Example 15.6.  Calculate the triple integral  ∫∫(∫_B)x y zdV over the box B=[0,1]×[2,3]×[4,5].

Solution: We use the Integrate command to calculate the given triple integral.

Integrate[x y z,{x,0,1},{y,2,3},{z,4,5}]

Volume as Triple Integral: Recall that if a solid region W is bounded between two surfaces ψ(x,y) and ϕ(x,y), where both are defined on the same domain D with ψ(x,y)≤ϕ(x,y), then its volume V can be expressed by the triple integral

V=∫∫(∫_W)1dV=∫(∫_D)(∫_(ψ(x,y))^(ϕ(x,y)))1dzdA

Example 15.7.  Calculate the volume of the solid bounded between the surfaces z=4(x^2)+4(y^2) and z=16-4(x^2)-4(y^2) on the rectangular domain [-1,1]×[-1,1].

Solution: Here is a plot of the solid:

Plot3D[{4x^2+4y^2,16-4x^2-4y^2},{x,-1,1},{y,-1,1},Filling ->{1->8,2->8},ImageSize->{250},ImagePadding->{{15,15},{15,15}}]

The volume of the solid is given by the triple iterated integral (∫_(-1)^1)(∫_(-1)^1)(∫_(4(x^2)+4(y^2))^(16-4(x^2)-4(y^2)))1dzdydx:

Integrate[1,{x,0,1},{y,-1,0},{z,4x^2+4y^2,16-4x^2-y^2}]

Exercises

In Exercises 1 through 4, evaluate the given iterated integrals:
1. (∫_0^1)(∫_0^x)(∫_0^(y^2))(x+y+z)dzdydx		2. (∫_0^3)(∫_0^(sin y))(∫_0^(y +z))x y zdxdzdy 
3. (∫_0^π)(∫_0^θ)(∫_0^(r cos θ))r (z^2)dzdrdθ			4. (∫_0^1)(∫_(Sqrt[x])^1)(∫_0^(1-y))z log(1+x y)dzdydx

In Exercises 5 through 8, evaluate the given triple integrals:
5. ∫∫(∫_W)(x+y z)dV, where W={(x,y,z):0≤x≤1,0≤y≤(Sqrt[x]),0≤z≤(y^2)}.
6. ∫∫(∫_W)sin ydV, where W lies under the plane z=1+x+y and above the triangular region bounded by x=0, x=2, and y=3x. 
7. ∫∫(∫_W)zdV, where W is bounded by the paraboloid z=4-(x^2)-(y^2) and z=0.
8. ∫∫(∫_W)f(x,y,z)dV, where f(x,y,z)=(z^2) and W is bounded between the cone z=(Sqrt[(x^2)+(y^2)]) and z=9.

9. The triple integral (∫_0^1)(∫_(x/2)^(1-x/2))(∫_0^(2-x-2y))dzdydx represents the volume of a solid S.  Evaluate this integral.  Then make a plot of S and describe it.

10. Midpoint Rule for Triple Integrals:
a. Develop a subroutine called MTRIPLERSUM to compute the triple Riemann sum of the triple integral ∫∫(∫_B)f(x,y,z)dV over the box domain B={(x,y,z):a≤x≤b,c≤y≤d,p≤z≤q} for uniform partitions and using the center midpoint of each sub-box as base point.  HINT: Modify the subroutine MDOUBLERSUM in Section 15.1 of this text.

b. Use your subroutine MTRIPLESUM in part a) to compute the triple Riemann sum of ∫∫(∫_B)((((x^2)+(y^2)+(z^2)))^(3/2))dV over the box B={(x,y,z):0≤x≤1,0≤y≤2,0≤z≤3} by dividing B into 48 equal sub-boxes, that is, cubes having side length of 1/2.

c. Repeat part b) by dividing B into cubes having side length of 1/4 and more generally into cubes having side length of 1/(2^n) for n sufficiently large in order to obtain an approximation accurate to 2 decimal places.

d. Verify your answer in part c) using Mathematica's NIntegrate command.

15.4  Integration in Polar, Cylindrical, and Spherical Coordinates

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

15.4.1  Double Integrals in Polar Coordinates

The following Change of Variables Formula converts a double integral in rectangular coordinates to one in polar coordinates:

Change of Variables Formula (Polar Coordinates):

I. Polar Rectangles: If R={(r,θ):(Subscript[θ, 1])≤θ≤(Subscript[θ, 2]),(Subscript[r, 1])≤r≤(Subscript[r, 2])}, then

∫(∫_R)f(x,y)dA=(∫_(Subscript[θ, 1])^(Subscript[θ, 2]))(∫_(Subscript[r, 1])^(Subscript[r, 2]))f(r cos θ,r sin θ)rdrdθ

II. Polar Regions: If D={(r,θ):(Subscript[θ, 1])≤θ≤(Subscript[θ, 2]),α(θ)≤r≤β(θ)}, then

∫(∫_D)f(x,y)dA=(∫_(Subscript[θ, 1])^(Subscript[θ, 2]))(∫_(α(θ))^(β(θ)))f(r cos θ,r sin θ)rdrdθ

Example 15.8.  Calculate the volume of the solid region bounded by the paraboloid f(x)=4-(x^2)-(y^2) and the xy-plane using polar coordinates.

Solution: We first plot the paraboloid:

f[x_,y_]=4-x^2-y^2
Plot3D[f[x,y],{x,-2,2},{y,-2,2},PlotRange->{0,4},ImageSize->{250}]

The circular domain D can be easily described in polar coordinates by the polar rectangle R={(r,θ):0≤r≤2,0≤θ≤2π}.  Thus, the volume of the solid is given by the corresponding double integral (∫_0^(2π))(∫_0^2)f(r cos θ,r sin θ)rdrdθ in polar coordinates:

Clear[r,θ];
Integrate[r*f[r*Cos[θ],r*Sin[θ]],{r,0,2},{θ,0,2Pi}]

Observe that here f(x,y) simplifies nicely in polar coordinates:

f[r*Cos[θ],r*Sin[θ]]
Simplify[%]

NOTE: Evaluating the same double integral in rectangular coordinates by hand would be quite tedious.  This is not a problem with Mathematica, however:

Integrate[f[x,y],{x,-2,2},{y,-Sqrt[4-x^2],Sqrt[4-x^2]}]

15.4.2  Triple Integrals in Cylindrical Coordinates

The following Change of Variables Formula converts a triple integral in rectangular coordinates to one in cylindrical coordinates:

Change of Variables Formula (Cylindrical Coordinates): If a solid region W is described by (Subscript[θ, 1])≤θ≤(Subscript[θ, 2]), α(θ)≤r≤β(θ), and (Subscript[z, 1])(r,θ)≤z≤(Subscript[z, 2])(r,θ), then

∫∫(∫_W)f(x,y,z)dV=(∫_(Subscript[θ, 1])^(Subscript[θ, 2]))(∫_(α(θ))^(β(θ)))(∫_((Subscript[z, 1])(r,θ))^((Subscript[z, 2])(r,θ)))f(r cos θ,r sin θ,z)rdzdrdθ

Example 15.9.  Use cylindrical coordinates to calculate the triple integral ∫∫(∫_W) zdV, where W is the solid region bounded above by the plane z=8-x-y, below by the paraboloid z=4-(x^2)-(y^2), and inside the cylinder (x^2)+(y^2)=4.

Solution: Since W lies inside the cylinder (x^2)+(y^2)=4, this implies that it has a circular base on the xy-plane given by the same equation, which can be described in polar coordinates by 0≤θ≤2π and 0≤r≤2.  Here is a plot of all three surfaces (plane, paraboloid, and cylinder):

plotplane=Plot3D[8-x-y,{x,-2,2},{y,-2,2}];
plotparaboloid=Plot3D[4-x^2-y^2,{x,-2,2},{y,-2,2}];
plotcylinder=ParametricPlot3D[{2*Cos[θ],2*Sin[θ],z},{θ,0,2π},{z,0,12}];
Show[plotplane,plotparaboloid,plotcylinder,PlotRange->All,ImageSize->{250}]

Since W is bounded in z by 4-(x^2)-(y^2)≤z≤8-x-y, or in cylindrical coordinates,  4-r cos θ-r sin θ≤z≤4-(r^2), it follows that the given triple integral transforms to

(∫_0^(2π))(∫_0^2)(∫_(4-(r^2))^(4-r cos θ-r sin θ))z rdzdrdθ

Evaluating this integral in Mathematica yields the answer

Integrate[z*r,{θ,0,2π},{r,0,2},{z,4-r*Cos[θ]-r*Sin[θ],8+r*Cos[θ]+r*Sin[θ]}]

15.4.3  Triple Integrals in Spherical Coordinates

The following Change of Variables Formula converts a triple integral in rectangular coordinates to one in spherical coordinates:

Change of Variables Formula (Spherical Coordinates): If a solid region W is described by (Subscript[θ, 1])≤θ≤(Subscript[θ, 2]), (Subscript[ϕ, 1])≤ϕ≤(Subscript[ϕ, 2]), and (Subscript[ρ, 1])(θ,ϕ)≤ρ≤(Subscript[ρ, 2])(θ,ϕ), then

∫∫(∫_W)f(x,y,z)dV=(∫_(Subscript[θ, 1])^(Subscript[θ, 2]))(∫_(Subscript[ϕ, 1])^(Subscript[ϕ, 2]))(∫_((Subscript[ρ, 1])(θ,ϕ))^((Subscript[ρ, 2])(θ,ϕ)))f(ρ cos θ sin ϕ,ρ sin θ sin ϕ,ρ cos ϕ)(ρ^2)sinϕdρdϕdθ

Example 15.10.  Use spherical coordinates to calculate the volume of the solid W lying inside the sphere (x^2)+(y^2)+(z^2)=z and above the cone z=(Sqrt[(x^2)+(y^2)]).

Solution: In spherical coordinates, the equation of the sphere is given by

((ρ )^2)=ρ  cos ϕ

or equivalently, ρ=cos ϕ.  Similarly, the equation of the cone transforms to

ρ cos ϕ=(Sqrt[(((ρ cos θ sin ϕ))^2)+(((ρ sin θ sin ϕ))^2)])=ρ  sin ϕ

It follows that cos ϕ=sin ϕ, or ϕ=π/4.  Therefore, the cone makes an angle of 45 degrees with respect to the z-axis, as shown in the following plot along with the top half of the sphere:

Clear[ρ]
plotcone=ParametricPlot3D[{ρ Cos[θ] Sin[Pi/4],ρ Sin[θ] Sin[Pi/4],ρ Cos[Pi/4]},{θ,0,2Pi},{ρ,0,Sqrt[2]/2}];
plotsphere=ParametricPlot3D[{Cos[ϕ] Cos[θ] Sin[ϕ],Cos[ϕ] Sin[θ] Sin[ϕ],Cos[ϕ] Cos[ϕ]},{θ,0,2Pi},{ϕ,0,Pi/4}];
Show[plotcone,plotsphere,PlotRange->All,ViewPoint->{1,1,1/4},ImageSize->{250}]

It is now clear that the solid W is described by 0≤θ≤2π, 0≤ϕ≤π/4, and 0≤ρ≤cos ϕ.  Thus, its volume is given by the triple integral

(∫_0^(2π))(∫_0^(π/4))(∫_0^(cos ϕ))(ρ^2)sin ϕdρdϕdθ

which in Mathematica evaluates to

Integrate[ρ^2*Sin[ϕ],{θ,0,2Pi},{ϕ,0,Pi/4},{ρ,0,Cos[ϕ]}]

Exercises

In Exercises 1 through 4, evaluate the given double integral by converting to polar coordinates:
1. (∫_(-1)^1)(∫_(-(Sqrt[1-(x^2)]))^(Sqrt[1-(x^2)]))(1-(x^2)-(y^2))dydx			2. (∫_0^2)(∫_0^(Sqrt[4-(x^2)]))(e^(-((x^2)+(y^2))))dydx
3. ∫(∫_D)x log ydA, where D is the annulus (donut-shaped region) with inner radius 1 and outer radius 3.
4. ∫(∫_D)arctan(y/x)dA, where D is the region inside the cardioid r=1+cos t.

5. Use polar coordinates to calculate the volume of the solid that lies below the paraboloid z=(x^2)+(y^2) and inside the cylinder (x^2)+(y^2)=2y.

6. Evaluate the triple integral (∫_0^2)(∫_0^(Sqrt[4-(x^2)]))(∫_0^(Sqrt[4-(x^2)-(y^2)]))((x^2)+(y^2))dzdydx by converting to cylindrical coordinates.

7. Use cylindrical coordinates to calculate the triple integral ∫∫(∫_W)((x^2)+((y )^2))dV, where W is the solid bounded between the two paraboloids z=(x^2)+(y^2) and z=8-(x^2)-(y^2).

8. Evaluate the triple integral (∫_(-2)^2)(∫_(-(Sqrt[4-(x^2)]))^(Sqrt[4-(x^2)]))(∫_(Sqrt[(x^2)+(y^2)])^(Sqrt[4-(x^2)-(y^2)]))((x^2)+(y^2)+(z^2))dzdydx by converting to spherical coordinates.

9. The solid defined by the spherical equation ρ=sin ϕ is called the torus.
a. Plot the torus.
b. Calculate the volume of the torus.

10. Ice-Cream Cone: A solid W in the shape of an ice-cream cone is bounded below by the cylinder z=(Sqrt[(x^2)+(y^2)]) and above by the sphere (x^2)+(y^2)+(z^2)=8.  Plot W and determine its volume.

15.5  Applications of Multiple Integrals

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

Mass as Double Integral: Consider a lamina (thin plate) D in  (ℝ^2) with continous mass density ρ(x,y).  Then the mass of D is given by the double integral

M=∫(∫_D)ρ(x,y)dA

where the domain of integration is given by the region that describes the lamina D.

Example 15.11.  Calculate the mass of the lamina D bounded between the parabola y=(x^2) and y=4 with density ρ(x,y)=y.

Solution: Here is a plot of the lamina D (shaded):

Plot[{x^2,4},{x,-2,2},ImageSize->{250},Filling->{2->{1}}]

We can view D as a Type I region described by -2≤x≤2 and (x^2)≤y≤4.  Thus. the mass of the lamina is given by the double integral:

Integrate[y,{x,-2,2},{y,x^2,4}]

NOTE: Mass of a lamina can also be interpreted as the volune of the solid bounded by its density function over D as shown in the following plot:

Plot3D[y,{x,-2,2},{y,0,4},RegionFunction->(#1^2<#2<4&),Filling->Bottom,Mesh->None,ImageSize->250]

Example 15.12.  Suppose a circular metal plate D, bounded by  (x^2)+(y^2)=9, has electrical charge density ρ(x,y)=(Sqrt[9-(x^2)-(y^2)]).  Calculate the total charge of the plate.

Solution: Here is a plot of the metal plate D (shaded):

Integrate[y,{x,-2,2},{y,x^2,4}]

Plot[{Sqrt[9-x^2],-Sqrt[9-x^2]},{x,-3,3},ImageSize->{250},Filling->{2->{1}},AspectRatio->1]

We shall calculate the total charge of the plate using polar coordinates, which will simplify the corresponding double integral.  Since ρ(r,θ)=(Sqrt[9-(r^2)])and D is a simple polar region described by r=3, the total charge is

Integrate[Sqrt[9-r^2]*r,{r,0,3},{theta,0,2Pi}]

Mass as Triple Integral: We can extend the notion of mass to a solid region W in (ℝ^3).  Suppose W is bounded between two surfaces z=ψ(x,y) and z=ϕ(x,y), where both are defined on the same domain D with ψ(x,y)≤ϕ(x,y), and has density ρ(x,y,z).  Then the mass of W can be expressed by the triple integral

M=∫∫(∫_W)ρ(x,y,z)dV=∫(∫_D)(∫_(ψ(x,y))^(ϕ(x,y)))ρ(x,y,z)dzdA

Example 15.13.  Calculate the mass of the solid region W bounded between the planes z=1-x-y and z=1+x+y and situated over the triangular domain D bounded by x=0, y=0, and y=1-x.  Assume the density of W is given by ρ(x,y,z)=1+(x^2)+(y^2).

Solution: Here is a plot of the solid region W:

Plot3D[{1-x-y,1+x+y},{x,0,1},{y,0,1-x},ViewPoint->{1,1,1},Filling->{1->1,2->1},Ticks->{Automatic,Automatic,{1,2}},ImageSize->{250},ImagePadding->{{15,15},{15,15}}]

The mass of the solid is given by the triple iterated integral (∫_0^1)(∫_0^(1-x))(∫_(1-x-y)^(1+x+y))(1+(x^2)+(y^2))dzdydx:

Integrate[1+x^2+y^2,{x,0,1},{y,0,1-x},{z,1-x-y,1+x+y}]

Center of Mass: Given a lamina D in (ℝ^2), its center of mass ((Subscript[x, CM]),(Subscript[y, CM])) (or balance point) is defined as the ratio of its moments (with respect to the coordinate axes) to its mass:

(Subscript[x, CM])=((Subscript[M, y])/M), (Subscript[y, CM])=((Subscript[M, x])/M)

where the moments (Subscript[M, y]) and (Subscript[M, x]) are defined by

(Subscript[M, y])=(1/A)∫(∫_D)x ρ(x,y)dA,    (Subscript[M, x])=(1/A)∫(∫_D)y ρ(x,y)dA

NOTE: In case the lamina has uniform density, that is, ρ(x,y)=1, then the center of mass is the same as the centroid whose coordinates represent averages of the coordinates over the lamina.

Center of mass (and centroid) can be naturally extended to solid objects in (ℝ^3).  Refer to your textbook for further details.

Example 15.14.  Calculate the mass of the solid region W bounded between the planes z=1-x-y and z=1+x+y and situated over the triangular domain D bounded by x=0, y=0, and y=1-x.  Assume the density of W is given by ρ(x,y,z)=1+(x^2)+(y^2).

Exercises

In Exercises 1 and 2, find the mass of the given lamina D.
1. D is bounded between y=sin (π x) and y=0 along the interval [0,1] and has density ρ(x,y)=x(1-x) .
2. D is bounded by the lines y=x+1, y=-2x-2, and x=1 and has density ρ(x,y)=1+(y^2) .

3. Find the center of mass of the lamina D in Exercises 1 and 2.

4. Find the centroid of the lamina in Exercises 1 and 2.  Compare the centroid of each lamina with its center of mass.

In Exercises 5 and 6, find the mass of the given solidi object W.
5. W is the interior of the tetrahedron enclosed by the planes x=0, y=0, z=0, and z=1-x-y and has density ρ(x,y,z)=1-z.
6. W is the ice-cream cone bounded below by the cylinder z=(Sqrt[(x^2)+(y^2)]) and above by the sphere (x^2)+(y^2)+(z^2)=8 and has density ρ(x,y,z)=(z^2).

7. Find the center of mass of the tetrahedron in Exercises 5 and 6.  Refer to your textbook for appropriate formulas.

8. Find the centroid of the tetrahedron in Exercises 5 and 6.  Compare this with its center of mass.  Refer to your textbook for appropriate formulas.

15.6  Change of Variables

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

A change of variables is often useful for simplifying integrals of a single variable (commonly referred to as u-substitution):

(∫_a^b)f(x)dx=(∫_c^d)f(g(u))g'(u)du

where x=g(u), a=g(c), and b=g(d).  This substitution formula allows one to transformation an integral in the variable x to one in a new variable u.  Observe that the interval [c,d] is mapped to interval [a,b] under the function g.

This technique can be extended to double integrals of the form ∫(∫_D)f(x,y)dxdy, where a change of variables is described by a transformation G(u,v)=(x,y), which maps a region (Subscript[D, 0]) in the uv-coordinate plane to the region D in the xy-coordinate plane.

The following Change of Variables Formula converts a double integral from the xy-coordinate system to a new coordinate system defined by u and v:

Change of Variables Formula (Coordinate Transformation): If G(u,v)=(x(u,v),y(u,v)) is a (C^1)-mapping from (Subscript[D, 0]) to D, then

∫(∫_D)f(x,y)dxdy=∫(∫_(Subscript[D, 0]))f(x(u,v),y(u,v))|((∂(x,y))/(∂(u,v)))|dudv

where |((∂(x,y))/(∂(u,v)))|, referred to as the Jacobian of G and also denoted by Jac(G), is given by

Jac(G)=|((∂(x,y))/(∂(u,v)))|=|({{((∂x)/(∂u)), ((∂x)/(∂v))}, {((∂y)/(∂u)), ((∂y)/(∂v))}})|=((∂x)/(∂u))((∂y)/(∂v))-((∂x)/(∂v))((∂y)/(∂u))

The Jacobian relates the area of any infinitesimal region inside (Subscript[D, 0]) with the corresponding region inside D=G((Subscript[D, 0])).  In fact, if G is a linear map, then Jac(G) is constant and is equal in magnitude to the ratio of the areas of D to that of (Subscript[D, 0]):

Jacobian of a Linear Map: If G(u,v)=(A u+C v,B u+D v) is a linear mapping from (Subscript[D, 0]) to D, then Jac(G) is constant with value

Jac(G)=|({{A, C}, {B, D}})|=A D-B C

Moreover,

Area(D)=|Jac(G)|Area((Subscript[D, 0]))

Refer to your textbook for a detailed discussion of transformations of plane regions.

Example 15.12.  Make an appropriate changes of variables to calculate the double integral ∫(∫_D)x ydA, where D is the region bounded by the curves x y=1, x y=2, x (y^2)=1, and x (y^2)=2.

Solution: Here is a plot of the shaded region D bounded by the four given curves:

plot1=ContourPlot[{x*y==1,x*y==2,x*y^2==1,x*y^2==2},{x,0,5},{y,0,5},AspectRatio->Automatic,ImageSize->{250}];
plot2=ContourPlot[1,{x,0,5},{y,0,5},AspectRatio->Automatic,RegionFunction->Function[{x,y},1<x y<2 &&1<x y^2<2],ImageSize->{250},PlotPoints->100];
Show[plot1,plot2]

Observe that D is rather complicated.  Since D can be described by the inequalities 1<x y<2 and 1<x (y^2)<2, we make the natural change of variables u=x y and v=x (y^2), which transforms D to a simple square region (Subscript[D, 0]) in the uv-plane bounded by u=1, u=2, v=1, and v=2:

ContourPlot[1,{u,0,3},{v,0,3},ImageSize->{250},RegionFunction->Function[{u,v},1<u<2 &&1<v<2]]

To find the formula for our transformation G(u,v)=(x(u,v),y(u,v)) that maps (Subscript[D, 0]) to D, we solve for x and y in terms of u and v:

Clear[sol,x,y,u,v]
sol=Solve[{u==x*y,v==x*y^2},{x,y}]

It follows that G(u,v)=((u^2)/v,v/u) and the corresponding Jacobian is

x=sol[[1,1,2]]
y=sol[[1,2,2]]
Jac=D[x,u]*D[y,v]-D[x,v]*D[y,u]

Thus, the given integral transforms to ∫(∫_D)x ydA=∫(∫_(Subscript[D, 0]))(u/v)dA=(∫_1^2)(∫_1^2)(u/v)dvdu with value

Integrate[u/v,{u,1,2},{v,1,2}]

Exercises

1. Consider the transformation G(u,v)=(2u+v,u-3v).
a. Set D=G((Subscript[D, 0])) where (Subscript[D, 0])={0≤u≤1,0≤v≤2}.  Make a plot of D and describe its shape.
b. Compute Jac(G).
c. Compare the area of D with that of (Subscript[D, 0]).  How does this relate to Jac(G)?

2. Compute the area of the ellipse ((x^2)/4)+((y^2)/9)=1 by viewing it as a transformation of the unit circle (u^2)+(v^2)=1 under a linear map G(u,v)=(x(u,v),y(u,v)) and using the area relationship described by Jac(G).

3. Evaluate the integral ∫(∫_D)x ydA, where D is the region in the first quadrant bounded by the equations y=x, y=4x, x y=1, and x y=4.  HINT: Consider the change of variables u=x y and v=y.

4. Evaluate the integral ∫(∫_D)(x+y)/(x-y)dA, where D is the parallelogram bounded by the lines x-y=1, x-y=3, 2x+y=0, and 2x+y=2.  HINT: Consider the change of variables u=x-y and v=2x+y.

5. Evaluate the integral ∫(∫_D)(y/x)dA, where D is the region bounded by the circles (x^2)+(y^2)=1, (x^2)+(y^2)=4 and lines y=x, y=3x.  HINT: Consider the change of variables u=(x^2)+(y^2) and v=y/x.

Chapter 16	Line and Surface Integrals

Useful Tip: If you are reading the electronic version of this publication formatted as a Mathematica Notebook, then it is possible to view 3-D plots generated by Mathematica from different perspectives.  First, place your screen cursor over the plot.  Then drag the mouse while pressing down on the left mouse button to rotate the plot.

16.1  Vector Fields

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

Let (Subscript[F, 1]), (Subscript[F, 2]), and (Subscript[F, 3]) be functions of x, y, and z. The vector-valued function

F(x,y,z)=⟨(Subscript[F, 1])(x,y,z),(Subscript[F, 2])(x,y,z),(Subscript[F, 3])(x,y,z)⟩

is called a vector field. We have already encountered a vector field in the form of the gradient of a function. Other useful examples of vector fields are the gravitational force, the velocity of fluid, magnetic fields, and electric fields.

We use the Mathematica commands VectorFieldPlot and VectorFieldPlot3D to plot the graphs of vector fields.  However, before using these commands, it is advisable to load the VectorFieldPlots package. This is done by evaluating

Needs["VectorFieldPlots`"]

Example 16.1.  Draw the following vector fields.
a) F(x,y)=⟨sin y,cos x⟩ 	b)   F(x,y,z)=⟨y, x+z,2x-y⟩

Solution:
a)

Clear[F,x,y,z]
 F[x_,y_]={Sin[y],Cos[x]}

VectorFieldPlot[F[x,y],{x, -5,5},{y,-4,4},ImageSize->{250} ]

Here is another display of the preceding vector field with some options specified.

VectorFieldPlot[F[x,y],{x, -5,5},{y,-4,4},Axes->True,AxesOrigin ->{0,0},Frame->False,ColorFunction->Hue,ImageSize->{250}]

To see other available options of VectorFieldPlot, evaluate the command Options[VectorFieldPlot].

b) We shall use two of the options of VectorFieldPlot3D, which does not have as many options as VectorFieldPlot. (Again, you can find these by evaluating Options[VectorFieldPlot3D].)

Clear[F,x,y,z]
F[x_,y_,z_]={y (z^2),x (z^2),2 x y z}
VectorFieldPlot3D[F[x,y,z],{x,-3,3},{y,-3,3},{z,-3,3},ColorFunction->Hue,VectorHeads->True,ImageSize->{250}]

Example 16.2.  Draw the unit radial vector fields:
a) F(x,y)=⟨(x/(Sqrt[(x^2)+(y^2)])),(y/(Sqrt[(x^2)+(y^2)]))⟩	b)   F(x,y,z)=⟨(x/(Sqrt[(x^2)+(y^2)+(z^2)])),(y/(Sqrt[(x^2)+(y^2)+(z^2)])),(z/(Sqrt[(x^2)+(y^2)+(z^2)]))⟩

Solution: For convenience, we define both vector fields to be 0 at the origin. We shall use the If command to do so.

a)

Clear[F,x,y]
F[x_,y_]=If[(x^2)+(y^2)≠0,(({x,y})/(Sqrt[(x^2)+(y^2)])),{0,0}]
VectorFieldPlot[F[x,y],{x,-3,3},{y,-3,3},ImageSize->{250}]

b)

Clear[F,x,y,z]
F[x_,y_,z_]=If[(x^2)+(y^2)+(z^2)≠0,(({x,y,z})/(Sqrt[(x^2)+(y^2)+(z^2)])),{0,0,0}]
VectorFieldPlot3D[F[x,y,z],{x,-3,3},{y,-3,3},{z,-3,3},ColorFunction->Hue,VectorHeads->True,ImageSize->{250}]

Exercises

In Exercise 1 through 4, draw the given vector fields.
1.   F(x,y)=⟨ (y^2)-2xy, xy+6(x^2)⟩			2.   F(x,y,z)=⟨sin x,cos y ,xz⟩   
3.   F(x,y)=⟨  -(y/(Sqrt[(x^2)+(y^2)])),(x/(Sqrt[(x^2)+(y^2)]))⟩			4,   F(x,y,z)=⟨ x+cos (xz),y sin (xy),xz cos (yz) ⟩

In Exerices 5 and 6, calculate and plot the gradient vector field for each of the following functions.
5.   f(x,y)=ln(x+(y^2))				 6.  f(x,y,z)=sin x  (cos z/y)

16.2  Line Integrals

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

Suppose C is a smooth curve in space whose parametric equations are given by

x=x(t), y=y(t),  z=z(t)

where a≤t≤b.  Let (Subscript[C, 1]), (Subscript[C, 2]), (Subscript[C, 3]), .... , (Subscript[C, N]) be a partition of the curve C with arc length (Subscript[Δs, 1]), (Subscript[Δs, 2]), (Subscript[Δs, 3]), ...  , (Subscript[Δs, N]) and let (Subscript[P, 1]), (Subscript[P, 2]), (Subscript[P, 3]), ... , (Subscript[P, N]) be points on the subarcs.

If f(x,y,z) is a function that is continuous on the curve C, then the line integral of f is defined by

(∫_C)f(x,y,z)ds=(lim_((Subscript[Δs, i])->0))(∑_(i=1)^N)f((Subscript[P, i]))(Subscript[Δs, i])

NOTE: If c(t)=⟨x(t), y(t),z(t)⟩ is the vector equation of the curve C, then it can be shown (refer to your calculus textbook) that

(∫_C)f(x,y,z)ds=(∫_a^b)f(c(t)‖c'(t)‖dt

In addition, if F(x,y,z)=⟨(Subscript[F, 1]),(Subscript[F, 2]),(Subscript[F, 3])⟩ is a vector field that is continuous on C, then the line integral of F over C is given by

(∫_C)F(x,y,z)·ds=(∫_C)(F·T)ds=(∫_a^b)F(c(t))·c'(t)dt

where T is the unit vector T=((c'(t))/(‖c'(t)‖)) and F·T is the dot product of F and T.

Example 16.3.  Find  (∫_C)f(x,y,z)ds, where f(x,y,z)=x y+(z^2) and C is given by  x= t, y= (t^2), and z=(t^3), for 0≤t≤1.

Solution:

Clear[x,y,z,t,f,c]
f[x_,y_,z_]=((x )^2)y+x z
x[t_]=t
y[t_]=(t^2)
z[t_]=(t^3)
c[t_]={x[t],y[t],z[t]}

(∫_0^1)f[x[t],y[t],z[t]]Norm[c'[t]]\[DifferentialD]t

Here is a numerical approximation of the preceding line integral.

NIntegrate[f[x[t],y[t],z[t]]Norm[c'[t]],{t,0,1}]

Example 16.4.  Find  (∫_C)F(x,y,z)·ds, where F(x,y,z)=⟨ x  z, z (y^2), y (x^2)⟩ and the curve C is given by  x= 2t, y= sin t, and z=cos t, 0≤t≤2π.

Solution:

Clear[x,y,z,t,f,c]
F[x_,y_,z_]={x z,z (y^2), y (x^2)} 
x[t_]=2t 
y[t_]= Sin[t]
z[t_]=Cos[t]
c[t_]={x[t],y[t],z[t]}

(∫_0^(2Pi))F[x[t],y[t],z[t]].c'[t]\[DifferentialD]t

N[%]

Exercises

1.  Find  (∫_C)f(x,y,z)ds, where:
a.  f(x,y,z)= x (y^(2 ))-4 zy and C is given by  x= 2t, y= (t^(2/3)), and z=1-3(t^2), for 0≤t≤1.
b.  f(x,y,z)=(yz/x) and C is given by  x= ln t, y= (t^2), and z=3t, for 3≤t≤5.

2.   Find  (∫_C)F(x,y)·ds, where:
a.   F(x,y)=⟨ (e^(3x-2y)),(e^(2x+3y))⟩ and C is given by  x= 2t, y= sin t,  0≤t≤ π
b.  F(x,y)=⟨(x^2),yx+(y^2)⟩ and C is the unit circle center at the origin.

3.  Find  (∫_C)F(x,y,z)·ds, where:
a.   F(x,y,z)=⟨xyz,-xz,xy ⟩ and C is given by  x= t, y= 2(t^2), z=3t  0≤t≤ 1
b.   F(x,y,z)=⟨(xy^3),z+(x^2),(z^3)⟩ and C is the line segment joining (-1,2,-1) and (1, 3, 4).

16.3  Conservative Vector Fields

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

Let F(x,y,z)=⟨(Subscript[F, 1]),(Subscript[F, 2]),(Subscript[F, 3])⟩ be a vector field. Let (Subscript[C, 1]) and (Subscript[C, 2]) be any two different curves with the same initial point P and end point Q.  We say that the vector field F is path independent if

(Subscript[(∫_C), 1])F(x,y,z)·ds=(Subscript[(∫_C), 2])F(x,y,z)·ds

A vector field that is path independent is called conservative.

NOTE 1: A vector field F is conservative if

(∫_C)F(x,y,z)·ds=0

for every closed curve C.

NOTE 2: If F=∇u is the gradient of a function u=u(x,y,z), then we say that u is the potential of F.  Moreover, if the end points of C are P and Q, we have

(∫_C)F(x,y,z)·ds=u(P)-u(Q)

In particular, if the curve is closed, that is, if P=Q, then

(∫_C)F(x,y,z)·ds=0

Therefore, gradient is conservative. The converse of this statement is true if its domain is an open connected domain.

NOTE 3: Let F=⟨(Subscript[F, 1]),(Subscript[F, 2])⟩.  If F=∇u=⟨((∂ u)/(∂ x)),((∂ u)/(∂ y))⟩, then (Subscript[F, 1])=((∂ u)/(∂ x)) and (Subscript[F, 2])=((∂ u)/(∂ y)). Taking the partial derivative of (Subscript[F, 1])with respect to y and that of (Subscript[F, 2]) with respect to x and using the fact that (((∂^2) u)/(∂ x∂ y))=(((∂^2) u)/(∂ y∂ x)), we see that (Subscript[F, 1]) and (Subscript[F, 2]) must satisfy

((∂ (Subscript[F, 1]))/(∂ y))=((∂ (Subscript[F, 2]))/(∂ x))

This equation is used to check if a vector field is conservative.  In that case, we solve (Subscript[F, 1])=((∂ u)/(∂ x)) for u by integrating with respect to x and then use the equation (Subscript[F, 2])=((∂ u)/(∂ y)) to find the constant of integration. Here is an example.

Example 16.5.  Show that the vector function F=⟨3(x^2)-2xy +2,6(y^2)-(x^2)+3⟩  is conservative and find its potential.

Solution: Here, (Subscript[F, 1])=x (y^2) and (Subscript[F, 2])=(x^2)y. We now compare ((∂ (Subscript[F, 1]))/(∂ y)) and ((∂ (Subscript[F, 2]))/(∂ x)) to verify if F is conservative.

Clear[x,y,F1,F2]
F1[x_,y_]= 3(x^2)-2x y+2
F2[x_,y_]=6(y^2)-(x^2)+3

D[F1[x,y],y]
D[F2[x,y],x]

Thus, the vector field is conservative. To find its potential u, we integrate (Subscript[F, 1])=((∂ u)/(∂ x)) with respect to x to get

Clear[h,u]
u=Integrate[F1[x,y],x] +h[y]

Note that the addition of h(y) is necessary because the constant of integration may depend on y.  We now solve the equation (Subscript[F, 2])=((∂ u)/(∂ y)) for h'(y).

Clear[sol]
sol=Solve[D[u,y]==F2[x,y],h'[y]]

This means that h'(y)=3(1+2(y^2)).

Integrate[sol[[1,1,2]],y]

Hence, h(y)=3y+2(y^2)  and so u(x,y)=2x+(x^3)-(x^2) y +3y+2(y^3) is the potential of F.

NOTE 4: Let F=⟨(Subscript[F, 1]),(Subscript[F, 2]),(Subscript[F, 3])⟩.  If F=∇u=⟨((∂ u)/(∂ x)),((∂ u)/(∂ y)),((∂ u)/(∂ z))⟩, then (Subscript[F, 1])=((∂ u)/(∂ x)), (Subscript[F, 2])=((∂ u)/(∂ y)) and (Subscript[F, 3])=((∂ u)/(∂ z)). Taking the partial derivative of (Subscript[F, 1])with respect to y and that of (Subscript[F, 2]) with respect to x and using the fact that (((∂^2) u)/(∂x∂y))=(((∂^2) u)/(∂y∂x)), we see that (Subscript[F, 1]) and (Subscript[F, 2]) must satisfy

((∂ (Subscript[F, 1]))/(∂ y))=((∂ (Subscript[F, 2]))/(∂ x))

Taking the partial derivative of (Subscript[F, 1])with respect to z and that of (Subscript[F, 3]) with respect to x and using the fact that (((∂^2) u)/(∂x∂z))=(((∂^2) u)/(∂z∂x)), we see that (Subscript[F, 1]) and (Subscript[F, 3]) must satisfy

((∂ (Subscript[F, 1]))/(∂ z))=((∂ (Subscript[F, 3]))/(∂ x))

The preceding two equations can be used to check if a vector field is conservative. If this the case, we solve (Subscript[F, 1])=((∂ u)/(∂ x)) for u by integrating with respect to x and then use (Subscript[F, 2])=((∂ u)/(∂ y)) to find the constant of integration. We show this by the following example.

Example 16.6.  Show that the vector function F=⟨yz+yz cos (xy ), xz+xz cos (xy) ,xy+sin (xy)⟩  is conservative and find its potential.

Solution: Here, (Subscript[F, 1])=y z+y z cos( x y) ,  (Subscript[F, 2])=x z +x z cos (x y),  and (Subscript[F, 3])=x y + sin(x y) .

Clear[x,y,F1,F2,F3]
F1[x_,y_,z_]= y z +y z Cos[x y]
F2[x_,y_,z_]= x z + x z Cos[x y]
F3[x_,y_,z_]= x y +  Sin[x y]

We now compare ((∂ (Subscript[F, 1]))/(∂ y)) and ((∂ (Subscript[F, 2]))/(∂ x)):

D[F1[x,y,z],y]
D[F2[x,y,z],x]

Next, we compare ((∂ (Subscript[F, 1]))/(∂ z)) and ((∂ (Subscript[F, 2]))/(∂ x)):

D[F1[x,y,z],z]
D[F3[x,y,z],x]

Thus, the vector field is conservative. To find its potential u, we integrate (Subscript[F, 1])=((∂ u)/(∂ x)) with repsetct to x to get

Clear[u, h]
u=Integrate[F1[x,y,z],x] +h[y,z]

Note that the addition of h(y,z) is necessary because the constant of intgeration can depend on y and z. We now solve the equation (Subscript[F, 2])=((∂ u)/(∂ y)) for ((∂ h)/(∂ y)).

Clear[sol]
sol=Solve[D[u,y]==F2[x,y,z],(∂_y) h[y,z]]

This means that ((∂ h)/(∂ y))=0 and hence h is a function of z only.   Next, we solve the equation (Subscript[F, 3])=((∂ u)/(∂ z)) for ((∂ h)/(∂ z)).

Clear[sol2]
sol2=Solve[D[u,z]==F3[x,y,z],(∂_z) h[y,z]]

Hence, ((∂ h)/(∂ z))=0 and we can take h=0. Therefore, u=x y z +z sin (x y) is the potential for the vector field F.

Exercises

1. Show that the vector field F=⟨ (y^3)-3(x^2)y, 3(xy^2)-(x^3)⟩  is conservative and find its potential.

2. Show that the vector field F=⟨y z+((2 xy)/z), xz+((x^2)/z), xy-(((x^2)y)/(z^2))⟩  is conservative and find its potential.

3. Determine whether the vector field F=⟨(x^2), yx +(e^z), y (e^z)⟩  is conservative.  If it is, find its potential.

16.4  Parametrized Surfaces and Surface Integrals

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

A parametrized surface is a surface whose points are given in the form

G(u,v)=(x(u,v), y(u,v), z(u,v))

where u and v (called parameters) are independent variables used to describe a domain D (called the parameter domain).

The command for plotting parametrized surfaces is ParametricPlot3D.  This command has been discussed in Section 14.1.2 of this text.

Example 16.7.  Plot the parametrized surface defined by G(u,v)=(cos u sin v, 4 sin u cos v, cos v) over the domain D={(u,v)| 0≤u≤2π, 0≤v≤2π}.

Solution:

ParametricPlot3D[{ Cos[u] Sin[v],4 Sin[u] Cos[v], Cos[v]},{u,0,2Pi},{v,0,2Pi},ImageSize->{250}]

Example 16.8.  Plot the parametrized surface defined by G(u,v)=(u cos v,u sin v,1-(u^2)) over the domain D={(u,v)|0≤u≤1,0≤v≤2π}.

Solution:

ParametricPlot3D[{u Cos[v]  ,u Sin[v]  , 1-(u^2)},{u,0,1},{v,0,2Pi},ColorFunction->"BlueGreenYellow",ImageSize->{250},
ImagePadding->{{15,15},{15,15}}]

NOTE: On a parametrized surface G(u,v)=(x(u,v), y(u,v), z(u,v)), if we fix one of the variables, we get a curve on the surface.  The plot following shows the curves corresponding to u=3/4 (latitude) and v=5π/3 (longitude).

Clear[plot1,plot2,plot3] 
plot1= ParametricPlot3D[{u  Cos[v]  ,u Sin[v]  , 1-(u^2)},{u,0,1},{v,0,2Pi},ColorFunction->"BlueGreenYellow"];
plot2=ParametricPlot3D[{  3/4 Cos[v]  ,3/4  Sin[v]  , 7/16},{v,0,2Pi},PlotStyle->{Thickness[0.01],Red}];
plot3=ParametricPlot3D[{  u  Cos[5Pi/3]  ,u  Sin[5Pi/3]  ,1-(u^2)},{u,0,1},PlotStyle->{Thickness[0.01],Blue}];
Show[plot1,plot2,plot3,PlotRange->All,ImageSize->{250},
ImagePadding->{{15,15},{15,15}}]

Let P=G((Subscript[u, 0]),(Subscript[v, 0])) be a point on the parametrized surface S.  For fixed v=(Subscript[v, 0]), the tangent vector to the curve G(u,(Subscript[v, 0])) at ((Subscript[u, 0]),(Subscript[v, 0]))  is given by

(Subscript[T, u])=((∂G)/(∂u))((Subscript[u, 0]),(Subscript[v, 0]))

while the tangent vector for  G((Subscript[u, 0]),v) corresponding to a fixed u=(Subscript[u, 0]) is given by

(Subscript[T, v])=((∂G)/(∂v))((Subscript[u, 0]),(Subscript[v, 0]))

These two vectors are tangent to the surface S.  Thus, the normal vector n to the tangent plane at G((Subscript[u, 0]),(Subscript[v, 0])) is given by

n(P)=n((Subscript[u, 0]),(Subscript[v, 0]))=(Subscript[T, u])×(Subscript[T, v])

Example 16.9.  Consider the parametrized surface G(u,v)=( u cos v, u sin v, 1-(v^2)).
a) Find (Subscript[T, u]), (Subscript[T, v]), and n.
b) Find the equation of the tangent plane at (1/2, 5π/3).
c) Plot the tangent plane and surface.

Solution:  Let us define G as a function of u and v in Mathematica.

Clear[G,u,v]
G[u_,v_]={u Cos[v], u Sin[v], 1-(u^2)}

a) We use Tu for (Subscript[T, u]) and Tv for (Subscript[T, v]). We evaluate these as functions of u and v.

Clear[Tu,Tv,n]
Tu[u_,v_]=D[G[u,v],u]
Tv[u_,v_]=D[G[u,v],v]
n[u_,v_]=Cross[Tu[u,v],Tv[u,v]]

b) The normal vector to the tangent plane at (1/2, 5π/3) is

Clear[normal]
normal=n[1/2,5Pi/3]

The tangent plane passes through the point

Clear[point]
point=G[1/2,5Pi/3]

Thus, the equation of the tangent plane is given by

Clear[tplane]
tplane=normal.({x,y,z}-point)==0

which simplifies to

Simplify[tplane]

c) Here is the plot of the surface and the tangent plane. Observe that we have used ColorFunction and ColorFunctionScaling options.

Clear[plot1, plot2]
plot1= ParametricPlot3D[G[u,v],{u,0,1},{v,0,2Pi},ColorFunction->"BlueGreenYellow"];
plot2=ContourPlot3D[2 x+4 z==5+2 (Sqrt[3]) y, {x, -3,3}, {y, -3,3},{z, -4,4},ColorFunction->Function[{x,y,z},Hue[Mod[z,1]]],ColorFunctionScaling->False];
Show[plot1, plot2,ImageSize->{250},ImagePadding->{{15,15},{15,15}}]

NOTE: The area A(S) of a parametrized surface S: G(u,v)=(x(u,v), y(u,v), z(u,v)), where (u,v)∈D, is given by

A(S)=∫(∫_D)||n(u,v)||dudv

If f(x,y,z) is continuous at all points of S, then the surface area of f over S is given by

∫(∫_S)f(x,y,z)dS=∫(∫_D)f(G(u,v))||n(u,v)||dudv

Example 16.10.  Show the following:
a) The area of the cylinder of height h  and radius r is 2π rh.
b) The area of the sphere of radius r is 4π (r^2).

Solution: 
a) A parametric equation of the cylinder of height h  and radius r can be given by

x=r cos v, y=r sin v, and z=u, where  0≤v≤2π , 0≤u≤h

Thus, the cylinder is given by G(u,v)=(r cos u, r sin u, v).

Clear[ G,u,v,r]
G[u_,v_]={r Cos[v], r Sin[v],u}

Here is a plot of the cylinder with r=3 and h=5:

r=3;h=5;
ParametricPlot3D[G[u,v], {u, 0, h},{v, 0, 2Pi}]

To compute the surface area of the cylinder, we need to compute its normal vector.

Clear[Tu,Tv,n,r,h]
Tu[u_,v_]=D[G[u,v],u];
Tv[u_,v_]=D[G[u,v],v];
n[u_,v_]=Cross[Tu[u,v],Tv[u,v]]

Here is a plot of the cylinder with its normal vector for  r=3 and h=5:

r=3;h=5;
Clear[plot1,plot2]
plot1=ParametricPlot3D[G[u,v], {u, 0, h},{v, 0, 2Pi}];
plot2=VectorFieldPlot3D[n[u,v],{u,0,h},{v,-2Pi,2Pi},{z,-3,3},  VectorHeads->True,PlotPoints->15];
Show[plot1,plot2,ImageSize->{250}]
Clear[r,h]

The surface area is

SArea=(∫_0^h)(∫_0^(2Pi))Norm[n[u,v]]\[DifferentialD]v\[DifferentialD]u

Since r>0, |r|=r and hence the preceding output is 2π r h .

b) A parametric equation of the sphere of radius r is

x=r cos u sin v, y=r sin u sin v, z=r cos v

where 0≤u≤2π and 0≤v≤π.  Thus, the sphere is given by G(u,v)=(r cos u sin v,r sin u sin v,r cos v).

Clear[ G,u,v,r]
G[u_,v_]={r Cos[u] Sin[v], r Sin[u] Sin[v],r Cos[v]}

Here is a plot of the sphere with r=3.

r=3; 
ParametricPlot3D[G[u,v],{u, 0, 2Pi}, {v, 0, Pi},ImageSize->{250}]

To compute the surface area of the sphere, we need to compute its normal vector.

Clear[Tu,Tv,n,r]
Tu[u_,v_]=D[G[u,v],u];
Tv[u_,v_]=D[G[u,v],v];
n[u_,v_]=Cross[Tu[u,v],Tv[u,v]]

Here is a plot of the sphere with its normal vector for  r=3.

r=3;h=5;
Clear[plot1,plot2]
plot1=ParametricPlot3D[G[u,v],{u, 0, 2Pi}, {v, 0, h}];
plot2=VectorFieldPlot3D[n[u,v],{u,-2Pi,2Pi},{v,0,h},{z,-3,3},  VectorHeads->True,PlotPoints->10];
Show[plot1,plot2,ImageSize->{250}]
Clear[r,h]

The surface area is

SArea=(∫_0^Pi)(∫_0^(2Pi))Norm[n[u,v]]\[DifferentialD]u\[DifferentialD]v

For a real number r, the conjugate of r is r and hence the preceding output is 4π (r^2).

Example 16.11.  Consider the parametrized surface S defined by G(u,v)=( u cos v, u sin v, v), where 0≤u≤1, 0≤v≤2π.
a) Find the surface area of S.
b) Evaluate ∫(∫_S)xyzdS.

Solution:
a)

Clear[ G,u,v]
G[u_,v_]={u Cos[v], u Sin[v],v}

Clear[Tu,Tv,n]
Tu[u_,v_]=D[G[u,v],u]
Tv[u_,v_]=D[G[u,v],v]
n[u_,v_]=Cross[Tu[u,v],Tv[u,v]]

The surface area A(S) is given by

SArea=(∫_0^1)(∫_0^(2Pi))Norm[n[u,v]]\[DifferentialD]v\[DifferentialD]u

which is approximately equal to

N[%]

b) We define f:

Clear[f]
f[x_,y_,z_]=x y z

The surface integral of f is

(∫_0^1)(∫_0^(2Pi))f[G[u,v][[1]],G[u,v][[2]],G[u,v][[3]]]Norm[n[u,v]]\[DifferentialD]v\[DifferentialD]u

Or numerically,

N[%]

Exercises

1. Plot the parametrized surface G(u,v)=((e^u)sin v,(e^u) cos v,v) over the domain D={(u,v)| -1≤u≤1, 0≤v≤2π}.

2. Plot the parametrized surface G(u,v)=(3sin u cos v,sin u sin v,cos v+3 cos u) over the domain D={(u,v)| 0≤u≤2π, 0≤v≤2π}.

3. Consider the parametrized surface G(u,v)=((e^(-u))  cos v,(e^u)sin v,(e^u)cos v).
a.  Find (Subscript[T, u]), (Subscript[T, v]), and n.
b.  Find the equation of the tangent plane at (0, π/ 2).
c.  Plot the tangent plane and surface.

4. Consider the parametrized surface S: G(u,v)=( u-v ,3u+v,(u^2)-2 u v +6(v^2)), where 0≤u≤1, 0≤v≤1.
a.  Find the surface area of S. (Use NIntegrate for faster integration.)
b.  Evaluate ∫(∫_S)(3x+ 2(y^2)-  (z^2))dS.

16.5  Surface Integrals of Vector Fields

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

An orientation of a surface S is a continuously varying choice of the unit normal vector (Subscript[e, n])(P) at each point of the surface.  Thus, (Subscript[e, n]) is given by either

(Subscript[e, n])(P)=((n(P))/(||n(P)||))   or   (Subscript[e, n])(P)=-((n(P))/(||n(P)||))

If F(x,y,z) is continuous at all points of a parametrized surface S, then the surface integral of F over S is given by

∫(∫_S)F·dS=∫(∫_S)(F·(Subscript[e, n]))dS

where (Subscript[e, n]) is the unit normal determined by an orientation. The surface integral of F is also called the flux of F across S.

The surface integral of F over a parametrized surface S given by G(u,v)=(x(u,v),y(u,v),z(u,v)), where (u,v)∈D, is given by

∫(∫_S)F·dS=∫(∫_S)(F·(Subscript[e, n]))dS =∫(∫_D)F(G(u,v))·n(u,v) dudv

Example 16.12.  Find  ∫(∫_S)F·dS, where F(x,y,z)=⟨x  z, z , y x⟩ and S is given by  G(u,v)=(u-(v^2),u v,(u^2)-v), 0≤u≤2, and 1≤v≤3.

Solution:

Clear[F,G,x,y,z,u,v]
F[x_,y_,z_]={x z, z, y x}
G[u_,v_]={u-(v^2), u v, (u^2)-v}

Clear[Tu,Tv,n]
Tu[u_,v_]=D[G[u,v],u]
Tv[u_,v_]=D[G[u,v],v]
n[u_,v_]=Cross[Tu[u,v],Tv[u,v]]

Flux=(∫_0^2)(∫_1^3)F[G[u,v][[1]],G[u,v][[2]],G[u,v][[3]]] .n[u,v]\[DifferentialD]v\[DifferentialD]u

Example 16.13.  Find  ∫(∫_S)F·dS, where F(x,y,z)=⟨(x^2), (z^2) , y+ (x^2)⟩ and S is the upper hemisphere (x^2)+(y^(2 ))+(z^2)=4 with outward normal orientation.

Solution:  First, we find the parametric equation of the cylinder. This can be given by x=2 cos u sin v, y=2 sin u sin v, and z=2cos v, where 0≤u≤2π and 0≤v≤π/2.

For the hemisphere to have the outward orientation, we note that n=(Subscript[T, v])×(Subscript[T, u]). With this in mind we compute the flux of F across S through the following steps.

Clear[F,G,x,y,z,u,v]
F[x_,y_,z_]={   (x^2), (z^2), (x^2)+y+(z^3)}
G[u_,v_]= { 2 Cos[u]Sin[v]  , 2 Sin[u] Sin[v]   , Cos[v] }

Clear[Tu,Tv,n]
Tu[u_,v_]=D[G[u,v],u]
Tv[u_,v_]=D[G[u,v],v]
n[u_,v_]=Cross[Tv[u,v],Tu[u,v]]

Flux=(∫_0^(Pi/2))(∫_0^(2Pi))F[G[u,v][[1]],G[u,v][[2]],G[u,v][[3]]] .n[u,v]\[DifferentialD]u\[DifferentialD]v

Exercises

1. Find ∫(∫_S)F·dS, where F(x,y,z)=⟨ (e^z),z,y x⟩ and S is given by G(u,v)=(u v,u-v,u),  0≤u≤2, and -1≤v≤1, and oriented by n=(Subscript[T, u])×(Subscript[T, v]).

2. Find  ∫(∫_S)F·dS, where F(x,y,z)= ⟨ z,x ,y ⟩ and S is the portion of the ellipsoid  ((x^2)/16)+((y^(2 ))/9)+((z^2)/4)=1 for which x≤0,   y≤0, and z≤0 with outward normal orientation.

3. Let S be given by G(u,v)=((1+v cos(u/2))cos u,(1+v cos(u/2))sin u , v sin (u/2) ),  0≤u≤2π, and ((-1)/2)≤v≤(1/2).
a. Plot the surface S. (S is an example of a Mobius strip.)
b. Find the surface area of S.
c. Evaluate ∫(∫_S)((x^2)+ 2(y^2)+3  (z^2))dS.
d. Find the intersection points of S and the xy-plane.
e. For each of the points on the intersection of S and the xy-plane, find the normal vector n.
f. Show that n varies continuously but that n(2π,0)=-n(u,0). (This shows that S is not orientable and hence it is impossible to integrate a vector field over S.)

Chapter 17	Fundamental Theorems of Vector Analysis

Useful Tip: If you are reading the electronic version of this publication formatted as a Mathematica Notebook, then it is possible to view 3-D plots generated by Mathematica from different perspectives.  First, place your screen cursor over the plot.  Then drag the mouse while pressing down on the left mouse button to rotate the plot.

NOTE: In order to perform the operations of curl and divergence on vector fields discussed in this section using Mathematica, it is necessary to first load the VectorAnalysis package:

Needs["VectorAnalysis`"]

The Fundamental Theorem of Calculus for functions of a single variable states that the integral of a function f(x) over an interval [a,b] (domain) can be calculated as the difference of its anti-derivative F(x) at the endpoints (boundary) of the interval:

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

This integral relationship between domain and boundary can be generalized to vector fields involving the operations of curl and divergence and is made precise by three theorems that will be discussed in this chapter: Green's Theorem, Stoke's Theorem, and Divergence Theorem.

17.1  Green's Theorem

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

Let  F(x,y)=⟨P(x,y),Q(x,y)⟩ a vector field continuous on an oriented curve C.  Recall that the line integral of F along C is denoted by

(∫_C)F(x,y,z)·ds=(∫_C) Pdx+Qdy

If c(t)=⟨x(t), y(t),z(t)⟩ is the vector equation of the curve C, then

(Subscript[∲, C]) Pdx+Qdy=  (∫_a^b)(P(x(t),y(t)) ((d x)/(d t))+Q(x(t),y(t)) ((d y)/(d t)))d t

The following is a generalization of the Fundamental Theorem of Calculus to two dimensions, which relates a double integral over a region with a corresponding line integral along its boundary.

Green's Theorem: If C is a simple closed curve oriented counterclockwise and D is the region enclosed, and if P and Q are differentiable and have continuous first partial derivatives, then

(Subscript[∲, C]) Pdx+Qdy=∫(∫_D)(((∂ Q)/(∂ x))-((∂ P)/(∂ y))) dA

Refer to your textbook for a detailed discussion and proof of Green's Theorem.

Example 17.1. Compute the line integral (Subscript[∲, C]) (e^(2x+y))dx+(e^(-y))dy, where C is the boundary of the square with vertices (0,0), (1,0), (1,1), (1,0) oriented counterclockwise.

Solution: We will use Green's Theorem.  Thus, we need to verify that the hypotheses of Green's Theorem hold. To this end, we define the function P and Q and compute their partial derivatives.

Clear[x,y,P,Q]
P[x_,y_]= (E^(2x+y))
Q[x_,y_]=(E^(-y))

D[P[x,y],x]
D[P[x,y],y]
D[Q[x,y],x]
D[Q[x,y],y]

The partial derivatives are continuous inside the square and the curve is oriented counterclockwise. Thus, the hypotheses of Green's Theorem are satisfied.  Note that the region D enclosed by C is given by 0≤x≤1 and 0≤y≤1.

(∫_0^1)(∫_0^1)(D[Q[x,y],x]-D[P[x,y],y])\[DifferentialD]y\[DifferentialD]x

N[%]

NOTE: If we were to solve this using the definition of line integral as discussed in Chapter 16 of this text, we would then need to consider four pieces of parametrization of C and then sum the four integrals.   Toward this end, let us use (Subscript[C, 1]) for the lower edge, (Subscript[C, 2]) for the right edge, (Subscript[C, 3]) for the top edge, and (Subscript[C, 4]) for the left edge of the square.  Here are the parametrizations followed by their line integrals.

Clear[x1,x2,x3,x4,y1,y2,y3,y4,t,F,c1,c2,c3,c4]
F[x_,y_]={P[x,y],Q[x,y] } 
x1[t_]=t
y1[t_]= 0
c1[t_]={x1[t],y1[t]}

x2[t_]=1
y2[t_]= t
c2[t_]={x2[t],y2[t]}

x3[t_]=1-t
y3[t_]= 1
c3[t_]={x3[t],y3[t]}

x4[t_]=0
y4[t_]=1- t
c4[t_]={x4[t],y4[t]}

(∫_0^1)F[x1[t],y1[t]].c1'[t]\[DifferentialD]t+(∫_0^1)F[x2[t],y2[t]].c2'[t]\[DifferentialD]t+(∫_0^1)F[x3[t],y3[t]].c3'[t]\[DifferentialD]t+(∫_0^1)F[x4[t],y4[t]].c4'[t]\[DifferentialD]t

N[%]

Exercises

In Exercises 1 through 4, use Green's Theorem to evaluate the given line integral.

1. (Subscript[∲, C]) (y^2)sin x dx+x ydy, where C is the boundary of the triangle with vertices (0,0), (1,0), (1,1), oriented counterclockwise.

2. (Subscript[∲, C]) 2(x^2) y dx+(x^3) dy, where C is the circle (x^2)+(y^2)=4, oriented counterclockwise.

3. (Subscript[∲, C]) ((x^2)+(y^2)) dx+ y (e^x)dy, where C is the boundary of the region bounded between the parabola y=5-(x^2) and the line y=2x-3, oriented clockwise.

4. (Subscript[∲, C])  (x/((x^2)+(y^2)))dx-(y/((x^2)+(y^2))) dy, where C is the boundary of the quarter-annulus situated between the circles (x^2)+(y^2)=1 and (x^2)+(y^2)=9 in the first quadrant (see plot below), oriented counterclockwise.

5. Let F(x,y)=(2x y+(y^3),(x^2)+3x y+2y).  Use Green's Theorem to demonstrate that the line integral (∫_C)F(x,y,z)·ds=0 for every simple closed curve C.  What kind of a vector field do we call F?

17.2  Stokes's Theorem

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

Let F(x,y,z)=⟨(Subscript[F, 1]),(Subscript[F, 2]),(Subscript[F, 3])⟩ be a vector field.  The curl of F, denoted by curl(F) or ∇×F, is defined by

curl(F)=∇×F=|({{i, j, k}, {(∂/(∂x)), (∂/(∂y)), (∂/(∂z))}, {(Subscript[F, 1]), (Subscript[F, 2]), (Subscript[F, 3])}})|=⟨((∂(Subscript[F, 3]))/(∂y))-((∂(Subscript[F, 2]))/(∂z)),((∂(Subscript[F, 1]))/(∂z))-((∂(Subscript[F, 3]))/(∂x)),((∂(Subscript[F, 2]))/(∂x))-((∂(Subscript[F, 1]))/(∂y))⟩

Here, we are using the del or symbol ∇ (nabla) to denote the vector operator ∇= ⟨(∂/(∂x)),(∂/(∂y)),(∂/(∂z))⟩.

The Mathematica command for computing the curl of a vector field F is Curl[F,coordsys], where coordsys is the coordinate system of the vector field.  This is demonstrated in the next example.

The following is a generalization of the Fundamental Theorem of Calculus three dimensions, which relates a surface integral involving curl with a corresponding line integral along its boundary.

Stokes's Theorem: If  F(x,y,z) a vector field with continuous partial derivatives and if S is an oriented surface S with boundary ∂S,  then

(∮_(∂S))F·dS=∫(∫_S)curl(F)·dS

If S is closed, then it has no boundary and hence both integrals are equal to 0.

NOTE: Recall that if the surface S is given by G(u,v)=(x(u,v), y(u,v), z(u,v)), where (u,v)∈D, then (∫_S)curl(F)·dS is given by

∫(∫_S)curl(F)·dS=∫(∫_D)curl(F)(G(u,v)) ·n(u,v) dudv

Refer to your textbook for a detailed discussion and proof of Stokes's Theorem.

Example 17.2.  Find the curl of the vector field F(x,y,z)=⟨ x sin (y z),(e^(x /y)) z ,y (x^2)⟩.

Solution: We use the Curl command:

Clear[F,F1,F2,F3,x,y,z]
F1 =x  Sin[y z]
F2  =(E^(x/y))z
F3 =((x )^2) y
F={F1,F2,F3}

Curl[F,Cartesian[x,y,z]]

NOTE: We obtain the same answer for the curl of F using the explicit formula:

curl={(∂_y) F3-(∂_z)F2,(∂_z)F1 -(∂_x)F3,(∂_x)F2-(∂_y)F1}

Or equivalently,

CurlF={D[F3,y]-D[F2,z],D[F3,x]-D[F1,z],D[F2,x]-D[F1,y]}

Example 17.3.  Let f(x,y,z) be a function of three variables with continuous first and second partial derivatives and let F=∇f be the gradient of f.  Find the curl of the vector field F.

Solution:

Clear[f,F1,F2,F3,x,y,z]
F1 =D[f[x,y,z],x]
F2  =D[f[x,y,z],y]
F3 =D[f[x,y,z],z]
F={F1,F2,F3}

Then the curl of F is

Curl[F,Cartesian[x,y,z]]

To see why the curl is zero, let us examine each partial derivative used in computing the curl of F.

D[F3,y]
D[F2,z]

NOTE: Here, (f^((0,1,1)))[x,y,z] stands for the second partial derivative (Subscript[f, yz]). Thus, the two partial derivatives that appear in the x-component of the curl of F are equal and hence their difference is zero. Similarly, we have

D[F3,x]
D[F1,z]

and

D[F2,x]
D[F1,y]

Example 17.4.  Compute  (∮_(∂S))F·dS, where F(x,y,z)=⟨ x y z, z+3x -3y , ((y )^2)x⟩ and S is the upper hemisphere of radius 4.

Solution: Note that ∂S is a circle of radius 4 lying on the xy-plane. Hence, ∂S can be parametrized by the curve c(t)=(x(t),y(t),z(t)) where

x=4 cos t, y=4sin t, z=0, where  0≤t≤2π

We then use this parametrization to evaluate the line integral (∮_(∂S))F·dS=(∫_0^(2π))F(x(t),y(t),z(t))·c'(t)dt:

Clear[F, x,y,z,t,c,curlF]
F[x_,y_,z_]={x y z, z+3x-3y, (y^2) x}
x[t_]=4Cos[t]
y[t_]= 4Sin[t]
z[t_]=0
c[t_]={x[t],y[t],z[t]}

(∫_0^(2Pi)) F[x[t],y[t],z[t]].c'[t]\[DifferentialD]t

Next, we use Stokes's Theorem to obtain the same answer via the corresponding surface integral.  The parametrization of the upper hemisphere of radius 4 is given by S(u,v)={x(u,v),y(u,v),z(u,v)}, where

x=4cos u sin v,  y=4 sin u sin v, and z=4 cos v,    where    0≤u≤2π, 0≤v≤π/2

We now compute the normal of the upper hemisphere:

Clear[S,u,v,Tu,Tv,n] 
S[u_,v_]:= { 4 Cos[u]Sin[v],4Sin[u] Sin[v],4Cos[v] } 
Tu[u_,v_]:=D[S[u,v],u]
Tv[u_,v_]:=D[S[u,v],v]
n[u_,v_]=Cross[Tv[u,v],Tu[u,v]]

The curl of F is

curlF[x_,y_,z_]=Curl[F[x,y,z],Cartesian[x,y,z]]

Thus, the surface integral is given by

(∫_0^(Pi/2))(∫_0^(2Pi))curlF[S[u,v][[1]],S[u,v][[2]],S[u,v][[3]]] .n[u,v]\[DifferentialD]u\[DifferentialD]v

This answer agrees with the one obtained using the line integral definition.

Example 17.5.  Find the flux of the curl of the vector field F(x,y,z)=⟨ (x^2), (z^2) , y+ (x^2)⟩ across S, where S is the part of the cone (z^2)=(x^2)+(y^2) for which 1≤z≤4 with outward normal orientation.

Solution:  First, we will need the following parametric equations to describe the cone S: x=u cos v , y=u sin v, and z=u, where 0≤v≤2π and 1≤u≤4.

For the cone to have outward orientation, we set n=(Subscript[T, v])×(Subscript[T, u]) (right-hand rule) since (Subscript[T, v]) points in the horizontal direction around the cone and (Subscript[T, u]) points in the direction along the length of the cone.

Clear[F,S,u,v,Tu,Tv,n] 
F[x_,y_,z_]={(x^2)+(y^2), x+(z^2),0}
S[u_,v_]:= { u Cos[v]  , u Sin[v] ,u } 
Tu[u_,v_]:=D[S[u,v],u]
Tv[u_,v_]:=D[S[u,v],v]
n[u_,v_]=Cross[Tv[u,v],Tu[u,v]]

We now compute the flux of curl(F) across S through the following steps.

curlF[x_,y_,z_]=Curl[F[x,y,z],Cartesian[x,y,z]]

Flux=(∫_1^4)(∫_0^(2Pi))curlF[S[u,v][[1]],S[u,v][[2]],S[u,v][[3]]].n[u,v]\[DifferentialD]v\[DifferentialD]u

Exercises

NOTE: In order to perform the curl operation in Mathematica, it is necessary to first load the VectorAnalysis package.  See instructions given at the beginning of this chapter.

In Exercises 1 and 2, find the curl of the given vector field.
1. F(x,y,z)=⟨ ln ((x^2)+(y^2)+(z^2)),x/ z ,(e^x)sin (y z)⟩
2. F(x,y,z)=⟨ -(x/((((x^2)+(y^2)+(z^2)))^(3/2))),-(y/((((x^2)+(y^2)+(z^2)))^(3/2))),-(z/((((x^2)+(y^2)+(z^2)))^(3/2)))⟩

In Exercises 3 and 4, verify Stokes's Theorem for the given vector field F and surface S.
3. F(x,y,z)=⟨ (x^3)e-3x y+(z^3),2 (z^3)-x (z^2)+(y^4),6y+2(z^3)(x^2)⟩ and S is the part of the paraboloid z=(x^2)+(y^2) for which z≤9 and with outward normal orientation.
4. F(x,y,z)=⟨ x y z,x y,x+y+z⟩ and S is the elliptical region in the plane y+z=2 whose boundary is the intersection of the plane with the cylinder (x^2)+(y^2)=1 and with upward normal orientation.

In Exercises 5 and 6, use Stokes's Theorem to compute the flux of the curl of the vector field F across the surface S.
5. F(x,y,z)=⟨ tan(x y z),(e^(y-x z)),sec((y^2)x)⟩ and S is the upper hemisphere of radius 4.
6. F(x,y,z)=⟨ (x^2)z,x (y^2),(z^2)⟩ and S consists of the top and four sides of the cube (excluding the bottom) with vertices at (0,0,0), (1,0,0), (0,1,0), (1,1,0), (0,0,1), (1,0,1), (0,1,1), (1,1,1).

17.3  Divergence Theorem

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

Let F(x,y,z)=⟨(Subscript[F, 1]),(Subscript[F, 2]),(Subscript[F, 3])⟩ be a vector field.  The divergence of F, denoted by div(F) or ∇·F, is defined by

div(F)=∇·F=((∂(Subscript[F, 1]))/(∂x)) +((∂(Subscript[F, 2]))/(∂ y))+((∂(Subscript[F, 3]))/(∂z))

where ∇= ⟨(∂/(∂x)),(∂/(∂y)),(∂/(∂z))⟩.

The Mathematica command for computing the divergence of a vector field F is Div[F,coordsys], where coordsys is the coordinate system of the vector field.  This is demonstrated in the next example.

The following is another generalization of the Fundamental Theorem of Calculus three dimensions, which relates a triple integral of a solid object involving divergence with a corresponding surface integral along its boundary.

Divergence Theorem: Let W be a region in (ℝ^3) whose boundary ∂W is a piecewise smooth surface, oriented so that the normal vectors to ∂W point outside of W, and F(x,y,z) be a vector field with continuous partial derivatives whose domain contains W.  Then

∫(∫_(∂W))F·dS =∫∫(∫_W)div(F) dV

Refer to your textbook for a detailed discussion and proof of the Divergence Theorem.

Example 17.8.  Find the divergence of the vector field F(x,y,z)=⟨ x sin (yz),(e^(x /y)) z ,(yx^2)⟩.

Solution:

Clear[F1,F2,F3,x,y,z]
F1 =x  Sin[y z]
F2  =(E^(x/y))z
F3 =((x )^2) y
F={F1,F2,F3}

Then the divergence of F is

Div[F,Cartesian[x,y,z]]

NOTE: Again we obtain the same answer for the divergence of F using the explicit formula:

D[F1,x]+D[F2,y]+D[F3,z]

Example 17.9.  Find ∫(∫_S) F·dS, where F(x,y,z)=⟨ x ,(y^2),y+z⟩ and S=∂W is the boundary of the region W contained in the cylinder  (x^2)+(y^2)=4 between the plane z=x and z=8.

Solution: If S is the boundary of the solid W, then W is given by

W={(x,y,z): -2≤x≤2, -(Sqrt[4-(x^2)])≤y≤(Sqrt[4-(x^2)]), x≤z≤8}

Clear[F,divF,x,y,z]
F[x_,y_,z_]={x,(y^2),y+z}
divF=Div[F[x,y,z],Cartesian[x,y,z]]

By the Divergence Theorem, we see that ∫(∫_S) F·dS is given by

(∫_(-2)^2)(∫_(-(Sqrt[4-(x^2)]))^(Sqrt[4-(x^2)]))(∫_x^8)divF\[DifferentialD]z\[DifferentialD]y\[DifferentialD]x

Exercises

NOTE: In order to perform the divergence operation in Mathematica, it is necessary to first load the VectorAnalysis package.  See instructions given at the beginning of this chapter.

In Exercises 1 and 2, find the divergence of the given vector field F.
1. F(x,y,z)=⟨ x y z,(x^2)+(y^2)+(z^2),x y+y z+x z⟩
2. F(x,y,z)=⟨ (e^(x y))cos z,(e^(y z))sin z, (z^2)⟩

In Exercises 3 and 4, verify the Divergence Theorem for the given vector field F and solid region W.
3. F(x,y,z)=⟨(x^2)y,(y^2)z,(z^2)x ⟩ and W={(x,y,z):(x^2)+(y^2)+(z^2)<1} is the unit ball. 
4. F(x,y,z)=⟨(e^x)cos y,(e^x)sin y,x y z ⟩ and W is the region bounded by the paraboloid z=(x^2)+(y^2) and z=4.

In Exercises 5 and 6, use the Divergence Theorem to calculate the flux of the vector field F across the surface S.
5. F(x,y,z)=⟨ x (e^(z )),(y^2),y+z x⟩ and S is tetrahedron bounded by the plane 3x+4y+5z=15 and the coordinate planes in the first octant.
6. F(x,y,z)=⟨ x y z,(x^2)+(y^2)+(z^2),x y+y z+x z ⟩ and S is the unit cube with vertices at (0,0,0), (1,0,0), (0,1,0), (1,1,0), (0,0,1), (1,0,1), (0,1,1), (1,1,1).