Thomas Calculus Mathematica Tutorial
Thomas Calculus Mathematica Tutorial
TABLE OF CONTENTS
1. INFORMATION FOR INSTRUCTORS ................................................................................................ 1
A. GETTING STARTED ..........................................................................................................................................1
Determine the Computing Needs of Your Students .................................................................................................................. 1
Familiarize Yourself With the Student Computing Environment ............................................................................................. 1
Install Mathematica Modules and CAS Exercise Examples ..................................................................................................... 1
A. GETTING STARTED
Determine the Computing Needs of Your Students
First, you need to determine where students will complete their Mathematica assignments. If you plan on having students
complete their work on campus, then make sure that Mathematica is installed and available in the lab where students will be
working.
For those of you who need to purchase Mathematica for a campus computer lab, consider an educational site license, which will
allow your school to install Mathematica on several machines at a discounted price. Currently, Mathematica runs on most major
platforms and operating systems. For more information and technical requirements for the various platforms, visit
www.wolfram.com/products/mathematica/platforms/. For more information on the purchasing an academic site license, go to
www.wolfram.com/solutions/highered/academicpurchase/.
If Mathematica is not available on campus, then you will need to determine if it is feasible for students to purchase their own
copies of Mathematica. The student version is called Mathematica for Students and it is available at greatly reduced price (about
90% off the professional version price). Full-time students and in some cases, part-time students are eligible to purchase the
student version. Although it is available online, you may want your campus bookstore to have copies of Mathematica for
Students available for purchase. For more information about Mathematica for Students, go to
www.wolfram.com/products/student/mathforstudents/. This site includes information on eligibility requirements for purchasing
Mathematica for Students along with information about the similarities and differences between the student version and
professional version of Mathematica.
Familiarize Yourself with the CAS Exercises and the Mathematica Modules
Spend some time working through some of the CAS exercises and the Mathematica modules before the semester begins. By
doing this, you will get a better feel about which Mathematica modules and exercises are most appropriate for your students. If
you are new to the Mathematica computing environment, I highly recommend completing the first Mathematica module, An
Overview of Mathematica, found on the Web site and/or CD-ROM. This module will introduce you to some of the basic features
and commands of Mathematica. In addition, read through the CAS Exercise Examples contained in this computer manual and
try some of the corresponding exercises in the text to become more comfortable with the Mathematica computing environment.
The Following Section Entitled Information for Students is Also For You!
Although the information in the following section is written for students, you should also read the next section to learn more
about the Mathematica computing environment. If you are already familiar with Mathematica, then you might want to quickly
skim through the material. However, if you are a new Mathematica user, then you may want to read the contents of the following
section very carefully.
A. MATHEMATICA NOTEBOOKS
Cells
A Mathematica notebook is a file organized into a sequence of cells. Each cell contains a specific type of information that has
either been entered by the user or has been created as the result of the execution of a Mathematica command. Associated with
each cell is a cell bracket in the right margin (see Figure 1).
an input cell contains a little triangle on the upper end of the cell bracket. An output cell contains the results of an input cell that
has been executed. A text cell contains information to be read by the user, but contains no executable commands.
Title Cell
Text Cell
Graphics Cell
Input Cells
Output Cells
Deleting Cells
To delete an entire cell, simplify click on the cell bracket and press the Delete key.
Palettes
Sometimes you can use palettes instead of the keyboard to enter information into a notebook. A palette is similar to a set of
calculator buttons, which provide you with shortcuts to entering commands and symbols into a notebook. A palette that you
might find useful is BasicInput . You can find it by pulling down the File menu, then selecting Palettes and then selecting
BasicInput. When the palette appears on the screen, drag it to the right side of the screen and resize the notebook so that they
both appear on the screen in non-overlapping windows (see Figure 5). Now, for example, suppose you want to compute the
square root of 16. Simply click on the square root button on the palette and the square root symbol will then appear in the
notebook. Enter 16 and then type Shift-Enter to obtain the result.
BasicInput
Palette
Syntax Errors
Incorrectly entering a Mathematica command will result in a syntax error when the command is executed. An error message will
be displayed on the screen as shown in Figure 6. Since Mathematica is case-sensitive, make sure you correctly capitalize the
appropriate letters in the command before you execute it. When possible, use palettes to enter commands and shortcuts to
commands rather than typing commands. More information on correct Mathematica syntax can be found later on in this manual
in a section entitled An Introduction to Mathematica and in the first module, An Overview of Mathematica.
Printing problems
A Mathematica notebook containing three-dimensional graphics may be very slow to print especially if you are connected to a
printer on a local network. To speed of the printing process, hold down the Ctrl key and then click on all the brackets containing
graphics. Then pull down the Cell menu and select Convert To followed by Bitmap. Converting the graphics images to bitmap
images will speed up the printing process.
C. MATHEMATICA MODULES
A list of the 38 Mathematica modules contained in the CD/Web site is given below. The title of each module is followed by a
set of parenthesis containing the name of the corresponding file on the CD/Web. The objective of each module is given along
with prerequisite reading in Thomas Calculus and Thomas Calculus, Early Transcendentals, Tenth Edition.
10
2. Modeling Change: Springs, Driving Safety, Radioactivity, Trees, Fish and Mammals
(ChP_mod.nb)
The purpose of this module is to use Mathematica to practice a modeling process: consider a behavior, observe data, fit a model,
analyze the error, improve the model if appropriate, interpret the model, and make predictions. Prerequisite reading for this
module is Section 7 of the Preliminary Chapter.
4. Going to Infinity: What Happens to Functions When the Independent Variable Gets
Bigger and Bigger and Bigger? (Ch1_inf.nb)
The purpose of this module is to interpret limits going to infinity both graphically and numerically. Read Sections 1.3 and 1.4 to
prepare for this module.
7. Motion Along a Straight Line, Part I: Position -> Velocity -> Acceleration (Ch3_mo1.nb)
In this module, you will apply special Mathematica functions to analyze position, velocity, and acceleration simultaneously.
Three specially designed Mathematica commands are introduced here that generate animations to help you visualize the
derivative relations among the position, velocity, and acceleration functions. Concepts from Sections 2.2, 2.4, 3.3 are covered in
this notebook.
9. Bending of Beams or What Does Calculus Have to Do With the Design of Structures?
(Ch4_bb.nb)
In this module, you will learn how engineers use calculus to design structures. Structural engineers need to calculate how beams
bend, and they do so by using principles of structural mechanics and calculus. You will investigate some of the ways that
engineers use calculus to ensure that the structures they design are both safe and functional.
Before you begin this module, refer to "Maximums, Minimums, and Inflection Points," a Java applet included in the Web/CD.
This applet allows you to explore the relationship between the shape of the graph of a function and the values of its first and
second derivatives. Read Section 4.1 before completing this module.
11
10. Using Riemann Sums to Estimate Areas, Volumes, and Lengths of Arc (Ch4_avl.nb)
In this module, Riemann sums are used to approximate areas, volumes, and lengths of arc. You will also construct accumulation
functions, and see how the accumulated quantities converge to the antiderivative in the limit. Concepts from Sections 4.3, 5.1
and 5.3 are covered in this lab.
11. Summing It up with Riemann, Definite Integrals and the Fundamental Theorem of
Calculus (Ch4_rs.nb)
The objective of this lab is to visualize the relationship among Riemann sums, the definite integral, and the Fundamental
Theorem of the Calculus. You will use each of these concepts to compute or approximate the signed area under the graph of a
function representing various applications. Read Sections 4.4 4.6, and 6.1 before completing this module.
13. Motion Along a Straight Line, Part II: Acceleration -> Velocity -> Position (Ch4_mo2.nb)
This module will help you develop an understanding of the integral relationship between acceleration and velocity, and between
velocity and position of an object moving along a straight line. Two specially designed Mathematica commands are introduced
here that animate the integral relations between acceleration and velocity, and between velocity and position of an object moving
along a straight line. A variety of motions are studied, including constant velocity, constant acceleration, harmonic oscillation,
and decaying oscillations. You can also use the specialized Mathematica commands to study other motions that may be of
interest to you. Read Section 4.5 before you begin this module.
16. Drug Dosages: Are They Effective? Are they Safe? (Ch6_dd.nb)
The purpose of this module is to use Mathematica to solve differential equations related to drug concentrations in the blood when
the drug is administered by a single injection, intravenously, or by periodic injections. You will learn how a simple
mathematical model and Mathematica can be used to regulate the concentration of a prescribed drug in the blood. Read Section
6.4 (Section 5.4 in the Early Transcendentals Version) before beginning this module.
18. Games of Chance: Exploring the Monte Carlo Technique for Numerical Integration and
Computing Probabilities with Improper Integrals (Ch7_int.nb)
The objective of this module is to learn the Monte Carlo method for approximating an integral that cannot be integrated
symbolically, and see an application of improper integrals. How can you use a game of chance to evaluate an integral, and what
12
do games of chance have to do with improper integrals? This module will give you insight into both of these issues. Read
Section 7.5 and 7.7 before beginning this module.
21. Use the Fourier Series to Approximate Discontinuous Functions and to Interpret Music
(Ch8_fs.nb)
The objective of this module is to use Mathematica to calculate Fourier series and to build even and odd Fourier representations
of selected functions. You will also get a chance to see how Fourier series can be used to build mathematical models of musical
tones, to look at their graphs, and even to play back the signal to hear how close our model is to the real thing. Read Sections 8.9
and 8.10 to prepare for this module.
13
30. Looking for Patterns and Applying the Method of Least Squares to Real Data
(Ch11_ff.nb)
The objective of this module is to minimize the sum of squared residuals to fit an arbitrary function to a set of data. Prerequisite
reading for this module is Section 11.7.
33. Take Your Chances: Try the Monte Carlo Technique for Numerical Integration in Three
Dimensions (Ch12_mc3.nb)
How can you use a game of chance to evaluate a multiple integral? That is just what you will do with this project. Using
Mathematica, you will generate random points within a fixed region and then estimate the volume of the desired portion by
considering the percentage of random points that fall within the boundaries of the desired portion. Since this will only estimate
the exact volume, you will also explore the accuracy of this method. Read Section 12.1 before beginning this module.
34. Means and Moments and Exploring New Plotting Techniques (Ch12_mm.nb)
The objective of this module is to extend the concept of the moments of a density function of a solid to applications in
probability and engineering. What do means and multiple integrals have to do with probabilities? How can the method of
moments be used to help determine whether or not an object will float in an upright position? These questions will be answered
as you explore this module. You will also get to practice new and interesting ways to plot functions. Read Sections 12.2 and 12.5
before beginning this module.
14
An Introduction to Mathematica
Computer Algebra System (CAS) Exercises
In this manual, you will find example exercises, similar to the CAS exercises in your text, and their corresponding solutions,
discussed and illustrated with Mathematica. To solve a given CAS exercise with Mathematica, first study the corresponding
example exercise in this manual and then use the example to guide you in solving the CAS exercise in your text.
But before attempting to solve the CAS exercises, spend a few minutes reading through this introduction to familiarize yourself
with the basic features, commands and structure of Mathematica. You are also strongly encouraged to complete the first
Mathematica module accompanying the Thomas' Calculus text entitled "An Overview of Mathematica" contained in the file
ChP_intr.nb.
Mathematica Arithmetic
You can think of Mathematica as a powerful calculator which can do exact as well as approximate arithmetic.
Addition, Subtraction, Multiplication and Division
The symbols , and s are used for adding, subtracting and dividing numbers, respectively. Here are three examples.
In[1]:=
Out[1]=
In[2]:=
Out[2]=
In[3]:=
Out[3]=
575754575849849894 748949854985944749598984
748950430740520599448878
87575750 489747598744894574949
489747598744806999199
99686868612732546598686500000000000 s 5000
19937373722546509319737300000000
The asterisk * or better yet, at least one space, is used to multiply numbers.
In[4]:=
6868868686 18234987271740
Out[4]=
125253733060463458733640
In[5]:=
6868868686 18234987271740
Out[5]=
125253733060463458733640
An Introduction to Mathematica
16
Powers
The ^ stands for the power.
In[6]:=
Out[6]=
55757 ^ 22
26217227822130734686061732698724649910044114252485611900573633503107377146737g
7455720035345978636911261049
Notice that the last output is such a large number that is fills up several lines! The following input was created by typing 109
Ctrl-^ 5.
In[7]:=
Out[7]=
1095
15386239549
Palettes
Mathematica comes with some standard palettes containing shortcuts to entering commands from the keyboard. A useful
palette, called BasicInput, contains shortcuts for computing powers, square roots, summations and much more. To open this
palette, pull down the File menu, choose Palettes and then select BasicInput. Drag BasicInput to the side of your current
notebook and if necessary, resize your notebook so that the notebook and palette are not overlapping.
r
To demonstrate how to use this palette, suppose you want to compute 390625 . In an Input cell, click on the button containr
ing f . Then enter 390625 and then execute the cell. Your input and output should look like the following.
In[8]:=
Out[8]=
r
390625
625
When using any palette key which requires more than one number such as the fraction ccffcc and f , use the Tab key to move
from one number to the next. For example, to compute 757555 s 5, use the button containing ccffcc in the palette. Enter 757555,
then press the Tab key and finally enter 5.
f
r
757555
In[9]:=
Out[9]=
cccccccccccccccccc
5
151511
r
27
r
Notice that Mathematica returns an exact answer. This may not always be helpful. For example, the following output is
identical to the input since Mathematica returns the exact answer in reduced from.
An Introduction to Mathematica
17
5899
In[11]:=
Out[11]=
ccccccccccccc
7
5899
ccccccccccccc
7
There are several ways of obtaining an approximate answer as shown in the following cells.
Mathematica will display an approximate answer if at least one number in the calculation contains a decimal points.
5899.
In[12]:=
Out[12]=
cccccccccccccccc
7
842.714
Placing //N immediately after a calculation will produce the same result.
5899
In[13]:=
Out[13]=
ccccccccccccc
ss
7
842.714
Instead of placing //N immediately after a calculation, you can instead place a calculation inside N[f].
In[14]:=
Out[14]=
5899
N$ ccccccccccccc (
7
842.714
5899
N$ ccccccccccccc , 15(
7
842.714
In[16]:=
Out[16]=
cccccccccc
125
5
At this point, 5 is the most recent result produced by Mathematica. So the following example will compute 52 .
In[17]:=
Out[17]=
%^2
25
The command %n represents the result on output line Out[n]. For example, the following command will subtract 1 from the
result in Out[15] (verify).
In[18]:=
Out[18]=
%15 1
841.714
An Introduction to Mathematica
With Mathematica, you can perform more than one calculation in a single cell by placing two calculations on separate lines
using the Enter key.
In[19]:=
r
23.1
29
Out[19]=
4.80625
Out[20]=
7
Assigning Names
Mathematica has two commands that can be used to assign names to values. One assignment command is called the equals
command ( ) and the other is the delayed equals command (: ). There is a subtle, yet very important difference between the
two commands which will be illustrated shortly.
Suppose we want to assign x the value of 2 and y the value of 3.
In[21]:=
Out[21]=
In[22]:=
Out[22]=
The number of letters in a name assigned to a value can be of any length as long as it does not begin with number and as long as
there are no spaces between any of the characters in the name.
For example, suppose you want to compute the product of x and y and assign the name prod to the result. Recall that the space
appearing between the x and the y represents multiplication.
In[23]:=
Out[23]=
prod
x y
If you wish to see the value of prod again, just type in the name and execute the cell.
In[24]:=
Out[24]=
prod
6
x
y
Out[25]=
Out[26]=
10
9
10
prod
6
18
An Introduction to Mathematica
19
The reason the value of prod is still 6 is due to the use of the
ment
prod=x y
is immediately executed and the resulting value is assignment to prod. If instead you had execute the assignment
prod:=x y
then the right hand side of the assignment statement will not actually be computed until prod appears later on in the input cell or
in some other input cell.
The Clear command removes assignments that you have made. It is always a good idea to clear an assigned name before
creating a new assignment for that name.
In[28]:=
Clear#prod'
Now the delayed equals := is used to assign prod to be the product of x and y.
In[29]:=
prod : x y
Since the current value of x and y are 9 and 10, respectively, then executing the following input cell produces a result of 90.
In[30]:=
Out[30]=
prod
90
Now suppose you change the value of x to 4. Then the value of prod changes as expected.
In[31]:=
Out[31]=
In[32]:=
Out[32]=
4
prod
40
Suppressing Output
Recall that more than one command can be placed in a single input cell as long as each new command starts on a new line.
In[33]:=
x 30
y 40
prod
Out[33]=
30
Out[34]=
40
Out[35]=
1200
Suppose you do not want the values of x and y displayed as output. Placing a semicolon (;) at the end of a line will suppress
the result of the current line from being displayed in the output.
An Introduction to Mathematica
In[36]:=
Out[38]=
x 90;
y 30;
prod
2700
Mathematica Commands
Built-In Commands and Constants
Mathematica commands consist of a string of letters beginning with a capital letter followed by a series of arguments enclosed
in square brackets. Two commands which you have already seen in this chapter are N and Clear. Here are a few more examples.
If m and n are integers, Range#m, n' produces a list of all the integers from m to n inclusive.
In[39]:=
Out[39]=
Range#1.1, 10'
1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, 8.1, 9.1
If list represents a list of numbers, then Min[list] will return the smallest number in list.
In[40]:=
Out[40]=
Min#%'
1.1
Plot#Cos#x' x, x,
S, 2 S'
2
1
-2
-1
-2
-3
-4
-5
Out[41]=
h Graphics h
Placing a semicolon after a command will suppress any output from being displayed. In studying the last output, the actual
output was not the graph itself, but rather the word -Graphics-. So placing a semicolon at the end of a plot command will
only suppress -Graphics- from being displayed.
20
An Introduction to Mathematica
21
In[42]:=
S
1
Plot$Sin$ cccc (, x, 0, cccc
x
2
0.5
0.25
0.5
0.75
1.25
1.5
-0.5
-1
In Mathematica, an equation such as cos+x/ x 0 is represented in Mathematica by Cos[x]-x==0. Since the cosine
function is a Mathematica command, it must begin with a capital letter and also note that a double equals sign (==) is used in a
Mathematica equation (a single equals sign represents an assignment command and therefore cannot be used). The following
FindRoot command locates a solution to cos(x)-x=0 near x 1.
In[43]:=
Out[43]=
FindRoot#Cos#x' x
0, x, 0, 2'
90 0.739085
Notice that the FindRoot command consists of two words (Find and Root) which are both capitalized. Notice there is no
space separating the two words. Mathematica will always capitalize the first letter in each word and will never leave any spaces
between the words in a single command.
Some Mathematica commands represent constants. For example the command Pi is S and E is Euler's number e. The following commands will display their approximate values.
In[44]:=
N#Pi'
N#E'
Out[44]=
3.14159
Out[45]=
2.71828
Rather than typing in commands from the keyboard, some commands can be entered from a standard palette. For example, in
the palette BasicInput, Pi is represented by S and E is represented by .
In[46]:=
N#S'
N#'
Out[46]=
3.14159
Out[47]=
2.71828
As another example, the command for computing the square root of a number x is Sqrt[x].
An Introduction to Mathematica
In[48]:=
Out[48]=
Sqrt#16'
4
But as seen earlier, a more natural way of computing square roots is the use the button containing
r
in BasicInput.
Command Options
Many Mathematica functions, especially the commands which produce graphs, contain options for enhancing the output. For
example, the option PlotStyle Thickness#.015' adjusts the thickness of the curve being plotted.
In[49]:=
-0.5
-1
-1.5
-2
In the following Plot command, two functions contained in brackets ..., x2 and x2 sin2 x are plotted simultaneously with an
option for changing the thickness of the first curve and the color of the second curve.
In[50]:=
-15
-10
-5
10
15
22
An Introduction to Mathematica
23
Help Menu
To see information about a given Mathematica command, enter a ? followed immediately by the name of the command.
In[51]:=
? FindRoot
FindRoot#lhs rhs, x, x0' searches for a numerical
solution to the equation lhs rhs, starting with x x0.
?? FindRoot
FindRoot#lhs rhs, x, x0' searches for a numerical
solution to the equation lhs rhs, starting with x x0.
Attributes#FindRoot'
HoldAll, Protected
Graphics`ImplicitPlot`
Once the package has been loaded into memory, the command ImplicitPlot is now defined and ready for use. It will plot
the graph of an equation as illustrated below. The PlotPoints30 option is used to make the plot the curve look less
2.4
choppy and the AspectRatio ! ccccccc
1.6 option changes the height to width ratio of the plot.
In[54]:=
ImplicitPlot$x2 y4
y2 x, x,
2.4
Creating Functions
You can create your own Mathematica commands. Since Mathematica commands always begin with a capital letter, you should
get in the habit of beginning the names of your commands with a lower case letter. The name of your command can be a string
of letters followed immediately by square brackets containing the variables in the function. An underscore _ is placed immediately after each variable on the left-hand side of the assignment statement to alert Mathematica to the fact that the a variable has
been declared. The assignment statement used here is , but a : could have also been used. (Sometimes the delayed equals :
will be preferred over the .) The following lines of input begin with a clear command since the variables used were assigned
specific values earlier in this notebook.
An Introduction to Mathematica
In[55]:=
24
Clear#x, y';
f#x_' x2 Sin#x'2 ;
The variable x is called a dummy variable since it can be replaced by any other variable or number.
In[57]:=
Out[57]=
f#y'
y2 Sin#y'2
Recall that variables can be a string of letters. So in the following input, the dummy variable x is replaced with fred and so
every occurrence of x in the function is replaced with fred.
In[58]:=
Out[58]=
f#fred'
fred2 Sin#fred'2
You can also evaluate the function for a given value such as x
In[59]:=
f#S s 2'
Plot#f#x', x,
ccS2cc
5 S, 5 S';
Sc
cccccc
2
Out[59]=
200
150
100
50
-15
-10
-5
10
15
Before redefining a function, it is always a good idea use the Clear command to clear out the current definition of the function.
In the following, the function f is redefined to equal x2 4 . Abs is the absolute value command.
An Introduction to Mathematica
25
In[61]:=
Clear#f';
f#x_' Abs#x2 4';
Plot#f#x', x, 3, 3';
5
4
3
2
1
-3
-2
-1
Lists
Definition of a List
One of the most important structures in Mathematica is a list. A list is an ordered array of elements contained inside braces ....
Here is an example of a list of numbers.
1, 2, 3, 4, 5
In[64]:=
Out[64]=
1, 2, 3, 4, 5
Notice that the elements of the list are separated by commas. As the following example shows, a list does not need to just
contain numbers.
In[65]:=
Out[65]=
S
x, 1, 2, S
x, 1, 2,
The list just created contains three elements: an unassigned variable x, a list 1, 2 and the number S.
Creating Lists
A list can be created and assigned a name.
In[66]:=
Out[66]=
first4
1, 2, 3, 4
1, 2, 3, 4
The Table command can be used to create a list. For example, suppose we want to create a list containing the first 15 positive
integers. The command Table[a[i],{i,1,n}] will create a list of the form {a[1], a[2], ..., a[n]}. Here are
couple of examples.
An Introduction to Mathematica
In[68]:=
Out[68]=
In[69]:=
Out[69]=
pts
Table#x2 ,
x, 1, 10'
Given a list y1 , y2 , y3 , ..., yn }, the ListPlot command can be used to plot the points +1, y1 /, +2, y2 /, ..., +n, yn /.
In[70]:=
ListPlot#pts';
100
80
60
40
20
10
The points are difficult to see, so an option is added to make the points for visible.
In[71]:=
10
Next, the Table command is used to create a list of lists, each containing two numbers.
In[72]:=
Out[72]=
newpts
Table$x,
r
1 x2 , x,
1, 1, .25(
0., 1., 0.25, 0.968246, 0.5, 0.866025, 0.75, 0.661438, 1., 0.
26
An Introduction to Mathematica
27
In the list newpts, each list of two points can be thought of as an ordered pair which can then be plotted.
In[73]:=
-1
-0.5
0.5
ListPlot#newpts, PlotJoined
! True';
1
0.8
0.6
0.4
0.2
-1
-0.5
0.5
pts
1, 4, 9, 16, 25, 36, 49, 64, 81, 100
To extract the ith element in the list, use the command pts[[i]].
In[76]:=
Out[76]=
pts##9''
81
An Introduction to Mathematica
In[77]:=
Out[77]=
newpts
0., 1., 0.25, 0.968246, 0.5, 0.866025, 0.75, 0.661438, 1., 0.
Executing newpts[[i]] will extract the ith element of the list which itself is a list.
In[78]:=
Out[78]=
newpts##2''
0.75, 0.661438
Executing newpts[[i,j]] will return the jth element in the ith list. For example, the following command extracts the 2nd
element in the fourth list contained in newpts.
In[79]:=
Out[79]=
newpts##4, 2''
0.968246
Here is another example where the first element in the last is extracted.
In[80]:=
Out[80]=
newpts##9, 1''
1.
sol
FindRoot#x2 3
0, x, 2'
x 1.73205
Notice that the output is a list containing x1.73205 and this is the only element in the list.
In[82]:=
Out[82]=
sol##1''
x
1.73205
The single element in the list can be divided into two parts. The first part is x and the second part is 1.73205.
In[83]:=
Out[83]=
In[84]:=
Out[84]=
sol##1, 1''
x
sol##1, 2''
1.73205
28
An Introduction to Mathematica
29
In[85]:=
Out[85]=
polysol
NSolve#x4 3 x2 x
x 1.87939, x
0, x'
The solution consists of a list of 4 lists. For example, to extract the third list, use the following command.
In[86]:=
Out[86]=
polysol##3''
x 0.347296
The third element is also a list containing one element, x0.347296 which is extracted as follows.
In[87]:=
Out[87]=
polysol##3, 1''
x
0.347296
The actual third solution is the second part of x0.347296 which can therefore be obtained by executing the following command.
In[88]:=
Out[88]=
polysol##3, 1, 2''
0.347296
polysol##4, 1, 2''
1.53209
Creating Animations
The Table command used to form lists can also be used to form a list of frames in a graphics movie which can then be animated with Mathematica.
To illustrate how to create a movie, the add-on command PolarPlot contained in the Graphics package will be used.
In[90]:=
Graphics`Graphics`
Suppose you want to graph the equation r cos+5 T/ in the polar coordinate system. The following input will do this where the
option PlotRange->{{-1,1},{-1,1}} instructs Mathematica to plot the graph with the horizontal axis ranging from 1
to 1 and the vertical axes ranging from 1 to 1. The other option given here is Ticks->None which will leave the axes unlabeled.
An Introduction to Mathematica
In[91]:=
PolarPlot#Sin#5 T',
T0
T, 0, T0 },PlotRange->{{-1,1},{-1,1}}, Ticks->None];
...,
To animate the created frames, double click on top of any one of the given frames.
In[92]:=
polarframes
Table$PolarPlot#Sin#5 T',
PlotRange !
T, 0, T0 ,
S
S
1, 1, 1, 1, Ticks ! None', T0 , ccccccc , S, ccccccc
12
12
30
An Introduction to Mathematica
31
If you would rather just see the frames all at once on the screen, we can take the list of 12 frames just created and divide the list
into a list of 3 lists using the Partition command.
In[93]:=
Out[93]=
framesdisplay
Partition#polarframes, 4'
An Introduction to Mathematica
In[94]:=
32
Show#GraphicsArray#framesdisplay'';
For a more sophisticated example, suppose you want to create a movie illustrating the relationship between the unit circle and
the sine curve. The purpose of the following example is to show you the power of animation, so don't worry about understanding all of the details.
First, a plot of y sin+x/ is created and given the name sincurve. The option DisplayFunction->Identity will
2
suppress the graph from being displayed for now and the option AspectRatio ! cccccccc
2 S2cc produces a graph whose ratio of
height to width is 2 to 2 S 2. The other options have been described previously in this chapter.
In[95]:=
sinecurve
PlotRange !
AspectRatio !
Next, a unit circle is created centered at + 1, 0/ with a radius of 1 with the Circle command. The Graphics command is
added so that the graph of the circle can be plotted later on with the Show command.
In[96]:=
cir
1, 1';
In the following input cell, a list is created where each element in the list is a plot of the points
+ 1, 0/, +cos+t / 1, sin+t //, +t, sin+t// are joined together, for t
cccc16Scc , cccc216cScc , cccc316cScc , ..., 2 S, using the ListPlot command
described earlier in this chapter.
In[97]:=
cirptslines
PlotRange !
AspectRatio !
S
S
2
cccccccccccccccc , Ticks ! None, PlotJoined ! True(, t, ccccccc , 2 S, ccccccc
2S2
16
16
Now the Table command is used to show the frames of the movie. Since the option DisplayFunction->Identity was
used in the previous commands to suppress the graphics output, the command DisplayFunction->$DisplayFunction
must now be used to instruct Mathematica to show the graphics previously hidden. (Only the first frame of the movie is shown
here to save space.)
An Introduction to Mathematica
33
In[98]:=
...,
7 +3
4/
49
mylist
S, , 1
S, , 1
Square brackets [...] are used in defining functions and evaluating built-in, add-on and defined functions.
In[103]:=
Out[104]=
g#x_' x Sin#x';
g#S s 2'
1
S
cccc
2
An Introduction to Mathematica
In[105]:=
Out[105]=
34
6S
Cos$ cccccccc (
5
1
cccc , 1 r
50
4
mylist##2''
Do not attempt to interchange these symbols! For example, using round brackets instead of square brackets when defining or
evaluating a function will produce an undesired result.
In[107]:=
Out[107]=
g +S/
gS
In this case, a right curly bracket was forgotten and can be easily fixed.
In[108]:=
0.5
-0.5
-1
In the following example, study the warning message. In this case, there is absolutely nothing wrong with defining a list the
name list, but Mathematica notices that this name is nearly the same as a Mathematica command called List with a capital L. In
this case, you can ignore the warning message and move on. Therefore, not all warning messages should be interpreted as
error messages.
35
In[109]:=
An Introduction to Mathematica
list
1, 2, 4
1, 2, 4
DayOfWeek#1962, 6, 6'
Out[110]=
DayOfWeek#1962, 6, 6'
The command did not work because it was not loaded into memory first. The command is contained in a package called
Calender inside a folder named Miscellaneous. Now the package is loaded and a warning message occurs.
In[111]:=
Miscellaneous`Calendar`
DayOfWeek::shdw : Symbol DayOfWeek appears in multiple contexts
Miscellaneous`Calendar`, Global`; definitions in context
Miscellaneous`Calendar` may shadow or be shadowed by other definitions.
Suppose you ignore the warning message and you try to execute DayOfWeek again. Nothing happens!
In[112]:=
DayOfWeek#1962, 6, 6'
Out[112]=
DayOfWeek#1962, 6, 6'
In order to get the DayOfWeek command defined in the package to work correctly, you must first use a command called
Remove.
In[113]:=
Remove#DayOfWeek'
DayOfWeek#1962, 6, 6'
Wednesday
11
An Introduction to Mathematica
If N was not a reserved word, then the output of the following input statement would be 2.
In[116]:=
Out[116]=
If you wanted a quick reminder of the N command (introduced earlier), execute ?N.
In[117]:=
?N
N#expr' gives the numerical value of expr. N#
expr, n' attempts to give a result with ndigit precision.
One way to resolve the problem would be to use a lower case letter.
In[118]:=
n
n
Out[119]=
1 1;
36
37
In[120]:=
An Introduction to Mathematica
2.617993877991494`*^-7.
Plot::plnr :
sin#x' is not a machinesize real number at x
0.25488992540742256`.
Plot::plnr :
sin#x' is not a machinesize real number at x
0.5328694051959509`.
General::stop :
Further output of Plot::plnr will be suppressed during this calculation.
1
0.8
0.6
0.4
0.2
0.2
Out[120]=
0.4
0.6
0.8
h Graphics h
In the following input cell, the first letter is capitalized, but since the FindRoot command consists of two words (i.e., Find
and Root), the letter r should instead be R.
In[121]:=
Out[121]=
This concludes your brief introduction to Mathematica. As you proceed through the following chapters, you may want to refer
back to this chapter on occasion.
f +x/ near x
x0 and to then
Plot[f[x],{x,a,b}]
will plot the graph of the function f +x/ on the interval #a, b'. Adding the PlotRange option to form the command
Plot[f[x],{x,a,b},PlotRange->{c,d}]
will plot the graph of the function f +x/ with the range of y values limited to the interval #c, d'. To compute limxx0 f +x/ symbolically with Mathematica, use the command
Limit #f#x', x ! x0 '.
sin x
Example: Estimate limx0 cccccccc
cc by completing the following steps:
x
(a) Plot the function near the point x0 being approached and from your plot, guess the value of the limit.
(b) Evaluate the limit symbolically.
sin x
Part (a) First we plot the function and from the graph you can estimate limx0 cccccccc
cc
x
1.
In[1]:=
Sin#x'
Plot$ cccccccccccccccccc , x, 2, 2, PlotRange ! 0, 1(;
x
1
0.8
0.6
0.4
0.2
-2
-1
Part (b) To verify your guess in part (a), you can evaluate the limit with Mathematica.
In[2]:=
Out[2]=
Sin#x'
Limit$ cccccccccccccccccc , x 0(
x
1
39
40
2 being approached and guess the value of limxx0 f +x/. Then verify your
L H and y2
x 32
cccccccc
cccccc near x0 .
x2
5
(c) From your graph in part (b), estimate G ! 0 such that for all x
0 x x0 G f +x/ L H.
Test you estimate by plotting f , y1 and y2 over the interval 0 x x0 G. For your viewing window, use
x0 2G x x0 2G and L 2H y L 2H.
Part (a) In the following input cell, the current definition of f +x/ is cleared, then redefined and plotted on #1.5, 2.5'. It appears
that the limit is 80.
In[3]:=
Clear#f';
x5 32
ccccccccccccccccc ;
x2
Plot#f#x', x, 1.5, 2.5';
f#x_' :
120
100
80
1.6
1.8
2.2
2.4
Limit#f#x', x 2'
80
Part (b) In the following input cell, the value of H is set equal to 0.2 and then the functions f , y1
plotted together.
In[5]:=
80 H and y2
80 H are
H : 0.2;
y1 : 80 H;
y2 : 80 H;
Plot#f#x', y1, y2, x, 1.99, 2.01,
PlotStyle ! RGBColor#0, 0, 0', RGBColor#0, 0, 1', RGBColor#0, 0, 1'';
80.75
80.5
80.25
1.99
1.995
2.005
2.01
79.75
79.5
79.25
Part (c) A new graph is now plotted over a smaller domain in order to estimate the value of G.
41
42
In[6]:=
80.2
1.996
1.998
2.002
2.004
79.8
79.6
From the graph, you can see that if we choose G
In the following input cell, a box is defined in which the function f should pass through without ever crossing the top or the
bottom of the box. In each of the assignment statements, a delayed equals (:=) is used so that x1, x2 and GHbox are not are not
assigned values until you call them later in the session.
In[7]:=
x1 : 2 G;
x2 : 2 G;
GHbox :
ListPlot#x1, y1, x1, y2, x2, y2, x2, y1, x1, y1, PlotJoined ! True,
PlotStyle ! RGBColor#0, 0, 1', DisplayFunction ! Identity';
The names gr1 and GHbox were assigned to the previous two graphs, so the command
Show[{gr1,GHbox}]
can be used to show the two graphs simultaneously.
Suppose instead that you had selected G to be 0.003. From the graph below, you can see that the function lies outside the
interval #80 H, 80 H'.
In[8]:=
G .003;
Show#gr1, GHbox, PlotRange ! 2 2 G, 2 2G, 80 2 H, 80 2 H';
80.4
80.2
1.994
1.996
1.998
2.002
2.004
79.8
79.6
In[9]:=
Clear#G';
G .002;
Show#gr1, GHbox, PlotRange ! 2 2 G, 2 2G, 80 2 H, 80 2 H';
80.4
80.2
1.996
1.998
2.002
2.004
79.8
79.6
So if G
43
44
Clear#f';
f#x_' : +1 x/1sx ;
Plot#f#x', x, 1, 1';
140
120
100
80
60
40
20
-1
-0.5
0.5
Choosing a smaller interval in the Plot command will lead to a better estimate of the limit. From the following graph, you
can see that limx0 f +x/ 2.71828.
In[11]:=
-0.0001
-0.00005
0.00005
0.0001
2.71815
In[12]:=
Clear#f';
Log#x2 '
ccccccccccccccccccccc ;
x2
Plot#f#x', x, 30, 30, PlotRange .5, .5';
f#x_' :
0.4
0.2
-15
-10
-5
10
15
-0.2
-0.4
0, limx
0, limx0 f +x/
.
45
(a) Define the difference quotient q at a general point x, with general stepsize h.
(b) Take the limit of the difference quotient as h 0 and let m+x/ represent the function obtained from computing the limit.
(c) On the same graph, plot m+x/ together with q for values of h
(d) Plot y
3.
(e) Substitute various values for x larger and smaller than x0 into m+x/.
Part (a) Begin by defining f and q.
In[1]:=
q
Out[1]=
x3 3x2 4;
f#x h' f#x'
Simplify$ ccccccccccccccccccccccccccccccccccccc (
h
f#x_'
h2 3 h +1 x/ 3 +2 x/ x
Part (b) From the simplified form of q found in part (a), can you determine of q as h 0?
Your result can be verified using the Limit command.
In[2]:=
Out[2]=
m#x_'
Limit#q, h 0'
3 +2 x/ x
Part (c) The difference quotient is plotted below for the specified values of h and then m+x/ is plotted.
The ReplaceAll command (/.) is used to replace q with specific values of h. For example, q/.h->1 will output the value
of q when h is 1. Since the option DisplayFunctionIdentity is used to suppress all the individual graphs from being
displayed, then DisplayFunction$DisplayFunction must be an included option in the Show command to display
all the functions on the same graph. The option DisplayFunction$DisplayFunction instructs Mathematica to
display a previously suppressed graph. Also note that RGBColor[1,0,0],RGBColor[0,1,0] , and RGBColor[0,0,1] represent the
colors red, green and blue, respectively.
Study the following input and output. What is happening to the graph of q as h 0? Why?
In[3]:=
47
50
40
30
20
10
Part (d) Since m+x0 / represents the slope of the line tangent to y f +x/ at +x0 , y0 /, the equation of the tangent line at +3, f +3// is
easily found and plotted together with y f +x/ in the following cell.
In[4]:=
y m#3' +x 3/ f#3';
Plot#f#x', y, x, 0, 5';
10
5
1
-5
-10
-15
-20
Part (e) The command Table[m[x],{x,1,5,.2}] will form a list m#1', m#1.2', m#1.4', ..., m#5'.
Compare the resulting numbers with the graph of y
y f +x/?
f +x/. Do these numbers make sense when compared with the graph of
48
In[5]:=
Out[5]=
Out[6]=
Clear#f';
f#x_' 5x3 15x 2;
f '#x'
15 15 x2
D#f#x', x'
Out[7]=
15 15 x2
Computing higher order derivatives such as f ''+x/, f '''+x/ and so forth are just as easy. The command D[f[x],{x,n}] will
compute the nth derivative of f +x/. Study the following example.
In[8]:=
Out[8]=
In[9]:=
Out[9]=
f ' '#x'
30 x
D#f#x', x, 3'
30
Out[10]=
Clear#x, y, t';
x#t_' t; y#t_' 160 t 16 t2 ;
rock Table#0, y#t', t, 0, 10, .4'
0,
0,
0,
0,
0, 0, 61.44, 0, 117.76, 0, 168.96, 0, 215.04, 0, 256., 0, 291.84,
322.56, 0, 348.16, 0, 368.64, 0, 384., 0, 394.24, 0, 399.36,
399.36, 0, 394.24, 0, 384., 0, 368.64, 0, 348.16, 0, 322.56,
291.84, 0, 256., 0, 215.04, 0, 168.96, 0, 117.76, 0, 61.44, 0, 0.
49
The ListPlot command is now used to plot the points one at a time. The output (of which only one frame is shown in the
hard copy of this manual), can be animated by double-clicking on any one of the frames. The option PlotStyle->PointSize[.02] is used to increase the displayed size of each point. Also note that rock[[i]] represents the ith ordered pair in
the list rock.
In[11]:=
10
In the following, a set of ordered pairs +x+t/, y+t// where x+t/ t and y+t/ 160t 16t2 is plotted on point at a time together with
(0,y(t)). Again, only the first frame is displayed below in the hard copy of this manual. The frames can be animated to show
how the height of the rock corresponds to the point of the graph of s 160t 16t2 .
In[12]:=
10
Graphing the position function s+t /, the velocity function v +t / and the acceleration function a+t /.
Here is an example of how to use Mathematica to plot a position vector with its velocity and acceleration functions.
50
160t 16t2 , plot its graph together with the velocity and acceleration functions.
The solution is a simple as defining the position function and then plotting it with its first and second derivatives. What
information does the graph reveal?
In[13]:=
s#t_' 160t 16 t2 ;
Plot#s#t', s '#t', s ' '#t', t, 0, 10';
400
300
200
100
10
-100
Clear#q';
Cos#x h' Cos#x'
cccccccccccccccc ;
q cccccccccccccccccccccccccccccccc
h
p1 Plot#q s. h 1., x, 0, 2 S';
p2 Plot#q s. h .5, x, 0, 2 S';
p3 Plot#q s. h .2, x, 0, 2 S';
0.5
-0.5
-1
1
0.5
-0.5
-1
1
0.5
-0.5
-1
51
52
Parametrized Curves
The following example is similar to Exercises 75 - 80 in your text.
Example: Consider the parametrized curve whose equations are x+t/
(c) Find an equation for the tangent line to the curve at the point where t0
4.
Part (a) The parametric curves are defined and then plotted using the following commands.
In[15]:=
Clear#x, y';
x#t_' t Cos#t'; y#t_' t Sin#t';
funplot ParametricPlot#x#t', y#t', t, 0, 6S';
17.5
15
12.5
10
7.5
5
2.5
5
10
15
20
dy
dy
d y
cc and cccc
cccccc are defined. Since cccc
cc is used in part (c) to find the slope of a tangent line, the derivative is defined
Part (b) Next, cccc
dx
dx
dx2
to be yprime[t] in the following cell.
2
In[16]:=
yprime#t_'
Out[16]=
1 Cos#t'
cccccccccccccccccccccccccc
1 Sin#t'
y '#t'
cccccccccccccccc
x '#t'
Out[17]=
yprime '#t'
Simplify$ cccccccccccccccccccccccccccccc (
x '#t'
t
2 Sin# ccc
c'
2cccccccccccccccc
cccccccccccccccccccccccccccccccc
cccc
5c
t
t
+Cos# ccc
2c ' Sin# ccc
2c '/
Part (c) Now the tangent line is computed and then the Show command is used to show the graph of the parametrized curve
and the tangent line simultaneously.
In[18]:=
In[19]:=
10
15
20
dy
cc .
(a) Solve the equation of y and then differentiate the result to find cccc
dx
dy
(b) Use implicit differentiation to find cccc
dxcc and verify that the result agrees the derivative found in part a.
r
703
ccccccc 0.
(c) Plot the graph of the equation together with the line tangent to the curve at , cccc74 , cccccccc
16
Part (a) Begin by assigning the equation the name eq and then use the Solve command to solve the equation for y.
In[20]:=
Out[20]=
Clear#x, y, eq';
eq +x 1/4
x2 y2 ;
solutions Solve#eq, y'
r
r
y 1 4 x 5 x2 4 x3 x4 , y 1 4 x 5 x2 4 x3 x4
The solutions for y can be extracted using the commands solutions[[1,1,2]] and solutions[[2,1,2]]. Next, the
dy
D command is used to find and simplify cccc
dxcc for each solution.
In[21]:=
Out[21]=
2 5 x 6 x2 2 x3
cccccccccccccccccccccccccccccccc
cccccccccccccccc
cccccccc
ccccccc
r
1 4 x 5 x2 4 x3 x4
Out[22]=
2 5 x 6 x2 2 x3
cccccccccccccccccccccccccccccccc
cccccccccccccccc
cccccccc
ccccccc
r
1 4 x 5 x2 4 x3 x4
53
54
dy
cc using implicit differentiation. The result is an equation which is arbitrarily
Part (b) The Dt command can be used to find cccc
dx
assigned the name implicitder.
In[23]:=
Out[23]=
implicitder
4 +1 x/3
Dt#eq, x'
2 x 2 y Dt#y, x'
dy
cc . The Mathematica command
The Mathematica notation Dt[y,x] above represents cccc
dx
Solve[implicitder,Dt[y,x]]
in the following input cell will solve the equation for Dt[y,x].
In[24]:=
Out[24]=
impsolution
2 5 x 6 x2 2 x3
cccccccccccccccc
Dt#y, x' cccccccccccccccccccccccccccccccc
y
In[25]:=
Out[25]=
4 10 x 12 x2 4 x3
2 5 x 6 x2 2 x3
cccccccccccccccc
cccccccccccccccc
cc cccccccccccccccccccccccccccccccc
cccccccccccccccc
cccccccc
ccccccc
cccccccccccccccccccccccccccccccc
r
r
2 1 4 x 5 x2 4 x3 x4
1 4 x 5 x2 4 x3 x4
Out[26]=
4 10 x 12 x2 4 x3
2 5 x 6 x2 2 x3
cccccccccccccccc
cccccccccccccccc
cc cccccccccccccccccccccccccccccccc
cccccccccccccccc
cccccccc
ccccccc
cccccccccccccccccccccccccccccccc
r
r
2 1 4 x 5 x2 4 x3 x4
1 4 x 5 x2 4 x3 x4
Part (c) To plot the equation, the ImplicitPlot command found in the package called ImplicitPlot, must be loaded into
memory first using the Needs command.
In[27]:=
Graphics`ImplicitPlot`
eqgraph ImplicitPlot#eq, x, 4, 4';
1.5
0.5
0.5
1.5
2.5
-0.5
-1
-1.5
r
r
703
703
ccccccc 0, +x0 , y0 / is assigned the value , cccc74 , cccccccc
ccccccc 0 and then the
To find the equation of the line tangent to the equation at , cccc74 , cccccccc
16
16
dy
c
c
ReplaceAll
is
replaced
with
this
ordered
pair
using
the
(/.)
command.
implicit solution for cccc
dx
In[29]:=
x0
m
Out[29]=
r
7
703
cccc ; y0 cccccccccccccccc ;
4
16
impsolution##1, 1, 2'' s. x x0 , y y0
29
cccccccc
cccccccccc
r
2 703
Now the tangent line is formed and the plotted. The Show command is then used to plot the implicit curve and the tangent line
together on a single graph.
55
56
In[30]:=
Clear#x, y';
y m+x x0 / y0 ;
tangraph Plot#y, x, 0, 3, DisplayFunction ! Identity';
Show#eqgraph, tangraph';
0.5
-1
1.5
2.5
3
r
x2 x 1 sin+x/ and the closed interval #1, 1', perform each of the following.
(a) Plot the function over the interval to see its general behavior there.
(b) Find interior points where f '
0.
58
In[1]:=
3
r
f#x_' x2 x 1 Sin#x';
Plot#f#x', x, 1, 1';
1
0.8
0.6
0.4
0.2
-1
-0.5
0.5
-0.2
In[3]:=
-1
-0.5
sol1
0.5
0.95 and x
FindRoot#f '#x'
0.4. The following FindRoot command will locate the negative root.
0, x, .95'
x 0.913313
From the graph of f '+x/, it is clear that another root lies near x
In[5]:=
Out[5]=
sol2
FindRoot#f '#x'
x 0.394546
0, x, .4'
0.4.
Part (c) From observing the function f '+x/ in the following output cell, you can see that f '+x/ is never undefined at point in
the interior of #1, 1'.
In[6]:=
Out[6]=
Simplify#f '#x''
x +6 7 x/
cccccccccccccccccccccccc
cccc Cos#x'
3 +1 x/2s3
Part (d) Now we evaluate the function at the two values of x where f '+x/ 0 and at the endpoints. Note that N[f[x]] or
equivalently, f[x]//N will give a numerical approximation of the value of f +x/. Recall that the command sol1[[1,2]]
will extract the first solution found in part (b).
In[7]:=
f#sol1##1, 2'''
f#sol2##1, 2'''
f#1' ss N
f#1' ss N
Out[7]=
1.1607
Out[8]=
0.210473
Out[9]=
0.841471
Out[10]=
0.41845
Part (e) From observing the output in part (d), you can see that on the interval #1, 1', the function has an absolute maximum
of approximately 1.1607 at x 0.913313 and an absolute minimum value of about 0.210473 at x 0.394546.
Out[11]=
sol
3
DSolve$y '#x' m x +x 1/2 , y#x', x(
1s3
9
3x
3 x2 ]
L
M ccccccc
cccccccc cccccccccc \
C#1'
20
8 ^
N 40
The solution is extracted using the command sol[[1,1,2]]. The value C[1] in the solution represents an arbitrary
constant. In the following input cell, the command /. is used to replace C[1] with specific values and the solution is then
plotted for these specific values of C[1].
59
60
In[12]:=
-4
-2
-2
Now suppose you want to find and plot the solution passing through + cccc12 , 2/. Begin by letting y equal the solution found earlier
with x replaced with cccc12 .
In[13]:=
Out[13]=
1
sol##1, 1, 2'' s. x cccc
2
33
cccccccccccccccc
cccc C#1'
160 22s3
y
The command Solve[eqn, var] will attempt to find the solutions to the variable var in the equation eqn. Therefore you can
use the Solve command to find the value of the constant C[1] for which y=-2.
In[14]:=
Out[14]=
const
Solve#y
2, C#1''
1
C#1' cccccccccc +640 33 21s3 /
320
Now the specific solution is plotted by replacing C[1] with the constant just obtained.
In[15]:=
61
-4
-2
-1
-2
The following example is similar to the CAS exercise found in Section 3.3.
a
cccccccc
cccccc with b ! 0 and a 0.
1bx2
f +x/ for a
62
In[16]:=
Clear#a, b, c, f';
a x2
cccccccccccccccccc ;
1 b x2
Plot#f#x' s. a 1, b 1, f#x' s. a .5, b 1,
f#x' s. a .25, b 1, f#x' s. a 0, b 1, f#x' s. a .25, b 1,
f#x' s. a .5, b 1, f#x' s. a 1, b 1, x, 3, 3';
f#x_'
0.75
0.5
0.25
-3
-2
-1
-0.25
-0.5
-0.75
Part (b) Now the frames of a movie are produced using the Table command (only the first frame of the movie is shown in the
hard copy of this manual). After the frames have been produced, you can double-click on any frame to produce an animation.
What do the graphs tell you about the number of inflections points and the concavity of the graph of y f +x/?
In[19]:=
Table#
Plot#f#x' s. a a0 , b 1, x, 3, 3, PlotRange ! 1, 1', a0 , 1, 1, .1';
1
0.75
0.5
0.25
-3
-2
-1
-0.25
-0.5
-0.75
-1
Part (c) The first derivative is computed and simplified in the following cell. From observing the output, it is clear that
f '+x/ 0 when x 0 and since b ! 0, the derivative is never undefined. Furthermore, if a ! 0, then f '+x/ ! 0 when x ! 0 and
f '+x/ 0 when x 0. Hence f is increasing on +0, / and decreasing on +0, / when a ! 0. What if a 0?
In[20]:=
Out[20]=
63
Simplify#f '#x''
2ax
cccccccccccccccccccccccc2cc
+1 b x2 /
Part (d) The second derivative is displayed in the following output and then the candidates for inflection points are obtained
using the Solve command.
In[21]:=
Out[21]=
In[22]:=
Out[22]=
g#x_'
a +2 6 b x2 /
cccccccccccccccccccccccccccccccc
+1 b x2 /3
Solve#g#x'
0, x'
1
1
x cccccccc
rcccccccc
rcc
rcccccccc
rcc , x cccccccc
3 b
3 b
1
1
1
To determine the inflection points and the concavity of the curve, the intervals ,, cccccccc
rcccc 0, , cccccccc
rcccc , cccccccc
rcccc 0 and
rcccccccc
rcccccccc
rcccccccc
1
, cccccccc
rcccc , 0 are examined by computing the value of the second derivative at x
rcccccccc
3
In[23]:=
2
2
cccccccc
cccccc , 0, and cccccccc
cccccc .
r r
r r
3
2
g$ cccccccc
rcccccccc
rcccc (
3 b
g#0'
2
g$ cccccccc
rcccccccc
rcccc (
3 b
Out[23]=
162 a
cccccccccccccc
343
Out[24]=
2a
Out[25]=
162 a
cccccccccccccc
343
From the output, it can be seen that for a given value of a, the second derivative changes signs at x
So the points of inflection occur at x
1
cccccccc
rcccc and x
rcccccccc
1
cccccccc
rcccc .
rcccccccc
3
1
cccccccc
rcccc . If a ! 0, where is the graph of f concave up and where is it
rcccccccc
1
cccccccc
rcccc and x
rcccccccc
1.
(a) Find the linearization L of f at the point a and plot f and L on a single graph.
(b) Plot the absolute error f +x/ L+x/ over I and find its maximum value.
(c) For the graph in part (b), estimate as large a G>0 as possible satisfying
x a G f +x/ f +a/ H
64
for H
Part (a) The function and its corresponding linearization are given below along with a plot of their graphs.
In[26]:=
Clear#f';
r
x1;
f#x_'
L#x_' : f '#1'+x 1/ f#1';
Plot#f#x', L#x', x, 0, 3';
2
1.8
1.6
1.4
1.2
0.5
1.5
2.5
Part (b) The graph of f +x/ L+x/ is shown next. The Mathematica command Abs[exp] represents the absolute value of an
expression exp.
In[30]:=
0.5
1.5
2.5
Part (c) From the graph given in part (b), it appears that G 0.5 is needed in order for f +x/ f +a/ 0.01 when x a G.
To see if G is small enough, a graph of y f +x/ f +a/ and y 0.01 over the interval x 1 0.5 (which is equivalent to
#0.5, 1.5' ) is given in the following output cell.
In[31]:=
0.6
0.8
1.2
1.4
0.45.
0.6
0.8
1.2
1.4
It looks like the updated G-estimate still needs to be slightly smaller, say G
.44.
65
66
In[33]:=
0.6
So G
0.8
1.2
1.4
.01.
To find a rough approximation of the roots, the Plot function is used to graph y
In[34]:=
f +x/ first.
-2
-1
-1
-2
-3
It appears that there are two negative roots - one near 0.8 and 0.4. To use Newton's method, let g+x/
In[35]:=
f#x_'
g#x_'
Cos#5 x' x;
f#x'
x cccccccccccccccc ;
f '#x'
f +x/
ccccc .
x cccccccc
f '+x/
f +x0 /
cccccccc which is equivalent to x1
x0 cccccccc
f '+x0 /
67
g+x0 /.
g#.8'
0.769407
Therefore x1 0.769407. Now we find x2 by computing g+x1 /. The % symbol refers to the last output, therefore computing
g#%' will yield the value of x2 .
In[38]:=
Out[38]=
g#%'
0.767502
g#%'
0.767493
g#%'
0.767493
Since the values of x3 and x4 are identical to 6 decimal places, the smallest root approximately equals 0.767493. Can you find
the other two approximate roots using Newton's method?
Log#x' x
x x Log#x'
Notice that the general form of the antiderivative is x x ln x C and Mathematica does not include the constant C in the
answer above.
Solving Initial Value Problems
Example: Use Mathematica to solve the initial value problem
y'
5e3x , y+0/
10.
Begin by letting y #x' equal the antiderivative and add a c to the answer.
In[2]:=
Out[2]=
y#x_'
3 x
x c
5
5 E3 x
c ccccccccccccccc
3
cval
Solve#y#0'
10, c'
25
c ccccccc
3
Now the command cval[[1,1,2]] is used to extract the value of c in the following assignment statement.
In[4]:=
Out[4]=
cval##1, 1, 2''
25
ccccccc
3
69
Factor#y#x''
5
cccc E3 x +1 5 E3 x /
3
1
cc y+1/
e2x cccc
x2 ,
Out[6]=
In[7]:=
Out[7]=
In[8]:=
Out[8]=
In[9]:=
yprime#x_'
1 \
L 2 x cccccc
c]
M
] x c1
M
x2 ^
N
1
E2 x
c1 ccccccccccc cccc
2
x
sol
Solve#yprime#1'
4, c1'
1
c1 5 cccccccc2cc
2E
c1
sol##1, 1, 2''
1
5 cccccccc2cc
2E
Clear#y';
y#x_'
yprime#x' x c2
Out[9]=
E2 x
+1 10 E2 / x
c2 ccccccccccc cccccccccccccccccccccccc
ccccccc Log#x'
4
2 E2
In[10]:=
sol
Out[10]=
In[11]:=
Out[11]=
Solve#y#1'
2, c2'
3 +1 4 E2 /
cccc
c2 cccccccccccccccccccccccc
4 E2
c2
sol##1, 1, 2''
3 +1 4 E2 /
cccccccccccccccccccccccc
cccc
4 E2
y#x'
E2 x
3 +1 4 E2 /
+1 10 E2 / x
ccccccc Log#x'
ccccccccccc cccccccccccccccccccccccc
cccc cccccccccccccccccccccccc
2
2 E2
4
4E
2, y'+1/
x3 sin x on #1, S' and use Mathematica to perform the following steps.
+average value/ for x using the average value calculation in part (c).
Part (a) First, the function is defined and graphed over the given interval.
In[13]:=
f#x_' x3 Sin#x';
Plot#f#x', x, 1, S, PlotRange ! 0, S3 Sin#S'';
30
25
20
15
10
5
1.5
2.5
Part (b) The value of 'x is defined below where the greek letter ' was entered from the BasicInput palette. Then the Table
command is used to partition the interval and to evaluate the function at the midpoint of each subinterval.
70
71
In[14]:=
Out[14]=
S1
cccccccccccc ;
100
fvals Table#f#1 +i .5/'x', i, 1, 100'
'x
Part (c) For a given list lis, the Mathematica command Plus@@lis will compute the sum of all the numbers in the lis.
In[15]:=
Out[15]=
averageval
11.9734
Part (d): Solving f +x/ +average value/ for x is equivalent to solving f +x/ average value 0 for x. You can plot the
f +x/ +average value/ first to obtain the approximate location of the root and then use the FindRoot command to obtain the
root.
In[16]:=
15
10
5
1.5
2.5
-5
-10
In[17]:=
Out[17]=
x 2.23651
ba
cccccccccccc , recs, fungraph, intest ,
n
intest
recs ListPlot#Flatten#
Table#a +i 1/deltax, 0, a +i 1/deltax, f#a +i 1 m/deltax',
a i deltax, f#a +i 1 m/deltax', a i deltax, 0, i, 1, n', 1',
PlotJoined ! True, DisplayFunction ! Identity, PlotRange ! All';
fungraph Plot#f#x', x, a, b, DisplayFunction ! Identity,
PlotRange ! All';
Show#recs, fungraph, DisplayFunction ! $DisplayFunction';
Return#intest'(
In[19]:=
f#x_' : x3 1;
RiemannSum#1, 2, 6, .5'
1.2
Out[19]=
1.4
1.6
1.8
4.73958
The value of m in RiemannSum[a, b, n, m] can be any value between 0 and 1 inclusive. Repeat the command above,
but try different values of m and describe what is happening. For example, let m 1 and observe how the rectangles are
formed. What happens if you use m 0?
72
73
The Mathematica command Integrate[f[x],{x,a,b}] will attempt to evaluate a f +x/dx. A shortcut way of using the
f
Integrate command is to open the palette entitled BasicInput and then click on the button containing f f f.
2
In[20]:=
Log#x' x
1
Out[20]=
1 Log#4'
#0, 1' and use Mathematica to perform the following steps. Let
The solution to this example is straight forward. First the function F is defined.
In[21]:=
Clear#f';
f#x_' x Sin#2x' Cos#x'2 ;
x
F#x_'
f#t' t
0
Out[21]=
1
1
cccc cccc +2 x 2 x2 2 Cos#2 x' Sin#2 x'/
2
4
Now the approximate location of the root F '+x/ is found after first graphing the function to determine the approximate location
of the root.
In[22]:=
0.2
0.4
-0.5
-1
-1.5
In[23]:=
Out[23]=
0.6
0.8
x+x 1/+x 3/+x 4/. Use Mathematica to complete the following steps.
(a) Plot the curves together to determine the number of points of intersection.
(b) Determine where the curves intersect.
(c) Integrate f +x/ g+x/ over consecutive pairs of intersection values.
(d) Sum together the integrals found in part (c).
Part (a) Study the following input and output. How many points of intersection do you see?
In[24]:=
Clear#f, g';
f#x_' Sin#x'2 ;
g#x_' x+x 1/+x 3/+x 4/;
Plot#f#x', g#x', x, 1, 5';
10
8
6
4
2
-1
-2
Part (b) Solving f +x/ g+x/ is equivalent to solving f +x/ g+x/ 0. By plotting f +x/ g+x/, you can see the approximate
locations of the roots. One of the roots is 0 (why?) and the remaining roots can be found using the FindRoot command.
74
75
In[25]:=
-1
-2
-4
-6
-8
-10
In[26]:=
int2
int3
int4
Out[26]=
x 1.13558
Out[27]=
x 2.99652
Out[28]=
x 4.04794
Parts (c) and (d) Now you can integrate f +x/ g+x/ over consecutive pairs of intersection values and sum up the values
obtained.
int2##1,2''
In[29]:=
area1
+f#x' g#x'/ x
Out[29]=
1.78766
int3##1,2''
In[30]:=
area2
+g#x' f#x'/ x
int2##1,2''
Out[30]=
3.81784
int4##1,2''
In[31]:=
area3
+f#x' g#x'/ x
int3##1,2''
Out[31]=
In[32]:=
Out[32]=
1.6636
area1 area2 area3
7.26909
In[33]:=
Out[33]=
1.49365
b
If you want a command that will estimate a f +x/dx with the Trapezoidal rule for a given value of n, then execute the following
command to create the function. A picture is given illustrating the trapezoids formed by the Trapezoidal rule. The command
b
TrapPic#a, b, n' will use n subintervals to estimate a f +x/dx
In[34]:=
ba
cccccccccccc , traps, fungraph, intest ,
n
n1
\
h L
]
M
]
M
cccc M
2
f#a'
f#a i h' f#b']
];
M
2 N
i 1
^
If you don't care to see a picture, use the following command instead.
In[35]:=
n1
\
h L
]
M
]
M
cccc M
2
f#a'
f#a i h' f#b']
];
M
2 N
i 1
^
Return#intest'(
Here is an example.
ba
cccccccccccc , intest ,
n
76
77
In[36]:=
Clear#f';
f#x_' x ;
N#TrapPic#1, 1, 8''
2
1
0.8
0.6
0.4
0.2
-1
Out[36]=
-0.5
1.48597
N#TrapRule#1, 1, 8''
1.48597
0.5
In[1]:=
f#x_'
1
r
4 2
3
cccccccccccccc x ccc2c 1;
3
1 f '#x'2 x
Out[1]=
In[2]:=
Out[2]=
13
ccccccc
6
NIntegrate$
1 f '#x'2 , x, 0, 1(
2.16667
Comparing the Length of the Polygonal Path with the Length of a Curve
79
In[3]:=
f#x_' x3 ;
a 0; b 2; n 3;
ba
'x cccccccccccc ;
n
pts Table#a i 'x, f#a i 'x', i, 0, n';
polypath ListPlot#pts, PlotJoined ! True, PlotRange ! All,
DisplayFunction ! Identity, PlotStyle ! RGBColor#1, 0, 0'';
fungraph Plot#f#x', x, a, b, DisplayFunction ! Identity, PlotRange ! All';
Show#fungraph, polypath, DisplayFunction ! $DisplayFunction';
8
0.5
1.5
r
Part (b) The command Table$ 'x2 +f#a i 'x' f#a +i 1/'x'/2 , i, 1, n( will form a table whose
entries are the lengths of each line segment making up the polygonal path. Then we can add these lengths together using
Plus@@.
In[4]:=
Out[4]=
Plus Table$ 'x2 +f#a i 'x' f#a +i 1/'x'/2 , i, 1, n( ss N
8.57709
NIntegrate$
8.63033
1 f '#x'2 , x, 0, 2(
The purpose of the following example is it explore a function and its inverse
together with their derivatives.
f +x/ and y
c) Find the inverse (call it g) of f and then find the line tangent to g at + f +x0 /, x0 /. (Use Theorem 1.)
d) Plot f , g, the two tangent lines, the identity and the line segment joining the points +x0 , f +x0 // and + f +x0 /, x0 /.
Part (a) Study the following input and output.
81
In[1]:=
f#x_' Cos#x';
Plot#f#x', f '#x', x, 0, S s 2';
1
0.5
0.25
0.5
0.75
1.25
1.5
-0.5
-1
Part (b) The following two input cells show how to create a tangent line along with the graph of the tangent line and the
function.
In[2]:=
Out[2]=
In[3]:=
1
0.75
0.5
0.25
0.5
1.5
2.5
-0.25
Part (c) The Solve command is now used to find the inverse of f (ignore the warning message in the following output).
In[4]:=
invsol
Solve#y
f#x', x'
not be found.
Out[5]=
g#y_'
g#x'
invsol##2, 1, 2'';
ArcCos#x'
1
cccccccccccccccccccccccc ;
f '#S s 6'
LInv#x_' S s 6 m+x f#S s 6'/;
m
x are all plotted for later use. Ignore the warning messages.
The line segment joining the points +x0 , f +x0 // and + f +x0 /, x0 / is now created and then the required graph is displayed.
In[8]:=
S
S
S
S
ListPlot$ cccc , f$ cccc ( , f$ cccc (, cccc , PlotJoined ! True,
6
6
6
6
PlotStyle ! Thickness#.01', DisplayFunction ! Identity(;
segment
82
83
In[9]:=
0.8
0.6
0.4
0.2
0.2
0.4
0.6
0.8
Slope Fields
A package called PlotField, contained in a file called Graphics, contains a command called PlotVectorField which can
be used to plot the slope field of a differential equation.
In[10]:=
Graphics`PlotField`
r
xy and a graph of the solution curve passing through +0, 1/.
r
1
cccccc dy
First, the solution is found by first noting that the differential equation is equivalent to cccc
x dx. So you can begin by
r
Example: Obtain a slope field for the differential equation y'
assigning an arbitrary name (such as eq) to the equation after the antiderivative of each side has been computed.
In[11]:=
Out[11]=
eq
2
r
y
1t
r
y y
2 x3s2
c ccccccccccccccc
3
r
x x c
In[13]:=
Out[13]=
cval
c 2
cval##1, 1, 2''
2
The Solve command is used again to find the solution for y in terms of x.
In[14]:=
Out[14]=
sol
1
y cccc +9 6 x3s2 x3 /
9
Out[15]=
Clear#f';
f#x_' sol##1, 1, 2''
1
cccc +9 6 x3s2 x3 /
9
dirfield
PlotVectorField$1,
r
x y , x, 0, 1,
84
85
In[18]:=
1.8
1.6
1.4
1.2
0.2
0.4
0.6
0.8
and
y[i_]:=y[i-1] + f[x[i-1],y[i-1]] dx
Notice also that delayed equals (: ) are used for these two assignment statements since we do not want to evaluate the right
hand side of the equations until a specific value of i is used.
When Mathematica is then asked to compute y[3] for example, it will first compute y[0], y[1] and y[2] using the
assignment statements above. If you then have Mathematica compute y[4], it will first recompute all the previous values
y[0] through y[3] again. To let Mathematica remember the previous values of x and y, use the following assignment
statements instead:
x[i_]:=x[i]=x[i-1]+dx
and
y[i_]:=y[i]=y[i-1]+f[x[i-1],y[i-1]] dx
Consider the following example.
Example: Use Euler's method to estimate the value of the solution to the initial value problem y' 1 x e y , y+0/
point x
2 using the step size dx 0.1. Compare the accuracy of your solution with the exact solution.
1 at the
In[19]:=
Clear#f, x, y';
f#x_, y_' 1 x2 y;
x#0' 1.; y#0' 2.; dx 0.1;
x#i_' : x#i' x#i 1' dx
y#i_' : y#i' y#i 1' f#x#i 1', y#i 1'' dx
The command Table[{x[i],y[i]},{i,0,n}] will form +x0 , y0 /, +x1 , y1 /, ..., +xn , yn /.
In[21]:=
Out[21]=
eulervals
A nice command for better visualization of the list of order pairs is the TableForm command and the additional option
TableHeadings, appearing in the following input cell, will place appropriate headings on each column.
In[22]:=
Out[22]//TableForm=
xi
1.
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
2.
yi
2.
2.3
2.6783
3.16398
3.79869
4.64323
5.78796
7.36967
9.59951
12.8097
17.5341
2.
If you want, you can now take the ordered pairs in the table and plot them to get an approximation of the solution curve.
86
87
In[23]:=
eulerplot
17.5
15
12.5
10
7.5
1.2
1.4
1.6
1.8
2.5
In[24]:=
Clear#x, y';
sol DSolve#y '#x'
x3
cccc
3c
Out[24]=
Out[25]=
y0 , y#x', x'.
1 x2 y#x', y#1'
1s3
+x3 /
1
1
Gamma# ccc
3c , ccc
3c '
32s3
2
1
x
E ,3
ccccccccc 0 31s3 x Gamma$ ccc
, cccccccc
E1s3 cccccccccccccccc
3c , ccccc
3 (0
cccccccccccccccccccccccccccccccc
cccccccccccccccccccccccccccccccc
cccccccccccccccccccccccccccccccc
cccccccc
cccc
y#x' cccccccccccccccccccccccccccccccc
1s3
3
3 +x /
exactyval
2 is found.
sol##1, 1, 2'' s. x ! 2.
25.6527
To see why our approximation is so far off, a plot of the approximate solution and the exact solution are displayed in the
following output cell. To obtain a better approximation, a smaller value of dx should be used.
In[26]:=
1.2
1.4
1.6
1.8
If you replace the previous code for Euler's method with the following
improved Euler's method, much better results will usually be obtained. Study
the following input cell.
In[27]:=
Clear#f, x, y';
f#x_, y_' 1 x2 y;
x#0' 1.; y#0' 2.; dx 0.1;
x#i_' : x#i' x#i 1' dx;
z#i_' : z#i' y#i 1' f#x#i 1', y#i 1'' dx;
f#x#i 1', y#i 1'' f#x#i', z#i''
cccccccccccccccccccccccccccccccc
ccccccccccccccccccccccccccccc dx;
y#i_' : y#i' y#i 1' cccccccccccccccccccccccccccccccc
2
In[28]:=
improvedEulervals
Out[28]=
From the table, it appears that y25.0678 when x=2. Much better! The plot of the graphs show how good the approximate
solution is compared to the exact solution.
In[29]:=
improvedeplot
ListPlot#improvedEulervals, PlotJoined ! True, DisplayFunction ! Identity';
88
89
In[30]:=
1.2
1.4
1.6
1.8
CAS Exercise Examples for Chapter 7: Integration Techniques, L'Hopital's
Rule and Improper Integrals
Section 7.5 Integral Tables, Computer Algebra Systems, and Monte Carlo
Integration
x
x x
2x
x x
3x
x x
4x
x x
Out[1]=
Out[2]=
Out[3]=
Out[4]=
Ex +1 x/
1
x
E2 x - cccc cccc 1
4
2
1
x
E3 x - cccc cccc 1
9
3
1
x
E4 x - ccccccc cccc 1
16
4
Out[5]=
nx
x x
1
x
En x - cccccc
c cccc 1
n2
n
In[6]:=
x
x x
1
Out[6]=
In[7]:=
Out[7]=
2
cccc
E
2
1
cccc x
cccccccccccccccc
r
0
4 x2
S
cccc
2
91
2 arctan+n3 /.
(a) Calculate and then plot the first 35 terms of the sequence. Determine the limit L of the sequence.
(b) Find an integer N such that an L 0.0001.
Part (a) The sequence is defined and then the Table command is used to display the first 35 terms in the sequence.
In[1]:=
Out[1]=
2.892882664,
3.137686409,
3.140863791,
3.141342654,
3.141478862,
3.141531618,
3.067552422,
3.138849171,
3.141000061,
3.141376694,
3.141491043,
3.141537001,
3.110345196,
3.139592654,
3.141104372,
3.141404825,
3.141501546,
3.141541768,
3.125592995, 3.13233346,
3.140090024, 3.140435246,
3.14118557, 3.141249718,
3.141428275, 3.141447978,
3.141510649, 3.14151858,
3.141546006
S.
Next, the ListPlot command is used to plot the sequence. The option PlotRangeAll is added to make sure all the
points appear in the plot of the sequence. The option AxesLabel ! n, an is added to give appropriate labels to the
horizontal and vertical axes.
In[2]:=
seqplot
an
3.14
3.138
3.136
3.134
3.132
n
5
10
15
20
25
30
35
3.128
Part (b) To determine n such that an S 0.0001, the horizontal lines y
In[3]:=
3.1415
3.14125
3.141
3.14075
3.1405
3.14025
5
10
15
20
25
30
35
S .0001 somewhere between 25 and 30. Next, the graph is magnified to get a
93
94
In[4]:=
3.14175
3.1417
3.14165
3.1416
3.14155
3.1415
3.14145
22
24
26
28
30
32
34
It is now clear that an S 0.0001 for n 28. To verify this, the value an S is computed for n
In[5]:=
27 and n
28.
Abs#a#27' S' ss N
Abs#a#28' S' ss N
Out[5]=
0.000101611
Out[6]=
0.0000911079
28.
1 and an1
1
cccccccc
cccc .
1an
(a) Use Mathematica to calculate and plot the first 25 terms of the sequence. Does the sequence appear to converge and if so,
to what value L?
(b) If the sequences does converge, find an integer N such that an L 0.00001 for n N.
Part (a) The following input cell defines an recursively and then uses the Table command to display the first 25 terms of the
sequence.
In[7]:=
Clear#a';
a#1' 1;
1
cccccccccccccccccccccccccccccc ;
1 a#n 1'
Table#N#a#n', 10', n, 1, 25'
a#n_' : a#n'
seq
Out[7]=
seqplot
an
0.6184
0.6182
n
5
10
15
20
25
0.6178
Part (b) From part (a), it appears that L 0.618033989. The value of N needed so that an L 0.00001 for n N is
determined by plotting the horizontal lines y L 0.00001 with the sequence.
95
96
In[9]:=
L 0.618033989;
band Plot#L .00001, L .00001, x, 0, 25, DisplayFunction ! Identity';
Show#seqplot, band, DisplayFunction ! $DisplayFunction,
PlotRange ! 10, 15, L .00002, L .00002';
an
0.61805
0.61804
0.61803
n
11
It appears that N
In[10]:=
Out[10]=
12
13
14
15
12.
Abs#a#12' L'
8.23793 106
In[11]:=
n
1
s#n_' : cccccccccccccccccccccc
i +i 1/
i 1
Limit#s#n', n '
1
1
cc , the limit is not found.
However, if this same method is applied to
n 1 cccc
n2
In[13]:=
Clear#s';
n
1
s#n_' : ccccccc ;
i2
i 1
Limit#s#n', n '
Out[13]=
S2
Limit$ ccccccc PolyGamma#1, 1 n', n (
6
Another way of evaluating an infinite series to enter n 1 an . Here are a couple of examples.
In[14]:=
Out[14]=
In[15]:=
Out[15]=
1
c
cccccc
2
n
n 1
S2
ccccccc
6
1
cccccc
cccccccccccccccc
2
n n1
n 1
r
r
r
r
5 S
5 S
5 S
4 Sec$ cccccccc
2 cc ( S Sin$ cccccccc
2 cc (0
2 cc ( , 5 Cos$ cccccccc
cccccccccccccccccccccccccccccccc
cccccccccccccccccccccccccccccccc
cccccccccccccccccccccccccccccccc
cccccccccccc
r
r
r
5 ,1 5 0 ,1 5 0
Use the N command to see the numerical approximation of the last output. The value of the last output is represented by %.
In[16]:=
Out[16]=
N#%'
1.54625
Sometimes Mathematica will produce the output of an infinite series in terms of a nonelementary function as seen in the
following cells.
In[17]:=
Out[17]=
1
cccccc
cccccccc
3
n 1
n 1
1 EulerGamma
cccccccccccccccccccccccccccccccc
cccccccccccccccccccccccccccccccccccccc
c
2
+1 +1/1s3 / +1 +1/1s3 /
1
cccc +PolyGamma#0, 1 +1/1s3 ' +1/2s3 PolyGamma#0, 1 +1/1s3 '
3
+1/2s3 PolyGamma#0, 1 +1/2s3 '/
In this case, either execute the command N[%] or use NSum command as shown next.
In[18]:=
Out[18]=
1
NSum$ cccccccccccccc , n, 1, (
3
n 1
0.686503
97
98
a.
x
Series$ cccccccccccc , x, 2, 3(
1x
2 +x 2/ +x 2/2 +x 2/3 O#x 2'4
The notation O#x 1'4 represents terms of +x 1/ to powers of 4 and higher, which are not explicitly displayed.
The Mathematica command Normal[Series[f[x],{x,a, n}]] will produce the Taylor polynomial of order n, Pn +x/,
generated by f at x a.
In[20]:=
Out[20]=
x
Normal$Series$ cccccccccccc , x, 2, 3((
1x
4 +2 x/2 +2 x/3 x
Cubic Approximations
Example: Let f +x/
x
cccccccc
cccccccc2cc . Complete each of the following.
r
1x
0 and plot P3 +x/ together with f +x/ over the interval #1, 1'.
(b) Calculate the fourth derivative f +4/ +c/ associated with the remainder term for P3 +x/. Plot the derivative as a function of c
over the interval #1, 1' and estimate the maximum absolute value M .
(c) Calculate the remainder R3 +x/ over the interval #1, 1', using the value of M found in part (b) in place of f +4/ +c/. Plot R3 +x/
over the interval #1, 1'. Use the plot to determine the values of x for which the function f +x/ can be replaced by P3 +x/ with an
error of less than 0.01.
(d) Compare the estimated error R3 +x/ with the actual error E3 +x/
Part (a) As previously described, the Normal and Series commands can combined to obtain the Taylor polynomial.
x
cccccccccccccccc
cccc ;
r
1 x2
p3 #x_' Normal#Series#f#x', x, 0, 3''
In[21]:=
f#x_'
Out[21]=
x3
x ccccccc
2
In[22]:=
-1
-0.5
0.5
-0.2
-0.4
-0.6
Part (b) The Mathematica command D[f[x],{x,n}] will compute f +n/ +x/. After computing the fourth derivative,, a graph
is obtained using the Plot command.
In[23]:=
Out[23]=
-0.5
0.5
-2.5
-5
-7.5
The maximum value of f +4/ +c/ is obtained near x
mate of M .
9 is a reasonable esti-
99
100
In[25]:=
Plot#g#c', c, .2, .4, AxesLabel ! c, "f+4/ +c/", PlotRange ! All';
f+4/ +c/
c
0.25
0.3
0.35
0.4
7.8
7.6
7.4
7.2
Part (c): An approximation of R3 +x/ can now be formed and plotted.
In[26]:=
9;
M x4
cccccccccc ;
4
Plot#R3 #x', x, 1, 1, PlotRange ! All';
R3 #x_'
0.35
0.3
0.25
0.2
0.15
0.1
0.05
-1
-0.5
0.5
The goal now is to zoom in on the graph by trial and error to the point where R3 +x/ 0.01 for all values of x in the graph.
In[27]:=
0.02
0.015
0.01
0.005
-0.4
In[28]:=
-0.2
0.2
0.4
-0.4
-0.2
0.2
0.4
From the last graph just obtained, it is clear that R3 +x/ 0.01on #0.4, 0.4' implying that f +x/ P3 +x/ 0.01 on this
interval.
Part (d) As the following output shows, the actual error f +x/ P3 +x/ is much smaller than 0.01 on [-0.4,0.4].
101
102
In[29]:=
0.003
0.0025
0.002
0.0015
0.001
0.0005
-0.4
-0.2
0.2
0.4
CAS Exercise Examples for Chapter 9: Vectors in the Plane and Polar
Functions
Graphics`Graphics`
In[2]:=
0.5
-1.5
-1
-0.5
0.5
-0.5
-1
-1.5
-2
1.5
104
The following is an example of plotting two functions simultaneously in different colors in a way completely analogous to the
Plot command. The option PlotStyle{RGBColor[1,0,0],RGBColor[0,0,1]} will plot the graph of cos+26/ in
red and the graph of sin+26/ in blue.
In[3]:=
0.5
-1
-0.5
0.5
-0.5
-1
105
1
0.75
0.5
0.25
CAS Exercise Examples for Chapter 10: Vectors and Motion in Space
2
r
,b f +z/ sin+T/0
cccccccccccccccccccccccccccccccc
cccccc cccccccccccccccccccccccc
ccccccccccccc
a2
b2
2
a f +z/cos +T/
b f +z/sin +T/
cccccccccccccccc
cccccccccccccccc cccccccccccccccc
cccccccccccccc
a2
b2
2
f +z/
y
x
cc cccc
cc f +z/ is satisfied. To display the graph of the quadric surface, use the Mathematica
and therefore the equation cccc
a2
b2
command
r
r
ParametricPlot3D$a f #z' Cos#T', b f #z' Sin#T', z, T, 0, 2S, z, zmin , zmax ' .
y
x
cc cccc
cc
(a) cccc
4
16
2
y
z
cc cccc
cc
(b) cccc
25
16
z
cccc
c
9
2
x
cccc
cc 1
9
16 and f +z/
z
z
2z
cccc
cc . Therefore, let x 2
cccc
cc cos+T/= cccc
ccc cos+T/ and let
9
9
3
2
107
In[1]:=
2z
4z
ParametricPlot3D$ cccccccc Cos#T', cccccccc Sin#T', z , T, 0, 2 S, z, 5, 5(;
3
3
5
0
-5
5
2.5
0
-2.5
-5
-2
0
2
2
y
z
cc cccc
cc
Part (b) Rearrange the equation cccc
25
16
y
x
x
z
cccc
cc 1 to get cccc
cc cccc
cc cccc
cc 1. This is a hyperboloid of two sheets (why?). In
9
9
16
25
y2
y2
cc 1 , z 4sin+T/
cccc
cc 1 . Notice that x and z are defined only when
this case, the equation is satisfied if x 3cos+T/ cccc
25
25
y 5 or y 5 which corresponds to the two parts of the graph. Study the following input commands. The option BoxRatios{1,1.5,1} scales the plot so that the length in the y direction is 1.5 times as long as the lengths in the other two
directions.
In[2]:=
backpart
y2
y2
ccccccc
1 , y, 4 Sin#T'
ccccccc
1 ,
ParametricPlot3D$3 Cos#T'
25
25
y2
y2
ParametricPlot3D$3 Cos#T'
ccccccc
1 , y, 4 Sin#T'
ccccccc
1 ,
25
25
-5
x
0
5
10
-10
5
0
z
-5
-10
#+4 sin+10 t// cos+t/'i#+4 sin+10 t// cos+t/'j +2cos+10 t//k and complete each of the following.
(a) Plot the space curve traced out by the position vector for 0 t 2S.
(b) Find the components of the velocity vector dr s dt.
(c) Evaluate the velocity vector at t
ccccS6 and determine the equation of the tangent line to the curve at r+ ccccS6 /.
108
109
In[3]:=
2
z
1
0
-1
-2
-5
5
2.5
0
-2.5
-2.5
0
x
2.5
5
-5
Part (b): Now the derivative of each component is computed to obtain the velocity vector.
In[4]:=
Out[4]=
v#t_'
Part (c) Next, the velocity vector is evaluated and the parametric equations of the tangent line are computed.
In[5]:=
Out[5]=
In[6]:=
S
v$ cccc ( ss N
6
2.76314, 5.2141, 17.3205
S
S
xl#t_' : x$ cccc ( x '$ cccc ( t;
6
6
S
S
yl#t_' : y$ cccc ( y '$ cccc ( t;
6
6
S
S
zl#t_' : z$ cccc ( z '$ cccc ( t;
6
6
Part (d) The space curve and the tangent line are displayed in the following output cell. Instead of plotting the curve for
values of t from 0 to 2S, a smaller interval of values is used so that the tangent line is easier to see.
In[7]:=
tanline
S
ParametricPlot3D$x#t', y#t', z#t', t, 0, cccc ,
4
PlotPoints ! 250, AxesLabel ! x, y, z, DisplayFunction ! Identity(;
spacecurve
y
0
-2
-2
2
3
4
x
5
6
110
111
x#t_'
Cos#t'; y#t_'
1
2 cccc Sin#t';
2
curve
ParametricPlot#x#t', y#t', t, 0, 2S, AspectRatio ! 1, PlotRange ! 1, 3';
3
2.75
2.5
2.25
1.75
1.5
1.25
-1
-0.5
0.5
Part (b) Using the formula found in Exercise 24 in your text, the value of N is computed.
In[9]:=
Out[9]=
N#t_'
112
S
N$ cccc ( ss N
4
1.01193
Part (c) Since N is a reserved Mathematica word, you can instead use n to represent the unit normal vector. See Exercise 25 to
see why the following formula was used to compute the normal vector. Is this the formula you should always use to find the
unit normal vector? Why or why not?
In[10]:=
Out[10]=
n#t_'
y '#t', x '#t' v
x '#t'2 y '#t'2 ;
S
n$ cccc (
4
1
2
ccccccccc
r , ccccccccc
r
5
5
Part (d) The center of the osculating circle is found using the following input cell.
In[11]:=
c
Out[11]=
x#t', y#t';
S
S
1
r$ cccc ( ccccccccSccccccc n$ cccc ( ss N
4
4
c'
N# ccc
4
r#t_'
0.265165, 2.53033
ymax},ContourShading->False, Contours-
113
In[12]:=
osccir
1
y, 1, 4, ContourShading ! False, Contours ! ccccccccccccccccc (;
S 2
c'
N# ccc
4
4
3.5
2.5
1.5
1
-1
-0.5
0.5
1.5
In[13]:=
2.5
1.5
-1
-0.5
0.5
1.5
114
CAS Exercise Examples for Chapter 11: Multivariable Functions and Their
Derivatives
f#x_, y_' x y ;
surface Plot3D#f#x, y', x, 2, 2, y, 2, 2, PlotPoints ! 20';
2
In[1]:=
1
0.75
0.5
0.25
0
-2
2
1
0
-1
-1
0
1
2 -2
Part (b) Before plotting some level curves of the surface, you might find it helpful to see the three-dimensional images represented by level curves. For example, the following Plot3D commands are used to display the level curves corresponding to
the horizontal planes z .25, z .5 and z .75. The ViewPoint option (found under the Input menu), contained in the
Show command, allows you to control the angle at which you view the image.
In[2]:=
-1
Now to show the actual level curves, the following ContourPlot command is executed.
116
117
In[3]:=
-1
-2
-2
-1
Deleting the Contours option allows Mathematica to choose the level curves to be plotted.
In[4]:=
-1
-2
-2
-1
Part (c) The following graph plots the level curve passing through +1, 1/. Why?
In[5]:=
-1
-2
-2
-1
Implicit Surfaces
The package ContourPlot3D contains the command
ContourPlot3D[f[x,y,z],{x, xmin, xmax},{y, ymin,
which will plot the level surface f +x, y, z/
Example: Plot the level surface x2 y 3z2
ymax},{z,zmin,zmax},Contours->{c)]
c.
1.
Graphics`ContourPlot3D`
Now the surface is plotted where the options Axes->True and AxesLabel->{x,y,z} are added so that the x, y and z
axes are labeled.
118
119
In[7]:=
2
z
4
2
-2
0
-4
-2
-2
0
x
2
4
-4
Parametrized Surfaces
The Mathematica command
ParametricPlot3D#f#u, v', g#u, v', h#u, v', u, umin, umax, v, umin, umax'
can be used to plot a surface described by the parametric equations
x
f +u, v/, y
g+u, v/ and z
In[8]:=
ParametricPlot3D#
u Cos#v', u Sin#v', u2 +Cos#v'2 Sin#v'2 /, u, 0, 1, v, 0, 2 S';
1
0.5
0
-0.5
-1
1
0.5
0
-0.5
-1
-1
-0.5
0
0.5
1
In[9]:=
r
5
Sin$ Abs#x y' (
Plot3D$ cccccccccccccccccccccccccccccccc
r
cccccccccc , x, 1, 1, y, 1, 1(;
5
Abs#x y'
1
0.95
0.9
0.5
0.85
-1
0
-0.5
-0.5
0
0.5
1 -1
r
5
sin, x y 0
cccccccccccccccc
cccc ccccc .
r
5
x y
120
121
The ViewPoint option (under the Input menu) can be used to view a surface from a different angle.
In[10]:=
r
5
Sin$ Abs#x y' (
Plot3D$ cccccccccccccccccccccccccccccccc
r
cccccccccc , x, 1, 1, y, 1, 1,
5
Abs#x y'
PlotPoints ! 60, ViewPoint ! 2.377, 2.363, 0.464(;
0.95
0.9
0.5
0
-0.5
-0.5
0.85
-1
0.5
-1
1
In[12]:=
Out[12]=
In[13]:=
Out[13]=
x Sin#x2 y'
2 x y Cos#x2 y'
x,y Sin#x2 y'
2 x Cos#x2 y' 2 x3 y Sin#x2 y'
D#Sin#x2 y', x, y'
2 x Cos#x2 y' 2 x3 y Sin#x2 y'
Example: Consider the function f +x, y/ x3 y2 3xy on 5 x 5, 5 y 5. Plot the function over the given rectangle
and then find and classify the critical points.
Here is a plot of the function.
In[14]:=
Clear#f';
f#x_, y_' x3 y2 3x y ;
Plot3D#f#x, y', x, 5, 5, y, 5, 5, PlotPoints ! 25';
200
100
0
-100
4
2
0
-4
-2
-2
0
2
-4
4
Now the first partial derivatives are found. (Ignore the warning messages.)
In[15]:=
Out[15]=
xparder
yparder
3 +x2 y/
General::spell1 : Possible spelling error: new symbol
name "yparder" is similar to existing symbol "xparder".
Out[16]=
3 x 2 y
sol
Solve#xparder
0, yparder
9
3
y 0, x 0, y cccc , x cccc
4
2
Now the second partial derivatives of the function are computed. (Ignore the
warning messages.)
122
123
In[18]:=
From the following work, you can conclude that both critical points are
saddle points.
In[19]:=
xxparder s. sol##1''
discrim s. sol##1''
Out[19]=
Out[20]=
9
In[21]:=
xxparder s. sol##2''
discrim s. sol##2''
Out[21]=
Out[22]=
36
0 and x2 y2 5
0.
Step one: First the functions f , g1 , g2 and h are defined as shown in the following input cell.
In[23]:=
Clear#f, h';
f x z x y;
g1 x2 z2 4;
g2 x2 y2 5;
h f O1 g1 O2 g2 ;
Step two: The partial derivatives are then computed and placed in equations which all have zero on the right side.
In[24]:=
eq1
eq2
eq3
eq4
eq5
x h
y h
z h
O1 h
O2 h
0;
0;
0;
0;
0;
Step Three: The Solve command is used to solve the system of equations formed in step two.
In[25]:=
sol
Out[25]=
O1
O1
O1
O1
cccc
cccc
cccccccc
ccccc ,
r
4
3
3
3
5
r
r
2 5
5
1
4
5
,
x
,
z
,
y
cccccccc
ccccc ,
ccccccccc , O2 ccccccccc
cccc
cccc
r
3
4
3
3
5
r
r
2 5
4
5
1
5
, y cccc , z cccc , x ccccccccccccc ,
ccccccccc , O2 ccccccccc
r
3
3
4
3
5
r
r
2 5
4
5
1
5
, y cccc , z cccc , x ccccccccccccc
ccccccccc , O2 ccccccccc
r
3
3
4
3
5
Step Four: The function f is then evaluated at each solution to determine the extreme values subject to the constraints asked
for in the exercise. What are the extreme values based upon the following work?
In[26]:=
Out[26]=
Out[27]=
Out[28]=
Out[29]=
f s. sol##1''
f s. sol##2''
f s. sol##3''
f s. sol##4''
r
2 5
r
2 5
r
2 5
r
2 5
124
sin x
cc dx dy using Mathematica.
Example: Integrate 0 y cccccccc
x
f
The easiest way to compute double integrals is to open the BasicInput palette and then click on the button containing f f f.
f
Enter 0, then the Tab key and then enter 1. Press the Tab key again and then click on f f f in the BasicInput palette. Enter
Sin#x'
cccccc , then press the tab key and enter x. Enter
y, then press the Tab key and then enter 1. Press the Tab key, enter the function cccccccc
x
y after pressing the Tab key. You can then let Mathematica compute the integral.
In[18]:=
Out[18]=
1 1
Sin#x'
cccccccccccccccccc x y
x
0 y
1 Cos#1'
If you want to compute a double integral by entering all your keystrokes from
the keyboard, enter the following.
In[19]:=
Out[19]=
y s5
r
x2 y 2 dx dy , complete each of the following.
y s 5 is equivalent to y
5x, the following Plot command can be used to plot the cartesian region of
In[20]:=
1
1
Plot$5x, 1, 5x, x, ccccccc , cccc , PlotRange ! 0, 1(;
5
5
1
0.8
0.6
0.4
0.2
-0.2
-0.1
0.1
0.2
Part (b) Replacing y with r sinT and x with r cosT, the Solve command can then be used to find the values of r and T. (Ignore
the warning messages.)
In[21]:=
Solve#r Cos#T'
Solve#r Cos#T'
Solve#r Sin#T'
r Sin#T' s 5, T'
r Sin#T' s 5, T'
1, r'
not be found.
1
1
cccc (
cccc ( , T ArcCos$ cccccccc
T ArcCos$ cccccccc
r
r
26
26
Solve::ifun : Inverse functions are
being used by Solve, so some solutions may
Out[22]=
1
1
cccc ( , T ArcCos$ cccccccc
cccc (
T ArcCos$ cccccccc
r
r
26
26
Out[23]=
r Csc#T'
not be found.
Part (c): The command PolarPlot is contained in the Graphics package and the package ComplexMap contains the
command PolarMap used to plot a portion of the polar coordinate system.
In[24]:=
Graphics`Graphics`
Graphics`ComplexMap`
The following command will plot the polar coordinate system for r
0 to 1.5.
126
127
In[26]:=
PolarMap#Identity, 0, 1.5';
1.5
0.5
-1.5
-1
-0.5
0.5
1.5
-0.5
-1
-1.5
1
1
Since our region of integration is bounded by the lines T ArcCos$ ccccccccc
r ( and T=ArcCos$ ccccccccc
r (, the next command is used
26
26
In[27]:=
polargr
1
1
1
1
ccccc ( ,
ccccc ( ArcCos$ cccccccc
ccccc (, ArcCos$ cccccccc
ccccc (, ArcCos$ cccccccc
ArcCos$ cccccccc
r
r
r
r
26
26
26
26
AspectRatio ! 1.1, Ticks ! None, GridLines ! None(;
csc T and the corresponding graph of this function can be found using the
128
129
In[28]:=
upperbd
1
1
c
ccc
c
cccccccc
ccccc ( ,
PolarPlot$Csc#T', T, ArcCos$ cccccccc
ArcCos$
(,
r
r
26
26
0.8
0.6
0.4
0.2
-0.2
-0.1
0.1
0.2
In[29]:=
0.8
0.6
0.4
0.2
-0.2
-0.1
0.1
0.2
Part (d) The integral is now converted to polar form and evaluated.
1
cc (
ArcCos$ cccccccc
r
In[30]:=
26
ArcCos$ cccccccccc (
1
r
1
cccccccc
ccccc
Sin cT
#
'
r4 Cos#T'2 r T
26
Out[30]=
1
7
1
7
169 , ccccccccc
169 , ccccccccc
r Cos$3 ArcCos$ ccccccccc
r ((0
r Cos$3 ArcCos$ ccccccccc
r ((0
26
26
26
26
cccccccccccccccccccccccccccccccc
cccccccccccccccc
cccccccccc cccccccccccccccccccccccccccccccc
cccccccccccccccccccccccccccccccc
cccccccccccccccc
cccc
cccccccccccccccccccccccccccccccc
25000
25000
1
1
1
1
1
1
ccccccc Log$Cos$ cccc ArcCos$ cccccccc
cccc ((( ccccccc Log$Cos$ cccc ArcCos$ cccccccc
cccc (((
r
r
40
2
40
2
26
26
1
1
1
1
1
1
ccccccc Log$Sin$ cccc ArcCos$ cccccccc
cccc ((( ccccccc Log$Sin$ cccc ArcCos$ cccccccc
cccc (((
r
r
40
2
40
2
26
26
Now the numerical approximation of the integral is obtained.
In[31]:=
Out[31]=
N#%'
0.00107938
130
131
y
ccc
5c
1
In[32]:=
2
y x
0
Out[32]=
cccc
5c
r
x2 y2 x y
Despite the warning message, the solution obtained with Mathematica agrees with the earlier answer when the N command is
used.
In[33]:=
Out[33]=
N#%'
0.00107938
Out[34]=
yx
1
cccc
6
1 z y x
r
1 x2 y2 and r+t/
r
f#x_, y_, z_'
1 x2 y2 ;
g#t_', h#t_', k#t_' t, t2 , t3 ;
g '#t'2 h '#t'2 k '#t'2 ss Simplify
If you try to evaluate the integral with Mathematica, an answer is not found. Therefore the NIntegrate command is used
instead to obtain a numerical answer.
S
ccc
2c
In[4]:=
integrand t
0
S
ccc
2c
Out[4]=
r
r
1 t2 t4 1 4 t2 9 t4 t
In[5]:=
Out[5]=
t2 itjt3 k, 0 t 1.
The package VectorAnalysis contains the command DotProduct which will compute the dot product of two lists of equal
size. Study the following input and output used to solve the work problem.
In[6]:=
Calculus`VectorAnalysis`
133
In[7]:=
In[10]:=
Out[10]=
In[11]:=
Out[11]=
In[12]:=
Out[12]=
t3 5 t6
1
In[13]:=
integrand t
0
Out[13]=
27
ccccccc
28
-2
-4
-4
-2
The second form of Green's Theorem in equation (4) in your text is used here
to compute the circulation.
3x y;
In[15]:=
m#x_, y_'
In[16]:=
integrand
Out[16]=
5
2
In[17]:=
Out[17]=
40 S
r2
164 x
r
2 164 x2
integrand y x
134