Main Rev.dvi Derive Lab Manual
User Manual: manual pdf -FilePursuit
Open the PDF directly: View PDF .
Page Count: 248
Download | |
Open PDF In Browser | View PDF |
Calculus Concepts Using Derive For Windows Ralph S. Freese and David A. Stegenga Professors of Mathematics, University of Hawaii R & D Publishing The procedures and applications presented in this supplement have been included for their instructional value. They have been tested with care but are not guaranteed for any purpose. The authors do not offer any warranties or representations, nor do they accept any liabilities with respect to the programs or applications. c Copyright 2000 by the Authors. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the authors. Printed in the United States of America. This publication was typeset using AMS-LATEX, the American Mathematical Society’s TEX macro system, and LATEX 2ε . For information on obtaining this book see http://www.math.hawaii.edu/CalcLabBook/ and to see our class web page containing our syllabus, assignments and general information for students see http://www.math.hawaii.edu/lab/ Honolulu, Hawaii May 7, 2001 Contents Preface Calculus Reform and Computers . How To Teach From The Manual . Advice For The Students . . . . . Setting Up The Computer Lab . . World-Wide Web Site For Our Lab . . . . . . . . . . 0 Introduction and Derive Basics 0.1 Overview . . . . . . . . . . . . . . 0.2 Starting Derive . . . . . . . . . . 0.3 Entering an Expression . . . . . . 0.4 Special Constants and Functions . 0.5 Editing . . . . . . . . . . . . . . . 0.6 Simplifying and Approximating . 0.7 Solving Equations . . . . . . . . . 0.8 Substituting . . . . . . . . . . . . 0.9 Calculus . . . . . . . . . . . . . . 0.10 Plotting . . . . . . . . . . . . . . 0.11 Defining Functions and Constants 0.12 Defining The Derivative Function 0.13 Functions Described By Tables . 0.14 Vectors . . . . . . . . . . . . . . . 0.15 Printing and Saving to a Disk . . 0.16 Help . . . . . . . . . . . . . . . . 0.17 Common Mistakes . . . . . . . . iii . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix ix x xiii xiii xv . . . . . . . . . . . . . . . . . 1 1 2 3 4 5 6 6 8 9 12 14 16 17 18 20 21 22 1 Curve Sketching 1.1 Introduction . . . . . . . . 1.2 Working with Graphs . . . 1.3 Exponential vs Polynomial 1.4 Laboratory Exercises . . . 2 The 2.1 2.2 2.3 . . . . . . . . . . Growth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 25 26 29 32 Derivative 37 The Derivative as a Limit of Secant Lines . . . . . . . . . . . . 37 Local Linearity and Approximation . . . . . . . . . . . . . . . 41 Laboratory Exercises . . . . . . . . . . . . . . . . . . . . . . . 44 3 Basic Algebra and Graphics 3.1 Introduction . . . . . . . . 3.2 Finding Extreme Points . 3.3 Max-Min Problems . . . . 3.4 Zooming and Asymptotes 3.5 Laboratory Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Curve Fitting 4.1 Introduction . . . . . . . . . . . . . . . . 4.2 Fitting Polynomials to Data Points . . . 4.3 Exponential Functions and Population Growth . . . . . . . . . . . . ∗ 4.4 Approximation Using Spline Functions 4.5 Laboratory Exercises . . . . . . . . . . . 5 Finding Roots Using Computers 5.1 Introduction . . . . . . . . . . . 5.2 Newton’s Method . . . . . . . . 5.3 When Do These Methods Work 5.4 Complex Numbers, Fractals and ∗ 5.5 Bisection Method . . . . . . . 5.6 Laboratory Exercises . . . . . . . . . . . . . . . . . . . . . ∗ Chaos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 47 47 49 50 52 55 . . . . . . . . . . . . 55 . . . . . . . . . . . . 55 . . . . . . . . . . . . 60 . . . . . . . . . . . . 61 . . . . . . . . . . . . 63 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 69 69 73 78 86 89 6 Numerical Integration Techniques 95 6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 6.2 An Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 ∗ 6.3 Theorem on Error Estimates . . . . . . . . . . . . . . . . . . 100 6.4 6.5 6.6 ∗ More on Error Estimates . . . . . . . . . . . . . . . . . . . . 102 ∗ Deriving Simpson’s Rule . . . . . . . . . . . . . . . . . . . . 104 Laboratory Exercises . . . . . . . . . . . . . . . . . . . . . . . 105 7 Taylor Polynomials 7.1 Polynomial Approximations . . . . . . 7.2 Examples . . . . . . . . . . . . . . . . 7.3 Taylor’s Theorem with Remainder . . . 7.4 Computing the Sine Function . . . . . 7.5 Computing the Exponential Function. . 7.6 Taylor Expansions About x = c . . . . 7.7 Interval of Convergence . . . . . . . . . 7.8 Laboratory Exercises . . . . . . . . . . 8 Series 8.1 Introduction . . . . . . . . . . 8.2 Geometric Series . . . . . . . 8.3 Applications . . . . . . . . . . 8.4 Approximating Infinite Series 8.5 Laboratory Exercises . . . . . 9 Approximating Integrals 9.1 Introduction . . . . . . . . . 9.2 The Basic Error Estimate . 9.3 The Logarithm Series . . . . 9.4 An Integral Approximation . 9.5 Laboratory Exercises . . . . 10 Polar and Parametric Graphs 10.1 Introduction . . . . . . . . . 10.2 Polar Coordinates . . . . . . 10.3 Rotating Polar Curves . . . 10.4 Complex Numbers . . . . . 10.5 Parametric Curves . . . . . 10.6 Laboratory Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 . 109 . 110 . 115 . 116 . 118 . 120 . 122 . 124 . . . . . 131 . 131 . 132 . 133 . 137 . 147 . . . . . 153 . 153 . 154 . 154 . 156 . 158 . . . . . . 161 . 161 . 161 . 164 . 166 . 167 . 172 11 Differential Equations 11.1 Introduction . . . . . . . . . . . . . . . . 11.2 Examples . . . . . . . . . . . . . . . . . 11.3 Approximation of Solutions . . . . . . . ∗ 11.4 Euler’s Approximation Method . . . . . 11.5 Linear First Order Differential Equations 11.6 Laboratory Exercises . . . . . . . . . . . 12 Harmonic Motion 12.1 Introduction . . . . . . . . . . . . . . 12.2 Examples . . . . . . . . . . . . . . . 12.3 Solving Linear Differential Equations 12.4 Systems of Differential Equations . . 12.5 Laboratory Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 . 177 . 177 . 182 . 186 . 187 . 191 . . . . . 195 . 195 . 196 . 198 . 206 . 211 A Utility Files 217 A.1 The Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 A.2 Listings of the Utility Files . . . . . . . . . . . . . . . . . . . . 223 B DfW Version 5 227 B.1 What’s New In DfW5 . . . . . . . . . . . . . . . . . . . . . . . 227 List of Figures Part of M206L World-Wide Web page . . . . . . . . . . . . . . xvi 0.1 0.2 0.3 0.4 0.5 0.6 0.7 Author entry form with special symbols . . . . . . Using the Calculus menu . . . . . . . . . . . . . . Examples of Limits, Products and Sums . . . . . Using Plot for graphics . . . . . . . . . . . . . . . Examples of Declare, Simplify and approximating Functions defined by tables of expressions . . . . Using the Calculus/Vector command . . . . . . . 1.1 1.2 1.3 Using vector to plot several graphs . . . . . . . . . . . . . . . 26 The functions x4 and ex . . . . . . . . . . . . . . . . . . . . . 30 The functions x4 and ex , rescaled . . . . . . . . . . . . . . . . 31 2.1 2.2 Secant lines approximating the tangent line . . . . . . . . . . . 38 Approximating derivatives using the difference quotient . . . . 43 3.1 3.2 Finding critical points . . . . . . . . . . . . . . . . . . . . . . 48 Zooming to find the horizontal asymptote . . . . . . . . . . . 51 4.1 4.2 4.3 Fitting a polynomial to data points . . . . . . . . . . . . . . . 57 The algebra behind fitting polynomials to data points . . . . . 59 Approximation using spline functions . . . . . . . . . . . . . . 64 5.1 5.2 5.3 5.4 5.5 5.6 Newton’s method for finding roots . . . . . . . . . . Each iteration gives twice as many digits . . . . . . Newton’s method with complex starting point . . . Chaos . . . . . . . . . . . . . . . . . . . . . . . . . Basins of attraction of x3 − 1 in the complex plane Bad Newton starting points for x3 − 3x = 0 in the plane . . . . . . . . . . . . . . . . . . . . . . . . . . vii . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . complex . . . . . . . . . . . . . . . . . 4 10 11 14 15 18 19 70 73 82 83 84 . 85 5.7 Basins of attraction for x3 − 3x = 0 . . . . . . . . . . . . . . . 86 5.8 Bisection method for finding roots . . . . . . . . . . . . . . . . 88 6.1 Approximating ln 2 with left endpoint method . . . . . . . . . 98 6.2 Rectangular vs trapezoidal approximation . . . . . . . . . . . 100 6.3 Trapezoid and midpoint rule for concave functions . . . . . . . 104 7.1 7.2 7.3 7.4 7.5 7.6 7.7 Basic examples of Taylor polynomials . . . . . . Taylor polynomials for sin x . . . . . . . . . . . Approximating sin x with its Taylor polynomials Approximating sin 100 within 6 decimals . . . . Approximating e5 within 6 decimals . . . . . . . Taylor expansion of the logarithm function . . . Graphically finding the radius of convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 113 114 118 120 122 123 8.1 Ratio test example . . . . . . . . . . . . . . . . . . . . . . . . 140 8.2 The geometric estimate in the integral test . . . . . . . . 143 P used 8.3 Summing the series 1/i2 . . . . . . . . . . . . . . . . . . . . 146 9.1 Using Taylor series to approximate integrals . . . . . . . . . . 158 10.1 10.2 10.3 10.4 10.5 10.6 Polar Coordinates . . . . . . . . . . . . Plotting points in polar coordinates . . Showing that y = 1/x is a hyperbola . Parametric plot of a semi-ellipse . . . . More parametric plots . . . . . . . . . The cycloid curve and the rolling wheel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 163 165 168 171 175 11.1 11.2 11.3 11.4 Slope field for the Newton cooling problem . A graph of a Verhulst population curve . . . Euler’s method for approximating solutions . Solving Newton’s cooling equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 185 187 189 12.1 12.2 12.3 12.4 12.5 12.6 The pendulum . . . . . . . . . . . . . . . . . Spring motion starting at different positions Under Damped Oscillations . . . . . . . . . Euler and the 2nd Runge-Kutta methods . . Rabbits and Foxes . . . . . . . . . . . . . . Pendulums . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 203 205 208 210 212 B.1 The new look of DfW5 . . . . . . . . . . . . . . . . . . . . . . 228 Preface Calculus Reform and Computers This lab manual is the result of more than a decade of experimenting with the use of computers as an enhancement to learning calculus. In the beginning we were working with Albert Rich and David Stoutemyer, founders of the Soft Warehouse Inc. here in Honolulu, and their muMATH computer program. This program was the precursor to Derive. It was a PC-version of the big mainframe computer program macsyma. They could symbolically integrate, differentiate and do other calculus type problems. There were no menus or graphics at that time, so we developed a small enhancement program which included these features and distributed it to several university mathematics departments in the United States and elsewhere. This effort took place in the middle to late 1980’s. Since then, there has been a national movement to include computers in the teaching of calculus and in fact to reform the teaching of calculus by discussing new ideas using not only the traditional algebraic approach but also by exploring the ideas graphically and numerically. In response to this movement, new computer programs were written such as Derive, Mathematica and Maple. Computer calculus labs were created at most universities and colleges to take advantage of this new technology and to start experimenting with new ideas for teaching calculus. Calculus textbooks are now starting to include substantial supplements on computer experiments and some have been completely rewritten to involve computers as an integral component of the course. It is hard to say right now what calculus instruction will look like in ten years but there is no doubt that computers are completely changing the teaching approach to certain topics with intensive use graphics or computation components. In this book we try to highlight those areas of calculus, which are best ix studied by using the computer to explore, to visualize and to suggest further directions to study. We also try to convey that studying calculus can be fun to do and that it is very important in understanding other topics in mathematics and other fields. This manual uses Derive because of its ease of use. Students enter expressions by filling out a form which includes special mathematical symbols such as π and ∞. Then, at the click of a button one can differentiate, integrate or plot the expressions. This calculator type interface is very easy for students to learn and after about 15 minutes of introduction during the first visit to the lab the students are ready to start using the program. There are also functions that are equivalent to the various buttons and menu commands. Knowing these functions enables one to write programs that extend the power of Derive. We will give numerous examples demonstrating both the simple calculator mode and the powerful programming language. How To Teach From The Manual We have been incorporating computers in our calculus curriculum for over a decade. Originally, this was done as an experimental section of our regular calculus classes and was taught by the two of us. But for the last four years this computer component has been a required lab course for all of calculus students. The typical class session starts with a discussion from the lecturer, who uses both the chalkboard and the projected image of a computer to present the material, which includes a combination of theory along with computer graphics and computations. One of the students has his computer monitor projected on a screen for the whole class to see and follows the instructions given by the lecturer. The rest of the class follows along on their own computers and consults the screen to make sure that they are doing it correctly. Each class session allows for a time period after the lecture during which the students can work on their assignments and ask questions. Each course will include several labs involving selected topics from calculus and differential equations. Typically, first semester students do the first several chapters focusing on graphing, properties of the derivative and perhaps a brief introductory treatment of Chapter 6 on approximating definite integrals. Second semester students generally do 7-8 chapters covering integration, series and differential equations. Second year students would study parametric curves, series and differential equations more thoroughly. There is also a good deal of extra material such as an introductory treatment of chaos theory and complex dynamics, approximations with spline functions, and the Runge-Kutta approximation methods which can be added whenever appropriate. Several of the chapters would require more than one lab depending on the level of understanding that is desired. The material in each chapter is for the most part self-contained and does not rely on any of the others. This allows considerable flexibility in planning a syllabus. For example, while we recommend reading the first four chapters in order, this is not necessary. Chapter 5 and Chapter 6 can be done in either order; however, Chapter 6 does use some material from Chapter 4 to derive the algorithm for Simpson’s Rule. Chapter 7 on Taylor polynomials and Chapter 8 on Series can also be done in either order; however, Chapter 9 assumes a knowledge of those two chapters. Likewise, Chapter 12 on harmonic motion assumes that the student has read Chapter 11 on differential equations. • Chapter 1 covers basic graphs and manipulation of graphs by translations and rescalings. A graphical comparison of exponential growth with polynomial growth is a prelude to later discussions of population growth models. • Chapter 2 covers the local linearity of the derivative using computer zooming techniques and the limit of secant lines. One of the exercises requires approximating a function by its tangent line. • Chapter 3 is a further discussion of the derivative including critical point theory, inflection points and max-min problems. • Chapter 4 shows how to fit a polynomial through a set of data points. This includes a discussion of how to solve a system of linear equations using the computer. A more advanced discussion on spline functions is given in the last section. There are exercises which explore the growth in the US population, over the last two centuries, viewed as empirical data. • Chapter 5 covers the Newton method for finding real roots to equations. Emphasis is given to both the speed at which the method converges and the care which is required in the selection of the starting point. There is also a brief review of the algebra of complex numbers and applications of Newton’s method to finding complex roots to polynomials. A discussion of fractals and chaos is given toward the end of the chapter. • Chapter 6 discusses the various methods for numerically approximating integral and a comparison of the rates of convergence. The last section shows how to derive Simpson’s method using the tools from Chapter 4. • Chapter 7 introduces Taylor polynomials as a means of approximating trigonometric and exponential functions. Pattern recognition is used to suggest infinite series representations. Emphasis is given to the analysis of the error and how many terms are needed to achieve a given accuracy. Graphical methods are used to discuss the interval of convergence in an elementary manner. • Chapter 8 introduces infinite series and gives several applications of the geometric series. There are discussions of the error that results when a series is approximated by its partial sums. • Chapter 9 combines the techniques of both Taylor polynomials and infinite series to discuss on the approximation of integrals using Taylor polynomials. As an application, the representation and approximation of the logarithm function is studied. • Chapter 10 shows how to plot polar and parametric curves. There are discussions of rotations of graphs, speed of particles traveling along a parametric curve and some connections with complex numbers. • Chapter 11 is a basic treatment of first order differential equations. Population growth models and Newton cooling are used as motivating examples. Graphical representations using slope fields and the Euler approximation method are discussed. • Chapter 12 discusses second order linear differential equations with constant coefficients such as the mass-spring system. The chapter ends with a treatment of the Runge-Kutta method of approximation. Advice For The Students The students should read the designated chapter in the manual and then complete the laboratory exercises for that chapter. Some of the sections are marked with a star which means that they are either optional or a little more advanced than the other sections. For example, many of the theorems and proofs that provide rigorous explanations for the material in these sections can be found in the starred sections. This same principle applies to the starred exercises, which generally contain problems that are a little more involved than the others or contain material that is not generally presented in a first year calculus course. We recommend reading the un-starred sections first and skimming over the starred sections before attempting the exercises. After becoming more familiar with the material by working several exercises, the starred sections should be more accessible and interesting. The text material and the labs assume that you are using the computer software Derive for Windows which we denote by DfW. As mentioned above, it is easy to learn how to use Derive because its design reminds you of an elaborate calculator. The buttons and nested menus at the top of the screen lead the student along. Chapter 0 contains a tutorial and reference on using Derive. There are many interesting features that will be explored in the labs. In the beginning we recommend that the students just skim over this chapter, while at the computer, so that they can do the basics, such as entering an expression, graphing it and so on. As the students progress through the text there will be frequent references to this chapter, so we recommend that they go back over the material that was skimmed the first time. Setting Up The Computer Lab Our computer lab has modified the basic installation of DfW in three ways. First of all, we added a subfolder which contains all of the files referred to in the manual and make this folder the default directory (see your DfW manual for doing this). These files include the Derive files which correspond to every demonstration figure in the manual. For example, in Figure 1.2 on page 30 there is a reference to the file F-EXP1.MTH which can be seen by looking at the header stripe for the algebra window in the figure. Loading the file F-EXP1 (the extension is unnecessary) allows the students to practice on the material that is being explained. The demonstration files are completely optional but the students occasionally find them quite useful. They can be downloaded from our web site. In addition to these optional files there are two required Derive files which implement the manual’s utility functions. These are ADD-HEAD and ADD-UTIL. We recommend that the students start each new lab session by loading the small file ADD-HEAD and then using the File/Save As menu to save this file using a new name such as H:LAB1. Here we have designated the student’s network harddrive as the H: drive. The ADD-HEAD file quietly loads the definitions, from the ADD-UTIL file, of all the utility functions that are used in the manual. For example, in Chapter 6 we explain how to enter from scatch and use the formula for the left endpoint method in numerical integration. But for the exercises and further discussion we introduce special utility functions such as LEFT, TRAP and SIMP that have the formula built-in. This allows the instructor to either emphasize the programming features or to simply demonstrate them and then allow the students to use a ready-made formula for the exercises. The last change we make is use the mixed output mode. This is done by selecting the menu option Declare/Algebra State/Output and then changing the notation option to mixed. With this option set then decimals are saved as decimals instead of being converted to fractions which is Derive’s default mode. When exiting Derive after making this change you will be asked to save the State Variables. You should accept this change for it then makes an entry in the initialization file DFW.INI. However, after everything is set up and working properly we recommend setting the permissions on the DFW folder to read and execute only. This will prevent the students from saving their lab files to the default directory (the one containing ADD-HEAD and the demonstration files) which is a common problem. In addition, this will prevent the students for changing the file DFW.INI that contains the basic settings mentioned above. These restrictions are easily done if you are using the Windows NT workstation operating system with the NTFS file system or if you are using a network installation of DfW. If you have Derive installed locally on a Windows 95/98 PCs then you should probably download the three files: ADDHEAD, ADD-UTIL and DFW.INI every time the student logs onto the system. This can be done with a login script. See Appendix A for a more detailed explanation of all of these issues. The latest versions of these files are available for downloading from our web site at: http://www.math.hawaii.edu/CalcLabBook/ World-Wide Web Site For Our Lab We maintain a web site on our lab for the students here at the University of Hawaii. This includes course information such as lab schedules and assignments but it also has several pages of general interest. The web address is http://www.math.hawaii.edu/lab/ There is a link to M241, which is our first semester Calculus class, and M242 is the second semester class. For example, let’s suppose that we click on the M242 button. You will notice that there are many links on the left border that will take you to different parts of the site. Just click on any of the underlined words and a new page will be displayed with addition information on that topic. For example, by clicking on the Utility Functions link you go to a page where the utility functions which we have added to the system, in the ADD-HEAD and ADD-UTIL files, are explained. Scrolling down there are explanations of functions like LEFT and SIMP which can be used for doing numerical integration in Chapter 6. The latest version of these files can also be downloaded from this web page. The picture on the following page shows part of our web site. It is a demonstration of Newton’s method that is explained in Chapter 5. You can flip back and forth between the web pages and Derive while you are reading the online material. In the Window’s desktop, this is simply a matter of clicking the DfW button on the task tray or you can use cascading windows. Another quick method is to press and hold the Alt key and then press the Tab until DfW is selected. The same procedure will take you back to the browser. You may have to experiment with this or ask a PC-friend for help, but it works very nicely and allows you to view the web page and then flip to the Derive screen and practice. Ralph S. Freese David A. Stegenga Part of our web page Chapter 0 Introduction and Derive Basics 0.1 Overview In this course you will learn to use the computer mathematics program Derive. This program, along with others such as Maple and Mathematica, are very powerful tools for doing calculus. They are capable of doing exact computations with arbitrary precision. This means that you can work with numbers of any size or number of decimal places (most spreadsheets only use 10-20 significant digits). These programs can simplify mathematical expressions by canceling common factors and doing other algebraic operations. They can do symbolic calculus such as differentiation and integration, solve equations and factor polynomials. When possible these programs solve these problems exactly and when exact solutions do not exist, such as factoring high degree polynomials or integration of some non-polynomial expressions, then numerical methods are applied to obtain approximate results. Probably the most important numerical technique is to graph and compare functions. This will be a key feature of the labs. Typically we will explore a topic by first graphing the functions involved and then trying to do symbolic calculus on them using the insight gained from the picture. If the problem is too difficult algebraically we then try numerical techniques to gain further insight into the problem. It is this combination of graphics, algebra and numerical approximation that we want to emphasize in these labs. Calculus is a hard subject to learn because it involves many ideas such as slopes of curves, areas under graphs, finding maximums and minimums, ana1 2 CHAPTER 0. INTRODUCTION AND DERIVE BASICS lyzing dynamic behavior and so on. On the other hand, many computations involve algebraic manipulations, simplifying powers, dealing with basic trig expressions, solving equations and other techniques. Our goal is to help you understand calculus better by concentrating on the ideas and applications in the labs and let the computer do the algebra, simplifying and graphing. Another important goal of the lab is to teach you a tool which can used from now on to help you understand advanced work, both in mathematics and in subjects which use mathematics. There are many features such as matrices and vector calculus which we will not discuss but can be learned later as you continue with your studies in mathematics, physics, engineering, economics or whatever. Any time you have a problem to analyze you can use the computer to more thoroughly explore the fundamental concepts of the problem, by looking at graphs and freeing you from tedious calculations. This chapter contains a brief introduction on how to use Derive. We suggest you sit down at the computer and experiment as you look over the material. Derive is very easy to learn thanks to its system of menus. The few special things you need to remember are discussed below and can also be found using the help feature in Derive. This manual assumes that you will be using Derive for Windows (DfW) Version 4. The recently released DfW Version 5 (DfW5) can also be used but there have been some changes to the menus and buttons that we try to point out using footnotes. See also Appendix B for more information on Version 5. 0.2 Starting Derive To start DfW look for on the Windows desktop and double click it. In DfW we use the drop down menus on the top strip or else click an appropriate button. If you move the cursor onto a button and leave it there a brief explanation of what the button does will appear. All possible options can be found on the drop down menus but the buttons provide a quick way of doing most common operations. For example, to enter a mathematical button which represents a pencil. Alternately, expression you click the 0.3. ENTERING AN EXPRESSION 3 you click the Author menu and then click Expression. In this manual we will indicate that two step combination by simply Author/Expression.1 In this manual we use a typewriter like font, eg., a(b + c) to indicate something you might type in. We use a sans serif font for special keys on the keyboard like Enter (the return key) and Tab. Most of Derive has easy to use menus and buttons which we will described below. It only takes a few minutes of practice to become capable at using DfW. You can skim over this section now or then come back to it later as the need arises. 0.3 Entering an Expression After clicking the button, you enter a mathematical expression, i.e., you type it in and then press the Enter key or else click OK. You enter an expression using the customary syntax: addition +-key, subtraction --key, division /-key, powers ^-key and multiplication *-key (however; multiplication does not require a *, i.e., 2x is the same as 2*x). Derive then displays it on the screen in two-dimensional form with raised superscripts, displayed fractions, and so forth. You should always check to make sure the two-dimensional form agrees with what you thought you entered (see Editing below to see how to correct typing errors). Table 1 gives some examples. If you get a syntax error when you press enter (or click OK) the problem is usually mismatched parentheses. Carefully check that each left parenthesis is matched with a corresponding right one. Also be careful to use the round parentheses and not the square brackets since they are used for vector notation; see Section 0.14 on page 18. Note from (3) and (4) and from (6) and (7) of Table 1 that it is sometimes necessary to use parentheses. Also note in (8), that to get the fraction you want, it is necessary to put parentheses around the numerator and denominator. See what happens if you enter (8) without the parentheses. Also try entering some expressions of your own. There are two ways to enter square roots. One way is using the 0.5 or 1/2 power as in (9) and the other is to enter the special square root character as in (10). 1 In DfW5, authoring has been improved and simplified but the above methods still works. See Appendix B for details. CHAPTER 0. INTRODUCTION AND DERIVE BASICS 4 Table 1: You enter: You get: (1) 25 25 (2) x^2 x2 (3) a^2x a2 x (4) a^(2x) a2x (5) sin x sin(x) (6) sin a x sin(a)x (7) sin(a x) sin(ax) (8) (5x^2 - x)/(4x^3 - 7) 5x2 −x 4x3 −7 (9) (a + b)^(1/2) √ (a + b) (10) 0.4 √ (a + b)1/2 (a + b) Special Constants and Functions In DfW all the special characters are on the author form and you just click on them to enter them in an expression. There are also key equivalent such as pi for π and #e for Euler’s constant2 e which is displayed by Derive as ê. Figure 0.1: Author entry form with special symbols 2 Leonhard Euler (oi’lar) was a 18th century Swiss mathematician. 0.5. EDITING 5 It is important to distinguish ê from just e. Derive takes e to just be some constant like a. To get the functions tan−1 x = arctan(x), sin−1 x = arcsin(x), etc., you type atan x and asin x. If you forget how a particular function is entered just use the Help menu. 0.5 Editing Suppose that you author an expression, click OK and then observe that you typed something wrong. To enter a correction you would click the button again and then click the right mouse button. A menu opens up with several options, one of which is Insert Expression.3 Clicking this option puts the highlighted expression of the current algebra window into the author box. You edit this expression as you would in any windows program. That is you position the cursor either by clicking or using the arrow keys. By highlighting or selecting a subexpression and typing you replace the selected text with the new text. One can use the Edit/Copy Expressions4 menu or Cntl-C to place a highlighed expression from any algebra window onto the clipboard and then in the authoring form right click the mouse and click Paste to copy the clipboard contents. The simpler method of just right clicking the mouse and then Insert is the best way as long as your expressions are in a single window. There is also an option for inserting the expression enclosed in parenthesis. A key equivalent to these techniques is to press either the F3 or the F4 key. You select or highlight expressions in the algebra window by clicking on them. For more complicated expressions you can click several times until the desired subexpression is selected. This requires a little practice but you can, x2 by clicking on for example, select the x + 2 part of the expression sin x(x+2) it 4 times (each click takes you deeper into the expression). The displayed expressions are numbered. You can refer to them as #n. So, for example, with the expressions in Table 1, you could get sin(x)/x2 by Authoring #5/#2. When you start Derive it is in a character mode. This means it treats each single character as a variable, so if you type ax Derive takes this to 3 In DfW5 you click in the Author box first and then right click Insert. A new feature is to right click the erroneous expression, choose Edit and press the Enter key after you make the corrections. 4 This is simply Copy in DfW5. CHAPTER 0. INTRODUCTION AND DERIVE BASICS 6 be a times x. This mode is what is best for calculus. The exception to this are the functions Derive knows about. If you type xsinx, Derive knows you want x sin(x). Actually on the screen you will see x SIN(x): Derive displays all variables in lower case and all functions in upper case. 0.6 Simplifying and Approximating After you enter an expression, Derive displays it in two-dimensional form, but does not simplify it. Thus, integrals are displayed with the integral sign and derivatives are displayed using the usual notation. To simplify (that is button. The alternate method is evaluate) the expression, click the the Simplify/Basic drop down menu. √ Derive uses exact calculations. If you Author the square root of eight, 8 will be displayed in the algebra window. If you simplify this, you get √ 2 2. If you want to see a decimal approximation, you click the button. See Figure 0.5 on page 15 for several examples. The number of decimal places used can be changed to any number. You choose Declare/Algebra State/Simplification5 and then reset the value of Digits on this form. This results in a change in the State variables for Derive and you will be prompted on whether you want to save these changes when you exit the program. Since you shouldn’t change files on the system directory you click No. An alternate way to do this for a single computation is to select the Simplify menu. Then, choose Approximate from the drop down menus and enter a new number of decimals. The only trouble with this method is that if you save your file the extra decimals will be ignored unless you set the Output decimal places appropriately. When you open the file later you will also need to reset the Output decimal place accuracy. 0.7 Solving Equations An important problem is to find all solutions to the equation f (x) = 0. If f (x) is a quadratic polynomial such as x2 −x−2, then this can be done using the quadratic formula or by factoring. To factor you choose Simplify/Factor from the menu bar and click Simplify on the entry form. The result is 5 In DfW5 you choose Declare/Simplification Settings. 0.7. SOLVING EQUATIONS 7 Table 2: Special Keys and Function Names Expression/Action Type: Menu: e #e Author entry form π pi Author entry form inf, -inf Author entry form sqrt(x) Author entry form ∞, −∞ The square sign: √ x ln x, logb x ln x , log(x, b) Inverse trigonometric functions d f (x) dx dn f (x) dxn Z f (x) dx Z b f (x) dx asin x, atan x, etc. dif(f(x), x) Calc/Differentiate dif(f(x), x, n) Calc/Differentiate int(f(x), x) Calc/Integrate int(f(x), x, a, b) Calc/Integrate a Simplify an expression Simplify Approximate Simplify/Approx Cancel a menu choice Esc-key Move around in a menu Tab-key Change highlighted expression N, H-key Click expression Insert highlighted expression F3 , F4 with ( )’s Right mouse button CHAPTER 0. INTRODUCTION AND DERIVE BASICS 8 (x + 1)(x − 2). This means that the roots of f (x) are x = −1, 2, i.e., these are the only solutions to f (x) = 0. We can also do this by using the SOLVE function. To do this we highlight . If you forget the function the equation, say x2 −x−2 = 0 and click the of a button just hold the cursor on it and a brief explanation will appear. An alternate method is to choose Solve/Algebraically from the drop down menu. The quadratic formula is used to solve for the roots so it is possible the answer will involve square roots (and even complex solution, e.g., x2 + 1 has no real roots but it does have two complex ones, namely, x = ±i). If f (x) is not a quadratic polynomial then Derive may not be able to factor it; nevertheless, it may be able to solve the equation f (x) = 0. As an example, sin x = 0 has infinitely many solution x = mπ where m is any integer. If we use Derive to solve this equation it gives the 3 solutions corresponding to m = −1, 0, 1 (these are the principle solutions and all others are obtained by adding or subtracting multiples of 2π). Finally, the simple equation sin x − x2 = 0 cannot be solved exactly in Derive although it is obvious that x = 0 is one solution and by viewing the graph we see another one with x ≈ 1. In order to approximate this solution we need to choose Solve/Numerically.6 You will then be asked for a range of x’s (initially it is the interval [−10, 10]). Since there are (at least) 2 solutions in [−10, 10], you should restrict the interval to say [.5, 1] which seems reasonable based on the graphical evidence. The result is that Derive gives the solution x = .876626. We will discuss how this computation is done later in Chapter 5. Note that Solve/Numerically will only give one solution (or none if there are none) even if the interval you choose cantains several solutions. To find additional solutions you need to use Solve/Numerically again but with an interval avoiding the first solution. 0.8 Substituting √ If you have an expression like x2 + 1/x and you want to evaluate this with say x = 3 or if you solved an equation f (x) = 0 and you want to substitute that value of x back into f (x), you start by highlighting the desired 6 In DfW5 you choose Solve/Expression and then select the Numerically solution method option. 0.9. CALCULUS 9 button and the substitution form opens expression. Next you click the up. You need to fill in the substitution value so you would just type 3 in the first example. On the other hand, if the substitution value is large, say lots of digits or some other complicated expression in the algebra window, the easiest way is to move the form out of the way (just hold down the left mouse button in the top strip and drag to another location) and select the desired expression by clicking on it. Then, paste it into the form by right clicking and choosing Insert. If there happen to be other variables in the expression you may have to change the variable in the variable list box. 0.9 Calculus This menu item is very important for us. After choosing the Calculus drop down menu, you get a submenu with Limit, Differentiate, Taylor series, Integrate, Sum, Product, and Vector. There are also buttons for most of these operators. After you have authored an expression, you can differentiate it by either clicking the button or choosing Calculus/Differentiate from the drop down menu. The form will have entries for what variable to use and how many times to differentiate, but it usually guesses right so you can just click OK. Then simplify. To integrate an expression, first author it or highlight it if it is already button or else choose in the algebra window, then either click the Calculus/Integrate. The form will have entries for what expression to integrate; it will guess you want to integrate the highlighted expression. It will have an entry for what variable you what to integrate with; again it will probably guess right. It will also have entries for the limits of integration. If you want an indefinite integral, just click the appropriate button and click OK. For a definite integral click the appropriate button, type in the upper/lower limit, then click OK. See Figure 0.2 on the next page for several examples using Differentiate and Integrate on the Calculus menu. The options Calculus/Limits is similar to the above. To find x2 − 1 x→−1 x + 1 lim or choose Limits from the you enter the expression, then either click Calculus menu. You fill in the variable (which is x) and the limit point which 10 CHAPTER 0. INTRODUCTION AND DERIVE BASICS Figure 0.2: Using the Calculus menu or choose Simplify to get the answer. is −1 since x → −1. Then click In a similar manner Derive does summation and product problems. Special notations are used; namely, n X ai = a1 + · · · + an i=1 and n Y ai = a1 · · · an . i=1 Let us discuss the summation notation which may be new to you. If a1 , . . . , an are numbers then n X ai = a1 + · · · + an . i=1 P The symbol on the left, ni=1 ai , is read as “the sum of ai as i runs from 1 to n.” Often ai is a formula involving i. So 5 X i=0 i 2 = 02 + 12 + 22 + 32 + 42 + 52 = 55. 0.9. CALCULUS 11 Figure 0.3: Examples of Limits, Products and Sums You can do this computation in Derive by clicking the or using the . Fill Sum option on the Calculus menu. Just author i^2 then click in the required variable i along with the starting value 0 and end value 5. Simplify to get 55. P As an interesting aside, edit the above sum and have Derive Simplify ni=1 i to get the formula: n X i=1 i= n(n + 1) . 2 This formula is used in many calculus texts to evaluate certain Riemann sums. See Figure 0.3 for some examples. Note that in Figure 0.3 3 Y xi = x · x2 · x3 = x6 . i=1 The option Calculus/Taylor will be explained in Chapter 7. 12 0.10 CHAPTER 0. INTRODUCTION AND DERIVE BASICS Plotting Supposed you want to graph the function x sin x. You simply author the expression, by clicking the pencil button , to be plotted and then click the button. A plot window will then opens up and the icon- button bar will change to a new set of buttons. You then click the again (it’s position is different in the plot window) and the graph will be drawn. There are several different ways to view the algebra and plot window together. The one we used to produce the pictures in the manual is to first select the algebra window (if you are currently in the plot window you can button) and then choose go to the algebra window by clicking the Window/Tile Vertically from the menus. This will split the screen into two windows: an algebra window on the left and a plotting window on the right. These windows each have a number in their upper left hand corner. You can have several plot windows associated with a single algebra window but you cannot plot together expressions from different algebra windows. You can switch windows by either clicking the top strip of the window or clicking the or buttons. Actually you can click anywhere in the window to select it but the top strip avoids changing the highlighted expression in the algebra window or moving the cross in the plot window. You can plot several functions in the same plot window. Move to the algebra window, highlight the expression you want to plot, switch to the plot in the plot window. Now both expressions window and then click the will be graphed. You can plot as many as you want this way. The plot window also has a menu option, Edit/Delete Plot, for removing some or all of the expressions to be plotted. Pressing the Delete-key also removes the current plot. When you plot, there is a small crosshair in the plot window, initially at the (1, 1) position. You can move the cross around using the arrow keys or by clicking at a new location. The coordinates of the cross are give at the bottom of the screen. This is useful for such things as finding the coordinates of a maximum or a minimum, or where two graphs meet. In order to center the graph so that the cross is in the center of the window, click the button. This is useful for zooming in and out to get a better view of the graph. There are several buttons for doing this in the plot window. Take a , and for zooming look and you will see a button for zooming in, namely 0.10. PLOTTING 13 and various ways of changing just the x-scale or just the y-scale. out You should try clicking these buttons to see exactly what happens. In general, these buttons change the scale of the plot window by either button7 doubling or halving it. You can customize these by using the (that’s a picture of a balance scale). Just click this button and fill out the form the appears with your own numbers. You can see the current scale at the bottom of the screen. We mentioned above how to plot any number of graphs simultaneously by repeatedly switching between the algebra window and the graphics window. Another technique for plotting three or more functions is to plot a vector of functions. This just means authoring a collection of functions, separated by commas and surrounded by square brackets. For example, plotting the expression [x, x^2, x^3] will graph the three functions: x, x2 , and x3 . In order to plot a collection of individual points one enters the points as a matrix, for example authoring the expression [[-2,-2], [0,-3], [1,-1]] and then plotting it will graph the 3 points: (−2, −2), (0, −3) and (1, −1). A quick way of authoring a vector is to use the button and a quick button. One then just fills out the way to enter a matrix is to use the form that opens up. So for example with the 3 points above we would click the matrix button and select 3 rows and 2 columns. The form will open up and we then fill in the 6 numbers above in the obvious order. You move between fields by either clicking or using the Tab-key. When plotting points you have a choice of connecting the points with a line segment so that it appear like the graph of a function. You do this by choosing Options from the menu bar. There are lots of interesting items on this menu that will allow you to customize plotting colors, the size points are plotted, axes and so on. To connect points we choose Points and then check the Yes button.8 We can also modify the size of the points by clicking the appropriate button. See the Figure 0.4 on the next page where each of these techniques is demonstrated. Choosing Option/Plot Color controls the color of a plot and whether the colors should rotate with each new graph. 7 This functionality has been replaced in DfW5 with the Set/Plot Region and Set/Plot Range menu options. 8 The default is for points to be connected but if data points are to be plotted then it is usually best to select No. 14 CHAPTER 0. INTRODUCTION AND DERIVE BASICS Figure 0.4: Using Plot for graphics 0.11 Defining Functions and Constants If you Author f(x), Derive will put f x on the screen because it thinks both x and f are variables. If you wish to define f (x) = x2 + 2x + 1, for example, you could Author f(x) := x^2 + 2x + 1. Note that we use := for assignments and = for equations. Alternately, you could choose Declare/Function, and then fill in the form with f(x) for the function name and x^2 + 2x + 1 for its value. Derive will then enter this as above with the :=-sign. See Figure 0.5 on the facing page. Constant are treated just like functions except there are no arguments. In order to set a = 2π for example you type a := 2 pi. Then, whenever you simplify an expression containing a, each occurrence is replaced with 2π. In many problems you find it useful to have constant names with more than one letter or symbol, which is the default in Derive. For example variables with names like x1, y2, etc. will be used frequently as are names like “gravity”. This can be done by declaring the variable, for example, to use the variable x1 we author x1:=. Now any use of these letters will be 0.11. DEFINING FUNCTIONS AND CONSTANTS 15 Figure 0.5: Examples of Declare, Simplify and approximating treated as the single variable x1. An interesting function defining technique is provided by the factorials. For n = 1, 2, . . . we define n-factorial, denoted by n!, as n! = n · (n − 1) · · · 2 · 1 n = 1, 2, . . . and for completeness we define 0! = 1. These numbers are important in many formulas, e.g., the binomial theorem. One observes the important recursive relationship n! = n(n−1)! which gives the value of n! in terms of the previous one (n − 1)!. Thus, since 5! = 120 we see immediately that 6! = 720 without multiplying all 6 numbers together. In Derive we can recursively define a function F(n) satisfying F (n) = n! by simply typing F(n) := IF(n=0, 1, n F(n-1)) where the properties of the Derive function IF(test, true, false) should be pretty obvious. The definition forces the function to circle back over and CHAPTER 0. INTRODUCTION AND DERIVE BASICS 16 over again until we get to the beginning value at n = 0, i.e., F (n) = n · F (n − 1) = · · · = n · (n − 1) · · · 2 · 1 · F (0) = n! We will give several other examples of this technique in the text. 0.12 Defining The Derivative Function A common application of defining functions is to have f (x) defined but the calculus problem requires a formula involving both f (x) and f 0 (x). For example, the equation of the tangent line at the point (a, f (a)) is given by y = f (a) + f 0 (a)(x − a). If you try to define the derivative of f (x) by g(x) := dif(f(x), x) and then evaluate g(2), you get DIF(F(2), 2), which is not what you want. Of course, we could also just compute the derivative and define g(x) := to be that expression. The advantage of defining it as a function is that if we change the definition of f (x), then g(x) will also change to the derivative of the new f (x). Thus, we get to use the formula for more than one application. Here’s a way to define the derivative as a function correctly: Start by Authoring f(x):= and we can enter the specific definition of f (x) now or button and enter f(u) in wait until later. Next, click the derivative the form (note the variable is u not x). Select the Variable u and press OK. button (with the previous expression highlighted) Now click the limit and enter the Variable u and the Point x. Finally, Author g(x):= and insert the previous expression by right-clicking and selecting Insert. The result is the expression G(x):= LIM( DIF( F(u), u), u, x). Actually, you could have just Authored this expression directly but the syntax and the number of parentheses is a little confusing in the beginning so the above method is easier and probably faster. The above technique is a little confusing and so to simplify matters we have included a function SUBST(u,x,a)9 in the ADD-HEAD file (we’ll discuss this file in more detail later). This function simplifies its argument u before it substitutes a for x. Thus, an alternate definition to the derivative function is given by G(x):= SUBST( DIF( F(u), u), u, x) See Chapter 2 where more discussion of this issue is given. 9 This function was added to DfW5. 0.13. FUNCTIONS DESCRIBED BY TABLES 0.13 17 Functions Described By Tables In calculus functions are typically described by giving a formula like f (x) = 2x3 + 5 but another technique is to describe the values restricted to certain intervals or with different formulas on different ranges of x-values. As an example, consider the function 2x + 1 for x < 1 f (x) = x2 for 1 ≤ x ≤ 2 4 for 4 < x which defines a unique value f (x) for each value of x. The problem is how do we define such a function using Derive? One basic technique is to use the logical IF statement. The syntax is IF(test, true, false). For example, if we enter and simplify IF(1 < 2, 0, 1) we get 0 whereas IF(1 = 2, 0, 1) simplifies to 1. Now our function above is entered as: f(x):= IF(x < 1, 2x + 1, IF(x <= 2, x^2, 4)) Notice how we use nested IF statements to deal with the three conditions and that with four conditions even more nesting would be required. Now once f (x) has been defined we can make computations such as Simplifying F(1) (should get 1), computing limits such as the right-hand limit limx→1+ f (x) (should get x2 evaluated at x = 1) or definite integrals using approX to simplify. We can also plot f (x) in the usual manner described in the previous section. Notice from Figure 0.6 that the function y = f (x) is continuous at all x 6= 1. At x = 1, both left and right limits exist but they are not equal so the graph has a jump discontinuity. As the number of table entries increases we are forced into using nested IF statements and the formulas become quite difficult to read and understand. An alternate approach is to use the Derive function CHI(a,x,b) which is simply 0 for x ≤ a CHI(a, x, b) = 1 for a < x < b 0 for b ≤ x Then except for x = 1 our function f (x) above satisfies: 18 CHAPTER 0. INTRODUCTION AND DERIVE BASICS Figure 0.6: Functions defined by tables of expressions F(x):=(2x+1) CHI(-inf,x,1) + x^2 CHI(1,x,2) + 4 CHI(2,x,inf) This technique works for graphing and limit problems and moreover gives the exact result at each point where the function is continuous. 0.14 Vectors Vectors are quite useful in Derive, even for calculus. They are also useful in plotting. To enter the 3 element vector with entries a, b, and c, we can Author [a, b, c] directly. It is important to note the square brackets which are used in Derive for vectors; commas are used to separate the elements. An easier approach is just click the button and fill in the three values on the vector input form. Derive also provides a useful function for constructing vectors whose elements follow a specific pattern. The vector function is a good way to make lists and tables in Derive. For example, if you Author vector(n^2, n, 1, 3), it will simplify to [1, 4, 9]. The form of the vector function is 0.14. VECTORS 19 vector(u,i,k,m) where u is an expression containing i. This will produce the vector [u(k), u(k + 1), . . . , u(m)]. You can also use the Calculus/Vector menu option to create a vector. So, for example, to obtain the same vector as before, you start by authoring n^2. Now choose Calculus/Vector and fill in the form setting the Variable to n (not x), the start value to 1, the end value to 3 and the step size to 1 (that’s the default value). A table (or matrix) can be produced by making a vector with vector entries. If we modify the previous example slightly by replacing the expression n^2 with [n, n^2] and then repeating the above we get [[1, 1], [2, 4], [3, 9]] which displays as a table with the first column containing the value of the index n and the second column containing the value of the expression n2 . This is a good technique for studying patterns in data. See Figure 0.7 for some examples. Figure 0.7: Using the Calculus/Vector command We have already seen two important applications of vectors in Section 0.10; namely, • Plotting a vector of 3 or more functions [f (x), g(x), h(x), . . . ] plots each CHAPTER 0. INTRODUCTION AND DERIVE BASICS 20 of these functions in order. • Plotting a vector of 2-vectors [[x1 , y1 ], [x2 , y2 ], . . . ] will plot the individual points (x1 , y1 ), (x2 , y2 ), . . . . We will have other application that will require us to refer to the individual expression inside of a vector. This is done with the Derive SUB function (which is short for subscript). Thus, for example, [a,b,c] SUB 2 simplifies to the second element b. Derive will display this as [a, b, c]2 which explains the name. For a matrix or vector of vectors then double subscripting is used so that, for example, if 1 2 y := 3 4 then Authoring y SUB 2 SUB 1 will be displayed as y2,1 and simplify to 3 (because it’s on row 2 and column 1). 0.15 Printing and Saving to a Disk You can save the expressions in an algebra window to either a floppy disk or the hard drive and come back later to continue working on them. Unfortunately, the plot windows are not saved10 but the pictures can be put on the clip board and saved as graphics files using suitable graphics software. To save to a floppy, put a the diskette in say the A: drive and activate the algebra window that you want to save. Click File/Save As and fill out the menu of options with the drive A: and a file name such as Lab5 or just save to A:LAB5 and enter. Derive will add the extension .MTH11 to indicate that this is a file consisting of Derive expressions. After the file has been saved you can update it by simply pressing the button. You will most likely save your files to the network harddisk. For example, suppose your network harddisk is the H:-drive. To save a file, just refer to it as say H:LAB5 or switch to the H:-drive and view your files. Later, you can recall these expressions by using either the File/Open or File/Load/Math options. The second method is used primarily to add 10 In DfW5 plots can be embedded in the algebra window and are saved along with the expressions using the new DFW file format. 11 DfW5 has added a new file format with the DFW extension. The MTH files can still be used. 0.16. HELP 21 expressions to an existing window. If you forget the name of your files just type either A: or H: and press the enter–key to see a listing of your files. During the course of your session with the computer you will make lots of typing and mathematical mistakes. Before saving your work to a file or before printing and turning your lab in for grading you should erase the unneeded can be used for entries and clean up the file. The three buttons this purpose. For example, if you select several expressions by say dragging the mouse pointer over them with the left button held down and then press button these expression will be removed. Clicking will undo the the last delete. You can move a block of highlights lines by holding down the right mouse button and dragging the block to a new location. Of course, when you delete or move some lines then the line numbers will no longer be in a proper sequence of #1, #2, . . . . You can correct this by pressing the renumbering button . You should practice these commands on some scratch work to make certain you understand them.12 One way to use the move command is to write comments in the file and placing them before computation. Many of the *.MTH files that we wrote for this lab manual use this technique. To do it, just author a line of text enclosed in double quotes, for example, "Now substitute x=0.". Then, move this comment to the appropriate location. You can print all the expressions in the algebra window (even the ones you can’t see) by pressing the button. You do the same thing to . Typically, print a graph. Just activate the plot window and press students turn in the labs by printing out the algebra window and penciling in remarks and simple graphs. More extensive graphs can be printed out. Some combination of hand writing and printouts should be the most efficient.13 0.16 Help You can obtain on-line help by choosing Help. This help feature provides information on all Derive functions and symbols. Suppose that you want to know how to enter the second derivative of a functions f (x) by typing. 12 DfW5 has changed the methods for moving expressions, correcting expressions and adding comments. See Appendix B for details. 13 The new functionality of embedded graphics in DfW5 allows for more flexibility in these matters. 22 CHAPTER 0. INTRODUCTION AND DERIVE BASICS For example, maybe this expression is to be used as part of another function. There are three techniques for learning how to do this. The first method starts by authoring F(x):= to declare f (x) to be a function of x. Next we use the menus with Calculus/Differentiate to calculate the second derivative by entering F(x) for the function and 2 for the order. Then, press Author followed by the pull-down key F3 or right click in the author box and select Insert. This will enter Derive’s way of typing the expression, in this case it’s DIF(f(x),x,2). The second method is to use the online help by choosing Help on the main menu. One then searches for a topic like differentiation or vector to get further information. 0.17 Common Mistakes Here are a few common mistakes that everyone makes, including the authors, every once in a while. It just takes practice and discipline to avoid these problems, although, it is human nature to blame the computer for your own mistakes. Fortunately, the computer never takes insults personally and it never takes revenge by creating sticky keys, erasing files, locking up, or anything else like that ... or does it? Q1. I tried to plot the line ax + b and instead I got an error message about “too many variables”. What did I do wrong? You must define a, b to have numerical values, otherwise Derive treats your function as f (a, b, x) which it cannot plot. Q2. I tried to plot the family of parabolas x2 + c and I got an error about too many variables. What did I do wrong? Same problem as above, except now Derive is trying to plot a surface z = f (x, c)in 2-dimensional space. You probably want to enter and Simplify a vector of functions such as VECTOR(x^2 + c, c, 0, 4). Now Plot this vector of 5 functions: x2 , x2 + 1, x2 + 2, x2 + 3, and x2 + 4. √ Q3. I entered the expression 5 − x correctly, but when I substituted x = 9 and simplified I got 2î. What happened? You took the square root of a negative number which is not allowed when you are working with the 0.17. COMMON MISTAKES 23 real number system. Derive treats this as a computation with complex numbers and uses the complex number i (where i2 = −1). Q4. I solved for the 3 roots of the cubic x3 −2x2 +x−2 and I got x = 2 which I guessed from the graph but the other two solutions were x = î and −î. Where do these last two come from? If you factor the cubic instead of using Solve you would get (x − 2)(x2 + 1). The complex solutions come from that quadratic term. In calculus, we just ignore those complex solutions. For example, numerically solving the above cubic will give only real solutions. Q5. I differentiated ex and I got ex ln e, what’s wrong? Nothing, Derive is treating the letter e as an ordinary symbol like a or b. You probably wanted Euler’s constant e which can be entered using the symbol bar or with #e. Q6. I tried to author the inverse tangent function arctan x and I got a · r · c · tan x instead. What’s wrong? Derive recognized the tan x part but treated the other symbols as individual constants. Use atan x. Q7. I entered the vector [v1 , v2 , v3 ] by typing [v1,v2,v3] and I got [v · 1, v · 2, v · 3] instead. What happened? You must declare these multi-letter variables first before they can be treated as a single variable. To do this just author v1:=, v2:= and v3:=. A quick way to do this is to simply author the vector [v1:=, v2:=, v3:=]. Q8. I tried to author x^n and I got a syntax error! How was this possible? The problem here is that either x or n is previously defined as a function. For example, maybe you had authored x(t) := sin t. You can check on this by scrolling up to find the definition. If instead, you know the problem is that x(t) is defined and you want to remove that definition, then just author x:=. In extreme cases you might just open a new window and copy over some of your expressions using the Copy and Paste technique. Q9. I entered and simplified sin(2π) and I got SIN([2π]) instead, what happened? You authored sin[2pi] instead of sin(2pi). Derive treats square brackets not as parenthesis but as a device for defining vectors, see Section 0.14. 24 CHAPTER 0. INTRODUCTION AND DERIVE BASICS Q10. I tried to show that limn→∞ (1 + n1 )n = e, instead Derive returns a question mark indicating that it can’t do this problem. What’s wrong? Same as above, check that your parenthesis are not brackets. Chapter 1 Curve Sketching 1.1 Introduction Before the widespread use of computers and graphing calculators, graphing a function f (x) was done by a combination of techniques including: • Plotting some judiciously chosen points. • Locating the intercepts on the x-axis by finding solutions to the equation: f (x) = 0. • Using Calculus to finding the local minima and maxima and where f (x) is increasing and decreasing. • Finding the points where the graph is curving upward and where it is curving downward. The transition point in between is called an inflection point. • Finding the horizontal and vertical asymptotes. Graphing is easier with a computer algebra system. In order to understand the behavior of a function f (x) we can plot it using Derive’s plot window (see Section 0.10 for instructions on plotting.). Moreover, we can also find the local minima and maxima and the other items above if we need them. We do this in Chapter 3. It is also possible to make a small change in the function f (x) and then plot that change to see how the graph is affected. We can also see important aspects of the graph by zooming in or out and moving around to different parts of the graph. In this lab you will develop your skills at graphing with the computer. 25 26 1.2 CHAPTER 1. CURVE SKETCHING Working with Graphs In many problems involving periodic behavior, such as oscillating springs, pendulums, planetary motion and others, the solutions generally have the form a sin(b(x − x0 )) where a, b and x0 are given numbers. This raises the question of how the graph of a function, such as sin x, changes when subject to the above modifications. You should observe the changes by comparing with the original function but you should also think about why the changes make sense, for example, what does changing a do, what is the geometrical significance of the point x = x0 on the x-axis. Figure 1.1: Using vector to plot several graphs As our first task, lets plot y = f (x) + c where f (x) = sin x and where c varies over the range −2, −1, . . . , +2. We start by clicking the pencil button , entering sin x + (-2) and pressing OK. Next, click the button 1.2. WORKING WITH GRAPHS 27 and the Plot Window appears. Notice that there are a different set of buttons at the top. The most important ones are the plot button , the various which doubles the scale in each direction and zoom buttons such as which centers the plot on the cross. The the cross buttons such as cross is the little reference point whose coordinates are shown in the lower left corner of the DfW window. You move the cross by either pointing and clicking or else using the arrow keys. Clicking the button will plot expression that is highlighted in the Algebra Window. We return to the Algebra Window by clicking the button and then entering the next expression sin x + (-1). Pressing puts us back in the Plot Window and by clicking again we plot the second expression in the same window as the first so that we can compare them. The second graph appears to be the same as the first except that it is shifted up one unit. We proceed in a similar manner with the remaining three expressions with each successive graph shifting up another unit. We like to have the Algebra Window and the Plot Window visible at the same time. We do this by splitting the screen using the Window/Tile Vertically command. Of course, you can work with only one window at a time but it is easy to change the active window by simply clicking on the name strip. You can actually click anywhere in the window to activate it but this is not a good idea in the Plot Window since this will also move the cross. Typically, the cross is carefully located at some important feature of the graph and you don’t want to move it unnecessarily. There are a few shortcuts that we can do to make this task a little easier. First of all it’s not necessary to retype each expression over and over again. Instead, we click on the expression we want to modify (this causes it to be . We then right click in the author highlighted) and then we press form and a menu opens up. We choose the Insert expression option and the highlighted expression appears in the author box. We then just change the -2 to -1 and press OK. That does it and we can now plot the new expression. A very fast way of plotting similar expressions all at once is to uses vectors 1 . Select the Calculus/Vector menu and enter sin x + c in the form. Click the Variable list box and select the variable c. For this example, set the Starting value to -2 and the Ending value to 2. The Step Size can be left 1 See Section 0.14 on page 18 for more information about the vector function 28 CHAPTER 1. CURVE SKETCHING at 1 although in other examples you might want to change this. Press OK. Next we need to simplify the resulting expression VECTOR( SIN(x) + c, c, -2, 2) button or by using the Simplify menu. The button by clicking the method is faster. With the vector of five expressions highlighted, click the button twice and all five graphs are plotted. One problem with this technique is that you can’t see the pattern, i.e., each successive graph is shifted up one unit. On the other hand, we can compute the 5-vector above and plot the individual elements in the vector by clicking on them and then plotting. This way you can plot say the first two or three until you see the pattern and then plot the entire vector to plot the rest. Another interesting technique is to define our function f (x) = sin x. But unlike a Calculus text that uses the equal sign both for equations and definitions in Derive we need to make a distinction. You must remember that the := symbol is for assignment whereas the = sign is used for equations and comparisons. To make a definition we author f(x):=sin x. We can then enter expressions such as f(x)+c which clearly shows the modifications we have in mind. Many other options are also possible; for example, editing the vector formula above by replacing the expression with f(x + c)gives an interesting result upon graphing. See if you can see a traveling wave in the plot window. Is it traveling from left to right or right to left? Warning You can change the function definition by simply Authoring f(x) := with a new expression. One problem with making definitions is that you tend to forget them, especially as you move on to a new problem. Thus, if you use the same letter f (x) in every problem you will definitely have problems and get confused as to the current definition of the expression f (x). A good strategy is to use definitions as little as possible and only when necessary. Use different letters, say f1(x):= for the first problem and f2(x):= for the second, and so on. You might also want to eliminate a definition as soon as you are done with it. It is important to note that once you define a function by this method it will not go away if you simply erase that line from your algebra window because it is in the computer’s memory. The way to completely remove a definition using the letter f is to author the expression f:=. This gives f an empty definition. 1.3. EXPONENTIAL VS POLYNOMIAL GROWTH 29 You might note that after you have defined a function in Derive it thereafter is displayed with uppercase letters. This is just a visual cue and it is not necessary to type expressions using uppercase letters2 1.3 Exponential vs Polynomial Growth Suppose we want to compare the behavior of the function x4 and with the exponential ex . For example, suppose we want to know which function grows the most as x gets large. If we graph x4 we see it has the same basic shape as the parabola x2 (you probably guessed this). It is a little flatter than the parabola between −1 and 1 and it grows more quickly for |x| > 1. If we now graph ex (be sure to use the special symbol ê and not the letter e) on the same graph and zoom out once, we see that the graph seems to get close to the x–axis as x gets larger in the negative direction (as x approaches −∞); that it crosses x4 at least twice; and it grows quickly when x is positive, but not as quickly as x4 ; see Figure 1.2 on the next page. One way to verify that the x–axis is a horizontal asymptote of ex is to highlight ex in the algebra window and choose Calculus/Limit and enter -inf for the ‘Point,’ as we did in Figure 1.2. To see where the curves cross we need to solve the equation x4 = ex . There are several ways to attack this problem. The most obvious is to simply look at the graph and estimate the coordinates of the intersection points. Using the cross is most helpful for this because we can click on the point of intersection and read off the coordinates in the Plot Window. The arrow keys can also be used to more precisely position the cross. Further accuracy can be obtained button and then zooming in by centering on the cross by clicking the button. several times by pressing the In order to get an exact solution to an equation we return to the Algebra button. Note that the little icon is a magnifying Window and use the glass. For example, a simple quadratic equation such as x2 + x − 2 = 0 can solved in this manner by entering the equation in the solve form and setting the variable to x. Pressing OK and then simplifying by clicking the button yields the two answers in a vector: [ x = 1, x = -2] . 2 lab. Derive does have a special mode in which case matters but we don’t use it in the CHAPTER 1. CURVE SKETCHING 30 Figure 1.2: The functions x4 and ex Unfortunately, Derive can not solve all equations (nor can anybody else!) and so we need to also consider approximate numerical solutions. The technique for doing this uses calculus and will be discussed in Chapter 5. For example, our equation x4 = ex cannot be solved exactly. If you try then Derive just returns the empty solution vector []. We can get approximate solutions if we use the Solve/Numerically3 menu. You enter the equation x^4 = e^x and then choose an appropriate interval which you believe contains the desired solution. This choice is usually made by looking at the graph. For example, the negative solution in Figure 1.2 appears to be in the interval [−1, 0]. Making the interval larger will not increase the number of solutions since the answer, unlike exact equation solving, has at most one answer. If there are no solutions in the interval, then you need to specify a new interval. In our example, the other solution in Figure 1.2 can be found if we choose the interval from 0 to 2. 3 In DfW5 you choose Solve/Expression and then select the Numerically solution method option. 1.3. EXPONENTIAL VS POLYNOMIAL GROWTH 31 Are there any other solutions? It is pretty clear that there are no other solutions for x < 0 but what about large x? From the graph it appears that x4 grows much faster than ex . But of course ex has “exponential growth” so perhaps ex > x4 for large enough x. To test this we try zooming out several times in the Plot Window by clicking . But both functions grow very quickly and it is a little difficult to be successful with this method. Back in the Algebra Window we can try to numerically solve x4 = ex for larger x. If we choose the interval to be 2 to 20, we get the solution x = 8.61316. So the graphs cross at this point. To find the y value of this point, we to substitute 8.61316 into x4 . The result use the substitute button approximates to 5503.64. To see this on the graph we need to zoom out once so that the x–scale includes x = 8.61316. Then we need to zoom out on the y–axis without zooming out on the x–axis. The need to do this is why there are those extra zoom buttons. After zooming out several times we obtain the graph of Figure 1.3. Another approach is to use the Set/Scale menu and enter an x-scale of 5 and a y-scale of 5000. Figure 1.3: The functions x4 and ex , rescaled CHAPTER 1. CURVE SKETCHING 32 There are a couple things this demonstration shows. First that in order to see the important features of a graph it may take some skill at moving around and manipulating the scale of the graph. Moreover, even though we can clearly see the two graphs intersecting at x = 8.61316 in Figure 1.3, we can no longer see the other two solutions. So it may not be possible to see all the important features in one plot. In the exercises you will learn how to move and scale in the plot window and to use the algebra window in order to find all the important features of one or more graphs. 1.4 Laboratory Exercises 1. Use the author button and the approximate button (or Simplify/Approximate) to get decimal approximations for each of the following. a. 81/2 b. sin( π4 ) c. sin( π4 )/51/2 2. Let f (x) = 1/(1 + 2x2 ). a. Graph each of the following f (x) − 1, f (x), f (x) + 1, and f (x) + 2 in a plot window. Then, use the Window/New 2D-Plot Window command to open another plot window and plot f (x − 1), f (x), f (x + 1) and f (x + 2) in that window. (Hint: The Vector menu can be used to simplify the typing.) b. What does the transformation f (x) → f (x) + a do to the shape of the graph? to the position of the graph? c. What does the transformation f (x) → f (x + a) do to the shape and position of the graph? 3. Graph cos x, 2 cos x, and cos(2x) and explain what the transformations f (x) → f (ax) and f (x) → af (x) do to the graph of f (x). 4. What do the transformations f (x) → f (−x) and f (x) → −f (x) do? Graph f (x) = x5 − x2 + 1 and f (−x) and −f (x). 1.4. LABORATORY EXERCISES 33 5. Let g(t) = sin t + cos t. a. Graph g(t). b. What sort of transformations should be applied to sin t to make its graph look like the graph of g(t)? c. Use Derive’s crosshair to find the maximum value of g(t) and to find the first root of g(t) to the left of zero. d. Use these numbers to find a and b so that g(t) = a sin(t + b), at least approximately. *e. Find exact values of a and b so that sin t + cos t = a sin(t + b). Hint: Set the simplification of trigonometry functions to “Expand” using the Declare/Algebra State/Simplification menu. Then evaluate a sin(t + b). 2 6. Let f (x) = e−ax where a is a constant. a. Plot f (x) for a = −2, −1, 0, 1, and 2. You can use the vector function if you like but plot each expression one at a time so you can see its graph. b. For each of the five values of a determine whether the graph is curving upward, curving downward, no curving at all or curving both ways. If the graph has both upward and downward curving graphically approximate the points where there is a transition between upward and downward curving. These are the inflection points. Print out the Plot Window and mark it up with your pencil indicating which graph corresponds to which value of a, inflection points, etc. 7. Find the points where the curves ln x and x1/4 intersect. Make two (or more) graphs with different scales showing the places where the curves intersect. 8. Make separate graphs of each of the following functions. Using some of the graphing techniques such as zooming, centering, etc. Make sure CHAPTER 1. CURVE SKETCHING 34 your graphs show the main features such as the x and y–intercepts, the critical points, and the inflection points. 3x 4x2 + 1 a. sin(x) cos(20x) b. √ c. 1 1 + 5000(x − 1)2 d. x sin(1/x) *9. Enter the rational function (1) x6 + 3x5 + x4 + 1 2x4 − 1 a. Choose Simplify/Expand and select Rational. This gives a partial fractions decomposition of the function. (Partial fraction decompositions are used in integrating rational functions) Notice that the partial fraction decomposition consists of (a sum of) one or more proper rational functions (where the denominator has higher degree than the numerator) and a polynomial. What is the polynomial? b. Graph the rational function given by (1) and the polynomial you found in the first part. Zoom out a few times. How are the two graphs related when |x| is large? Explain why this is. *10. Let g(x) = −2x3 + 6x2 − 3x + 5 4x2 − 6x − 7 a. Graph g(x) so that your graph shows the main features of this function. b. This graph has a slant asymptote, i.e., an asymptote which is a line with nonzero slope. Zoom out a few times until you can see this slant asymptote. c. Find the formula for the slant asymptote by using Simplify/Expand. *11. In reading this chapter you might have wondered if ex and x4 intersect some place beyond c = 8.61316 · · · . You could use Derive to verify 1.4. LABORATORY EXERCISES 35 that there is no solution say between 8.7 and 100 and this would be strong evidence that they don’t intersect beyond c, but not a proof. So in this problem you are to find a proof that ex and x4 don’t intersect beyond c (without using Derive). Hint: By taking 4th roots we must show ex/4 > x for all large x. Now using Calculus, show that the slope of ex/4 − x is positive for all x ≥ 8, i.e., the derivative is positive. Use this to show ex > x4 for all x > c. 36 CHAPTER 1. CURVE SKETCHING Chapter 2 The Derivative 2.1 The Derivative as a Limit of Secant Lines Geometrically the derivative of a function f (x) at a point a is the slope of the tangent line of f (x) going through the point (a, f (a)). We can approximate the tangent line by the ‘secant’ line which goes through the points (a, f (a)) and (a + h, f (a + h)). The slope of this line, the rise over the run, is (f (a + h)−f (a))/h, and so, by the usual point-slope formula for a line, the equation of this secant line is f (a + h) − f (a) (x − a). y − f (a) = h As a + h gets closer to a, i.e., as h gets smaller, this secant line approximates the tangent line at a better and better, and so its slope approaches the derivative f 0 (a). We can visualize this with Derive by entering the following expressions: F(x) := x^3/3 SL(a, h) := f(a) + (f(a+h) - f(a))/h (x - a) The first step defines f (x) to be the function x3 /3. The second defines a function SL(a, h) which gives the secant line through the points (a, f (a)) so and (a + h, f (a + h)). For example, if we Simplify SL(1,1) we get 7x−6 3 that the equation of the secant line determined by the points (1, f (1)) and (2, f (2)) is y = 7x−6 . 3 37 38 CHAPTER 2. THE DERIVATIVE Now we want to fix a = 1 and plot several secant lines corresponding to different h’s. We can, for example, just Author and Simplify SL(1, 1), SL(1, 1/2), SL(1, 1/4), SL(1, 1/8), and SL(1, 1/16), and plot these lines and f (x) on the same graph. This simply means you highlight each of the simin the plot window, plified expression and then click the plot button see Section 0.10 on page 12 in Chapter 0 for the details on how to do this. This is illustrated in Figure 2.1. A nice way to calculate and plot these secant lines is to use vector techniques. Here’s how you would do it: Click the vector button and set the number of elements to 5. Now enter the 5 expressions above starting with SL(1,1) and using the Tab to move from entry to entry. Finally, simon the resulting vector [SL(1,1),...,SL(1/16)]. All plify and click five lines will be plotted one at a time. It all happens very quickly and it’s difficult to see the pattern of the plots. Actually, if you stare at the screen carefully just as you click the plot button you possibly can see (depending on the speed of your computer) an animation-like effect. Figure 2.1: Secant lines approximating the tangent line 2.1. THE DERIVATIVE AS A LIMIT OF SECANT LINES 39 If the drawing is too quick to see the animation, try the following method instead. Erase the 5 secant lines in the plot window by pressing the Del key 5 times. In the algebra window select an individual line in the vector by . repeatedly clicking on it. Then, activate the plot window and press Finally, repeat this process several times to see the pattern evolving in the plot window; namely, that the lines are rotating about the point (1, 13 ) on the graph. Moreover, the lines appear to be tending to the tangent line. In Figure 2.1 on the preceding page this pattern is clearly shown: the secant lines tend to the tangent line by rotating in a clockwise manner, i.e., with decreasing slope. We can use Derive to illustrate this effect using calculus. That is, as h tends to 0, the secant line tends to the tangent line by taking the limit: Author SL(1,h) and choose Calculus/Limit, taking the variable to be h (not x). After Simplifying we get 2 3x − 2 =x− . lim SL(1, h) = h→0 3 3 3 which, in fact, yields the tangent line to x /3 at x = 1. Check this out for yourself by plotting this function on your previous graph. Since the slope of the secant line is (f (a + h) − f (a))/h, this explains why we define the derivative as f (a + h) − f (a) (1) f 0 (a) = lim h→0 h and why the derivative is the slope of the tangent line. A quicker way of entering the 5 lines above is to observe that there is a pattern to the values 1, 12 , 14 , . . . ; namely 21n for n = 0, 1, . . . , 4. We can use this fact and the VECTOR function on the Calculus menu to simplify this task. Select Calculus/Vector and enter SL(1,1/2^n) in the form. Note that using uppercase letters is not necessary and that the highlighted expression will be replaced with whatever you type. For the Variable, scroll down and select n. Next we take the Starting value to be 0 since 20 = 1 and the Ending value to be 4 since 24 = 16. Click OK and simplify the resulting expression VECTOR(SL(1, 2^-n), n, 0, 4). The result is a vector of five secant lines as above. You will find that this is a convenient method of producing a large number of expressions without typing them individually. We can later change the definition of f (x) to a different function and use the SL(a, h) function to get secant lines to the new function. The file F-SECANT.MTH contains the definitions of SL(a, h) and the tangent line function, TL(a), discussed below. CHAPTER 2. THE DERIVATIVE 40 Tangent Lines In order to get a function TL(a) for the tangent line at a analogous to the secant line function SL(a,h), we need to be a little careful since the most obvious definition; namely, TL(a) := F(a) + DIF(F(a),a) (x - a) doesn’t work. This is because the order of evaluation is wrong. Consider what would happen if we evaluated TL(5). First 5 would be substituted for a and then the resulting expression, F(5) + DIF(F(5),5) (x - 5), would be evaluated. But DIF(F(5),5) doesn’t make sense. To solve this problem and to keep thing as simple as possible we use a special utility file ADD-UTIL.MTH. This file contains several new functions that we will be using for now on and so we suggest adding a few lines to start of every DfW session. This can be done by Opening or using Load/Math on the file ADD-HEAD1 Once this has been done, these new functions can be used. See Appendix A for a more detailed explanation. For example, the function SUBST(u, x, a)2 simplifies the expression u and then substitutes the value a for x in u. The three variables in the SUBST function are the expression, the variable and the evaluation point. It has the button to replace same effect as first Simplifying u and then using the x with a. To define the TL function we first make a function DF(x) of the derivative and enter F(u) with the variable set to using the SUBST function. Click and type in SUBST(). Then, u. With this expression highlighted click click in-between the parenthesis and insert the derivative by right-clicking and selecting Insert from the menu. Finally, type in next two arguments u and x separated by commas to complete the three arguments for this function. 1 All DfW4 files have the MTH extension although sometimes Windows doesn’t explicitly show the file extensions. However, DfW5 has added a new file format with the DFW extension which allows for the inclusion of graphics. The MTH files can still be used. The default extension used when Saving or Opening files depends on the version with DfW5 using the newer format. In this manual we usually drop the reference to the extension since it is assumed to be MTH. 2 This function was added to DfW5. 2.2. LOCAL LINEARITY AND APPROXIMATION 41 Pressing OK, you should get the first expression below: (2) (3) DF(x):= SUBST(DIF(F(u), u), u, x) TL(a) := F(a) + DF(a)(x - a) The TL function can then be defined as above. The utility file contains two more functions which you can use for the exercises and that eliminate the need to reproduce the definitions we’ve been discussing. To find the tangent line of say x3 /3 at x = 5 you enter and simplify the expression TANGENT(x^3/3, x, 5). Here again, the three variables in the TANGENT function are the expression, the variable and the evaluation point. Similarly, the secant line computed earlier can be obtained by entering SECANT(x^3/3, x, 1, 1/16). Here the last variable is the h-increment. When you Simplify either of these functions you get an expression of the form y = mx + b rather than just mx + b. You can still plot the entire equation and get the right result since DfW knows how to plot equations in addition to functions. You can test this by plotting the familiar equation x2 + y 2 = 1 to get the unit circle. Try it! Notice that using these functions it is not necessary to define any functions such as F(x):= or DF(x):= in order to get an answer. This is usually a better approach because the use of variables or definitions causes problem when you forget that something is defined. As a result you get some strange answers to your problems and you don’t know why. This difficulty is particularly common as you go from problem to problem in the exercises. Just remember to start off your labs by doing Load/Math to the ADD-HEAD file. 2.2 Local Linearity and Approximation One of the important properties of a function is that its graph can be approximated near a value x = a, or more precisely near the point (a, f (a)) on its graph, by the tangent line at that point. This means that as you zoom in closer to the point, the graph appears to be getting closer to the tangent line. Typically, the graph and the tangent line are eventually so close together that they are plotted as the same curves. This ‘local linearity’ is very useful in many applications. To see this local flatness in action, move the crosshair in the plot window we obtained above to the point (1, 1/3) where all the lines intersect, then center on the cross by clicking the button. CHAPTER 2. THE DERIVATIVE 42 Now we want to zoom in several times by clicking the zoomin button. Notice how flat the curve appears. Try clicking The zoom out button several times and then repeating to completely visualize this process. Approximating the Sine Function One of the most important functions in calculus is sin x and yet, with the exception of a handful of points such as: √ π 2 π , ... sin 0 = 0, sin = 1, sin = 2 4 2 we need either a calculator or Derive to obtain approximate numerical values. For example, Author sin( 13 ) and press the button. Derive does nothing with this expression other than to repeat it. On the other button and we get the approximate numerical value hand, pressing the sin( 13 ) ≈ 0.327194. To use local linearity we need to compute the tangent line at say a = 0 by authoring (make sure you Loaded ADD-HEAD) our new function TANGENT(sin x, x, 0) . The answer is y = x. You should verify this visually by plotting sin x and x together on the same graph. Now center the cross at the origin and zoom in several times. On the other hand, using the formulas d sin x = cos x and dx sin 0 = 0, cos 0 = 1 we can easily derive the above formula for the tangent line. The point is that we now have a powerful tool for approximating the values of sin x as long as x is small; namely, sin x ≈ x for x ≈ 0 . Looking back at our sin( 13 ) example above, we see that this simple technique has given a result which is accurate to roughly 2 decimal places. We can also use the above approach to approximate the derivative of a function and plot the result. For example, we know that the derivative of f (x) = x3 is 3x2 by using the standard formulas. On the other hand, the (x) with h fixed at some value like h = .01 function of x, g(x, h) = f (x+h)−f h 2.2. LOCAL LINEARITY AND APPROXIMATION 43 is a good approximation to 3x2 as one can see from Figure 2.2. The figure actually shows both plots although they appear to be only one curve. In Derive you should enter and Simplify the above expression (it sometimes helps to Expand the result to further simplify it). Then compare the graph with 3x2 by plotting both expressions together. Figure 2.2: Approximating derivatives using the difference quotient In this case, we can easily estimate how the close the two graphs are by algebraically simplifying (enter in Derive and press ) to get: (x + h)3 − x3 − 3x2 = 3hx + h2 . h Now for h = .01, the right hand side above no larger than .03|x| + .0001 and as long as we take −1 ≤ x ≤ 1 then this error term is approximately .03 and our accuracy is nearly 2 decimal places. Let us try this technique with sin x. Maybe you haven’t learned yet that the derivative of sin x is cos x. Here is way to strongly suggest this result CHAPTER 2. THE DERIVATIVE 44 visually: plot the functions sin(x + h) − sin(x) and cos x h for some small value of h, say h = .01. Can you tell the difference in the graphs? 2.3 Laboratory Exercises Start off your lab by Loading the ADD-HEAD file (use File/Load/Math). Note that the syntax of the SECANT and TANGENT functions are displayed on the second line of the ADD-HEAD file. 1. For each functions f (x) below (i) Plot the graph y = f (x). (ii) Use the function TANGENT(u,x,a) to calculate the tangent lines at the points a = 0, 2. (iii) Plot these tangent lines and turn in a sketch. Label the approximate slope of each tangent line by visual inspection. (iv) In the Algebra Window, compute the derivative f 0 (x) and use the button to plug in the values a = 0, 2. (v) Determine the exact slope of each of these tangent lines using part (v) and compare with your estimate for part (iii). 2. x 2 a. 1− c. 1 2 x −x 2 b. 1 2x − x2 2 d. sin x a. Using the TANGENT(u,x,a) function find the equation of the tan√ gent line for f (x) = 3 x (enter cube roots as x^(1/3)) at the point a = 8 and plot it along with the graph of f (x). √ 3 x at a = 8. Estimate b. In part a you found the tangent line to √ 3 9 by finding the y–value of this line when x = 9. Compare your answers with DfW’s own approximation to this quantity obtained button. by clicking the 2.3. LABORATORY EXERCISES 45 c. Using the plot window again give a reasonably accurate interval [c,d] containing the point x = 8 for which the tangent line approximates the function to 2 decimal place accuracy. (Hint: Plot the difference between the function and the tangent line and rescale to get a good picture. It is also helpful to use the Trace Mode which can be set from the Options menu of the graphics window.) 3. The acceleration due to gravity, a, varies with the height above the surface of the earth. If you go down below the surface of the earth, a varies in a different way. It can be shown that, as a function of r, the distance from the center of the earth, a is given by GM r3 for r < RAD RAD a(r) = GM for r ≥ RAD r2 where RAD is the radius of the earth, M is the mass of the earth, and G is the gravitational constant. All three of these are constants. In order to define the function a(r) and examine its graph, we’ll use the numerical values3 : GM := 4.002 × 1014 and RAD := 6.4 × 106 meters. a. Define a(r) using the technique in Section 0.13 and plot its graph. Rescale as necessary to give a good picture4 . b. Is a a continuous function of r? c. Is a a differentiable function of r? Explain your answer. d. Refine your answer to Part a so that the domain of a(r) is r ≥ 0. *4. Γ(x) is a differentiable function for x > 0 which is very important in applications. Derive knows this function but not how to differentiate it. You can get Γ in either version of Derive by typing gamma but in DfW you can also just click on the Γ in the Author Dialog Box. a. Graph Γ(x) and the four secant lines to Γ(x) through the points (3, Γ(3)) and (3 + h, Γ(3 + h)), for h = 1/2, 1/4, 1/8, and 1/16. [It is known that Γ(3) = 2, but you don’t really need this here.] 3 Simply Author the expression GM:=4.002 10^14 and similarly for RAD. The horizontal scale should reflect the value of RAD and the vertical scale can be determined from the numerical value of a(RAD) 4 CHAPTER 2. THE DERIVATIVE 46 b. Use the secant line you obtained in part a with h = 1/16 to approximate Γ(3.1). c. Have Derive approximate Γ(3.1). d. Use the graph to verify that Γ(n + 1) = n! = 1 · 2 · · · n whenever n = 0, 1, . . . , 5. (Since factorials play an important role in many applications this explain why the Γ function is important.) *5. Let f (x) = x2 sin(1/x) for x 6= 0 and f (0) = 0. In this problem you will show that f (x) is continuous and differentiable for all x but f 0 (x) is not continuous at 0. This means to find f 0 (0) you must use the definition of the derivative; you cannot just find f 0 (x) and take the limit as x → 0. a. Define f (x) as above by Authoring F(x) := x^2 sin(1/x) (don’t worry about x = 0 for now). Show limx→0 f (x) = 0. (Hint: Click and fill in the form.) b. Graph f (x), x2 , and −x2 , setting the plot scale to 0.1 horizontal and 0.01 vertical. Zoom in several times towards the origin by clicking the button and convince yourself that f (x) is continuous at x = 0. But notice that the curve oscillates up and down slightly. (0) . c. Find f 0 (0) by finding limh→0 f (0+h)−f h d. Find the derivative of f (x) using the 0 button. e. Make a new graph of f (x) and by zooming in several times convince yourself that f 0 (x) oscillates wildly between approximately ±1 as x approachs zero. Chapter 3 Basic Algebra and Graphics 3.1 Introduction Calculus is a beautiful and important subject. It derives its importance from its ability to describe and model basic phenomena in so many fields. Besides physics, chemistry and engineering, it is used in biology, economics, and probability. In order for calculus to be useful to you, you will need to understand calculus graphically and numerically as well as algebraically. Algebraically you learn how to differentiate functions given as complicated expressions. But you also need to understand the derivative visually as the slope of the tangent line and physically as a rate of change of y with respect to x. With Derive it is easy to learn all three of these aspects and to see the relations between them. 3.2 Finding Extreme Points As an example, consider the function f (x) = 2x4 − 3x3 . In order to understand the behavior of this function we can plot it using Derive’s plot window (see Section 0.10 for instructions on plotting.). The resulting graph can be seen in Figure 3.1 on the next page. The graph suggests f (x) has one local minimum which is the absolute minimum. Using the crosshair in the plot window (see Section 0.10) we can determine that the location of the minimum point has coordinates approximately given by x = 1.125 and y = −1.0625. We can get exact results by switching to the algebra window and doing some 47 48 CHAPTER 3. BASIC ALGEBRA AND GRAPHICS calculus. In Derive’s algebra window we choose Calculus/Differentiate or click the button to find the derivative. You get the answer by clicking . We can then choose Solve/Algebraically to find the simplify button where the derivative is 0, i.e., these are the critical points. Alternately, just click the solve button . The critical points occurs when x = 0 and when button to get decimal answers we x = 9/8. Pressing the approximate see that approximately 9/8 = 1.125, which is exact equality in this case. Now if we substitute this value for x into f (x) by highlighting the expression button to replace x with 9/8 2x4 − 3x3 and then using the substitution we get, after approximating, that y = −1.06787 which is close to our first estimate. Figure 3.1: Finding critical points Looking further at the graph we can see that f (x) does not have a local minimum or maximum at x = 0; in fact f 0 (x) < 0 on both sides of 0. The graph also shows that x = 9/8 is where the minimum occurs and that f (x) is decreasing on (−∞, 9/8] and increasing on [9/8, ∞). If we highlight the first 3.3. MAX-MIN PROBLEMS 49 (or choose Calculus/Differentiate), then we get derivative and clcik the second derivative. We can then solve to find the points of inflection, i.e., the places where the bending in the graph changes. The second derivative must be zero at these points but this criteria alone is not sufficient. Solving f 00 (x) = 0 yields x = 0 and x = 3/4. Again looking at the graph we see that both of these are indeed points of inflection since the graph is concave up on (−∞, 0], concave down on [0, 3/4], and concave up on [3/4, ∞). Insertion Tip In a typical problem the critical point will be complicated and retyping the expression in the substitution form is difficult and slow. A quicker method is to highlight the f (x) expression, 2x4 − 3x3 in our exbutton. Now click on parts of the answer ample, and then click the vector several times until the desired quantity, say 9/8 is highlighted. In the Substitution box click the right mouse button and select Insert. The highlighted quantity will be inserted in the form. You will find this a particularly useful technique when doing critical point problems algebraically instead of numerically. For example, f (x) = ax2 + bx + c. In this case the critical point is a large expression involving the parameters a, b, and c. 3.3 Max-Min Problems The typical max-min problems requires finding either the absolute maximum value or the absolute minimum value of a function, f (x), on an interval a ≤ x ≤ b. Our first step is plot the graph. We want the x-values to contain the interval [a, b] but not much larger. The y-values need to scaled in such a way that we get a clear picture of the largest and smallest values. If the function takes on negative values then the absolute minimum will be the largest negative value (the lowest point on the graph in any case). Using either the crosshair for precise approximations or just using the labels on the y-axis to obtain a rough answer are both good first steps to solving the problem. To obtain exact answers we need calculus and critical button to calculate point theory. In the Algebra Window we use the button to find the critical points from the f 0 (x). Next we use the 0 equation f (x) = 0. Once that value is found it can be substituted back into the expression for f (x) by pressing the Three problems arise: button. CHAPTER 3. BASIC ALGEBRA AND GRAPHICS 50 • First we are only interested in those points x which lie on our interval [a, b]. It probably will be necessary to obtain decimal approximations to our critical points x to see if they satisfy a ≤ x ≤ b. • The second problem is that the absolute maximum may not occur at the critical points at all. Instead, it occurs at either the left or right endpoint, i.e., x = a or x = b. This situation should be clear from the graph. • The third problem is that perhaps Derive can not solve the equation f 0 (x) = 0. As you look at the graph, you should be able to guess the critical point, at least approximately. Then you can ask Derive to approximate the critical point by using the Solve/Numerically1 menu. You will need to specify an interval on which Derive will search for a solution. But this should be obtained by again looking the graph and choosing a convenient interval containing the approximate critical point. Choosing too big of an interval can get you into trouble because Derive may end up finding a solution which is not the one you want. You would then need to refine your interval to exclude the undesired critical points. 3.4 Zooming and Asymptotes As another example of using both plotting and calculus operations, consider 3 2 −x+1 have a horizontal asympthe problem does the function g(x) = 3x +5x x3 −1 tote? In other words, we are interested in the behavior of the graph y = g(x) for very large values of x and we want to know whether the y-values tend to a limit. To solve this you begin by entering the function by choosing Author and typing (3x^3 + 5x^2 - x + 1)/(x^3 - 1). and see if it appears that g(x) has Now plot this. Zoom out by clicking a horizontal asymptote. A nice technique to do this is to leave the vertical scale alone and zoom out in the horizontal direction. There are several ways to do this; one way is use the zoom buttons on the menu bar. Can you guess 1 In DfW5 you choose Solve/Expression and then select the Numerically solution method option. 3.4. ZOOMING AND ASYMPTOTES 51 which button does this? Another way is change the scale, say x = 100 (click the button with the balance scale on it). Use the cross-hair to estimate the value of y that g(x) is tending to for large x. You should get y = 3 (see Figure 3.2). Figure 3.2: Zooming to find the horizontal asymptote Now return to the algebra window by clicking . We want to verify . When that limx→∞ g(x) = 3. Now choose Calculus/Limit or click asked for the “point,” type in inf or click ∞ symbol on the form. Simplify the answer; you should get 3. This means that as x gets large, g(x) approaches 3, i.e., the line y = 3 is a horizontal asymptote. We can check this calculation by the method of polynomial division which is accomplished in Derive using the Expand option. As we see at the bottom of Figure 3.2, 8 3x3 + 5x2 − x + 1 =3+ +··· 3 x −1 3(x − 1) where all the terms other than the 3 are small near x = ∞. This is because the denominator of each term has a larger power of x than the numerator. CHAPTER 3. BASIC ALGEBRA AND GRAPHICS 52 (The answer above is too wide for the window to display completely so you will need to scroll to see the 3. Use the horizontal scroll bar at the bottom of the window to do this.) 3.5 Laboratory Exercises 1. For each functions f (x) below (i) Plot the graph y = f (x) on the interval 0 ≤ x ≤ 2. (ii) By looking at the graph, estimate the x-value and y-value where the function obtains its absolute maximum value on the interval [0, 2]. (iii) In the Algebra Window, compute the derivative f 0 (x) and use the button to find the critical points on the interval [0, 2]. (iv) Study the graph to see if the endpoints need to be considered as possible extreme points. (v) Determine the absolute maximum value on [0, 2] by substituting into f (x) the x-value where the maximum is obtained. x 2 a. 1− c. 1 2 x −x 2 b. 1 2x − x2 2 d. sin x 2. Consider the function f (x) = x3 − x + 1. You do not need to declare a function, just enter and work the expression itself. a. Enter the expression for f (x) and plot it. Using the crosshair as described in Section 0.10, find an approximation for the both the x and y–coordinates of the local minimum of f (x). b. Using the same method find an approximation for the unique x satisfying the equation f (x) = 0, i.e., the value of x where the graph crosses the x–axis. or use Solve to find the root c. In the algebra window click exactly. Approximate this as a decimal and see how it compares with your answer in Part (b). 3.5. LABORATORY EXERCISES 53 d. In the algebra window find the derivative f 0 (x) and use it to find the exact coordinates of the local minimum you approximated in Part (a). (This will give you the critical value x; to get the y– coordinate substitute the value of the x–coordinate into f (x) by or by using the Simplify/Substitute/Variable menu; clicking see Section 0.8.) 3. Consider the class of all function of the form f (x) = x3 + bx2 + cx. a. Author the expression form x3 + bx2 + cx. Click the substitution button and enter some specific values for b, 2 c, then plot the result . Do this for several different choices for b and c and observe the critical points and inflection points of the different graphs. b. Using Derive’s calculus facilities in the algebra window, show that the function f (x) = x3 + bx2 + cx always has exactly one inflection point, regardless of the values of b, c. c. Again using Derive’s calculus facilities, show that f (x) can have either 0, 1 or 2 critical points. Determine for what values of b and c does f (x) have no critical point? d. Choose values b, c which demonstrate that f (x) may have either 0, 1 or 2 critical points and plot their graphs. x 7 4. Graph the function f (x) = ( 1+x 2 ) . At first there appears to be no part of the graph showing in the graphics window but this can not be since f (0) = 0. Try replotting the graph in another color by either just several times or using the Options/Plot Color menu. clicking Now the graph appears to the horizontal line y = 0 but this can not be since clearly f (x) = 0 only for x = 0. a. In the Algebra window, find the critical points of f (x) by using the and buttons. b. Determine the x and y coordinates of the local maximums and local minimums by using the button to substitute the values in part (a) into the function. 2 Derive can’t plot the function unless the values are provided. CHAPTER 3. BASIC ALGEBRA AND GRAPHICS 54 c. In the Graphics window, use the Zoom buttons or else the Set/Range menu in such a way that both the local maximum and local minimum points are visible. Furthermore, make the y-scale comparable to the y-coordinate of the local maximum. d. After you get a good looking graph, print out the result. 5. The volume of a tin can is V = πr2 h where r is the radius of the top (and the bottom) and h is the height. The surface area is A = 2πrh + 2πr 2 . (The first term is the area of the side and the second is the area of the top and bottom.) a. A manufacturing company wants to make cans with volume 42 in3 . To minimize their costs they want to minimize the area of the can. What values of r and h do this? (Hint: Author the formula for the area, 2πrh + 2πr 2 ; use the equation for the volume, 42 = πr 2 h, to solve for h in terms of r and substitute this into you expression for the area. Now find the value of r that minimizes the area using calculus techniques and use this value of r to find what h is.) b. You may have noticed that h = 2r for the can of minimum area you found in part a. Show that this relation always holds for the can of least surface area (not just for cans with volume 42). (Hint: Do this just as in part a except don’t replace V by 42 in the equation for the volume.) *6. Suppose we have the situation of the previous problem except that now the metal for the top and the bottom of the can costs 1.5 times as much as the metal for the side. What is h/r for the can of minimun cost? 7. Integrate each expression using the (See Section 0.9 for instructions.) Z x2 dx b. a. (x3 − 1)2 Z π/4 c. x sin(x2 ) dx d. 0 button (or Calculus/Integrate). Z π/2 (1 + cos x)2 dx 0 Z √ x 1 + x dx Chapter 4 Graphing Data and Curve Fitting 4.1 Introduction Consider the population of a certain country, P (t), as a function of time. We may not know exactly what P (t) is but instead just have a table of data, for example, the population at the beginning of each year for the last few years. We are interested in finding an appropriate curve for the data. We might try comparing the data against a linear function ax + b, a quadratic function ax2 + bx + c or say an exponential curve of the form P (t) = aert . Under a certain model of population growth P (t) will have this last form. Our problem is to determine the parameters a, b, . . . , from the data. Once we do this then we can use P (t) to estimate the population at times between the data and predict the population in the future. This kind of problem of fitting a function from a family of functions to numerical data arises frequently in many applied areas including statistics. In this lab we use the computer to help visualize data and fit the data to a function from a class of functions. We begin with the class of all polynomial functions. 4.2 Fitting Polynomials to Data Points Given a finite set of data points: (x1 , y1), . . . , (xn , yn ) 55 CHAPTER 4. CURVE FITTING 56 let’s consider the problem of finding a polynomial function f (x) which goes through these points. That is, we want f (x) to satisfy f (xi ) = yi for i = 1, . . . , n. If xi 6= xj , for i 6= j, then it turns out that we can always find a unique polynomial of degree at most n − 1 going through these points. This is quite obvious when n = 2 since there is a unique line passing through any 2 distinct points. If we are given 3 points, (x1 , y1), (x2 , y2), and (x3 , y3 ), and want to find a quadratic polynomial passing through these points, we let f (x) = ax2 +bx+c be an arbitrary quadratic. Since f (xi ) = yi for i = 1, 2, and 3, we obtain three (linear) equations ax21 + bx1 + c = y1 ax22 + bx2 + c = y2 ax23 + bx3 + c = y3 (1) in the unknowns a, b, and c. (Remember, we are given the points (xi , yi) so they are known and we want to find the unknowns a, b, and c.) We then solve this system of 3 equations for the 3 unknowns a, b, and c. For example, suppose we want to find a quadratic polynomial f (x) = ax2 + bx + c passing through (0, 0), (1, 2), and (2, 8). The way to do this with DfW is to first author f(x) := ax^2 + bx + c then choose Solve/System from the menu bar, set the number of equation to be 3, and then enter the three equations (you can either use the Tab-key after entering an equation or click the next equation box) f(0) = 0 f(1) = 2 f(2) = 8 Click on the Equation Variables box and select the variables to solve for as a, b, and c. Click OK and then simplify the resulting expression SOLVE( [F(0) = 0, F(1) = 2, F(2) = 8], [a, b, c]) (see Section 0.7 on page 6). Derive returns [a = 2 b = 0 c = 0] So in this case f (x) = 2x2 . We can double check this result by plotting the function 2x2 determined above along with the 3 × 2 data matrix 0 0 1 2 2 8 4.2. FITTING POLYNOMIALS TO DATA POINTS entered by using the 57 button. See Figure 4.1. Figure 4.1: Fitting a polynomial to data points For more complicated problems we would have to substitute in the values of a, b, c into the expression ax2 + bx + c using the button. The utility file ADD-UTIL has a function CURVEFIT(x, data) which does this automatically. Here the x is the variable and data is the matrix of point we want to fit the curve to. The more points we use the higher the degree of the polynomial needs to be. As we mentioned above, for 3 points with distinct x–coordinates there is a unique quadratic polynomial function passing through them. We can use Derive to demonstrate this by showing that the system of equations (1) can always be solved for a, b, and c, regardless of the values of (xi , yi). To do this we will just have Derive solve the system (1). However, there is a slight problem. In its normal input mode, called character input, Derive treats each letter as a separate variable. So if you author ab Derive will read this as a times b and the algebra window will show it as a · b. This is very convenient for calculus where we almost always CHAPTER 4. CURVE FITTING 58 use single characters for our variables. But to solve (1) we need the variables x1, x2, etc. When we enter x1, Derive will think of this as x times 1, which is not what we want. So we need to declare that x1, x2, etc., are variables. To declare x1 as a variable you can author x1 :=. You need to do this for all three x’s and y’s. Be sure to use the assignment characters := and not the equation character =. As a convenience for the exercises the ADD-HEAD file has provided declarations for x0, . . . , x4 and y0, . . . , y4. But if you need more variables or if you use a different letter other than x or y then you will need to declare them. button and selecting 3 Now enter the data matrix by clicking the rows and 2 columns. Then, enter x1 press Tab and enter y1. Continuing, enter all the remaining xi ’s and yi ’s. Click the OK button and the result should be x1 y1 x2 y2 x3 y3 Now we Author CURVEFIT(x,data) where data is the above matrix of points. Simplifying yields a complicated looking answer that is a little difficult to digest. However, if you examine the denominators of each of the expressions you will notice that they cannot be 0 since we are assuming that x1 , x2 , and x3 are distinct. This is the only thing that can go wrong with the formula in general so our assumption gives us a valid solution. See Figure 4.2 on the facing page. You might try increasing the number of points to see that the same principle applies. As an interesting variant on the above, suppose we want to find a, b, and c for a function f (x) = ax2 + bx + c when we know (2) f (x1 ) = y1 f (x2 ) = y2 f 0 (x3 ) = y3 (That’s the derivative!) In other words we specify that f (x) must pass through (x1 , y1) and (x2 , y2 ) and that its slope at x = x3 is y3 . We define f(x) as before and define g(x) 4.2. FITTING POLYNOMIALS TO DATA POINTS 59 Figure 4.2: The algebra behind fitting polynomials to data points as the derivative1 (3) g(x) := 2ax+b Now if we solve the system of equations f(x1) = y1 f(x2) = y2 g(x3) = y3 as before and then factor the answer, we see that the denominator of each of the 3 fractions is (x1 − x2 )(x1 + x2 − 2x3 ) (You can do this just as in Figure 4.2 except you need to define g(x) and use g(x3) = y3 in place of f(x3) = y3.) Of course we are assuming that 1 Note that you can’t simply define g(x):=DIF(f(x),x). We ran into this problem earlier on page 41 (see Section 0.12 on page 16 for a complete explanation). One solution to this problem is to use the utility file and define g(x):= SUBST( DIF(f(u),u), u, x). CHAPTER 4. CURVE FITTING 60 x1 6= x2 so the factor x1 − x2 will not be 0. The other factor is 0 when x3 = x1 + x2 2 This means we can always find f (x) except possibly if x3 = (x1 + x2 )/2. This is somewhat surprising since one expects to be able to solve for 3 unknowns satisfying 3 equations just as one can solve for 2 unknowns satisfying 2 equations. However, in both cases there are exceptional cases that need to be considered. In this case, the difficulty is related to the mean value theorem and is explored in Exercise 3. Related results for cubic functions are examined in Exercises 4 and 7. The solution to curve fitting problems involving the derivative can also be found using the CURVEFIT(x,data,ddata) function. As before x is the variable and data is a matrix of points satisfied by the function. The matrix ddata represents the points satisfied by the derivative. In the above example, we would author CURVEFIT(x,[[x1,y1],[x2,y2]],[[x3,y3]]) and simplify to get the answer. 4.3 Exponential Functions and Population Growth A good first model for population growth is (4) P (t) = aer(t−t0 ) Population models are studied more thoroughly in Chapter 11 using the theory of differential equations but for now we will just consider the exponential model. Here P (t) is the population at time t and a is the population at the starting time, t0 . Problem 7 uses this model. There are two parameters in (4), a and r. These parameters can be determined if we know the population at two different times, t1 and t2 , i.e., if we know P (t1 ) = y1 and P (t2 ) = y2 . This gives the equations aer(t1 −t0 ) = y1 aer(t2 −t0 ) = y2 4.4. APPROXIMATION USING SPLINE FUNCTIONS ∗ 61 but solving for a and r is a little more difficult since this is not a linear system of equations. Hence, we can not solve this system using the function. Instead, the way to do it is to use the first equation to solve for a and then substitute that value into the second equation and then solve the resulting equation for r. You can use SOLVE on any single equation but not systems. Another approach is to observe that the equations are linear in the quantities ln a and r because, if we let c = ln a, they are equivalent to: c + r(t1 − t0 ) = ln y1 c + r(t2 − t0 ) = ln y2 Of course, once we find c then a = ec , so you’re done. Problem 6 will require solving these equations. 4.4 Approximation Using Spline Functions∗ Suppose that, as before, we are given data points in the form of an n × 2 matrix declared as data. To take a simple example let’s assume that 0 0 1 1 data := 2 0 . 3 1 We want to find a smooth function f (x) whose graph passes through the data points. One solution to this problem is to use CURVEFIT(x, data) which gives us a degree n − 1 polynomial passing though the given data points. Unfortunately, for problems with a large number of data points this can take a long time to solve because it requires solving a large system of equations (n − 1 equations and n − 1 unknowns). One simple technique that doesn’t involve solving large systems of equations is to use a piecewise quadratic polygonal approximation to the graph. The idea is find a quadratic polynomial connecting each pair of consecutive data points but the catch is that in order for the graph to be smooth you need to make the derivatives match at each data point. Here’s how we do it: We start with an arbitrary slope, say m = 2, at the first data point, which is (0, 0) in our example, and use the second form of CURVEFIT to find a quadratic polynomial f1 (x) which satisfies the equations f1 (0) = 0, f1 (1) = 1 and f10 (0) = 2 . CHAPTER 4. CURVE FITTING 62 This solution is CURVEFIT(x,[data SUB 1, data SUB 2],[[0,2]]) where we note that each data point can be referred to as data SUB i or alternately, using the symbol bar as data↓i. Now to find our second quadratic f2 (x) connecting the second pair of data points and making sure that the graph of the two functions is smooth at x = 1 we simply solve for f2 (x) using the equation: f10 (1) = f20 (1). Continuing in this way we get quadratics f1 (x), f2 (x), . . . , fn−1 (x) corresponding to each of the n−1 intervals: [data1,1 , data2,1 ], [data2,1 , data3,1 ], . . . , [datan−1,1 , datan,1]. Note that we have used the double subscript notation to get the x-values in the first column of the data matrix. We combine these functions into a single function using the CHI function. Here CHI(a,x,b) is 0 unless a ≤ x ≤ b in which case it is 1. Thus, the combined function is (5) f (x) = 3 X fk (x) · CHI(datak,1, x, datak+1,1 ) k=1 In our example we can solve for the three quadratics and get f1 (x) = 2x − x2 , f2 (x) = 2x − x2 and f3 (x) = 3x2 − 14x + 16 Application The resulting function f (x) above is called a quadratic spline function and is important in approximation theory and computer graphics. One important example is in generating fonts for computer screens. Computers used to view a highly stylized letter like the capital S in some fancy font as a bitmap picture which required lots of memory to store and lots of time to draw on the screen. The modern approach is to view the letter as say 10-20 carefully chosen data points and then fill in the rest of the letter using spline function techniques. You can experiment with these techniques by using the utility function SPLINE(x,data,m1) which gives the quadratic spline passing the data points data and having derivative m1 at x = data1,1 . Using our example, we enter the above with m1 = 2 and Simplify. It’s instructive to plot the points data as a (non-connected) set of points and then plot the spline function to make sure that it passes through the points and that it indeed has a smooth graph. 4.5. LABORATORY EXERCISES 63 The definition behind the SPLINE function (see the file ADD-UTIL) is fairly straightforward. The function fk (x) depends on the previous function 0 (xk ), where the k th interval fk−1 (x) and more specifically on the quantity fk−1 is [xk , xk+1 ]. It turns out that it is more efficient to make a vector out of the n − 1 slopes m = [m1 , m2 , . . . ] using the formula (6) mk = 2 yk+1 − yk − mk−1 xk+1 − xk k = 2, . . . , n − 1 . which can be derived using DfW(see the file F-SPLINE.MTH). Using this formula one produces the vector of slopes using the ITERATES function. The formula looks a little complicated at first but should look straigtforward after some careful examination (see either the file ADD-UTIL or the SLOPE function in the file F-SPLINE.MTH). Using these quantities one then computes fk (x) using CURVEFIT(x, [data↓k, data↓(k+1)], [[data↓k↓1, m↓k]]) . See Figure 4.3 where we use this method of approximation to approximate the function y = sin x using n = 7, which is the smallest integer greater than 2π. Thus, based on the numbers sin 1, . . . , sin 7 plus the derivative at x = 0, i.e., m0 = 1, we get a good approximation to the sine function. 4.5 Laboratory Exercises Start off your lab by Loading the ADD-HEAD file (use File/Load/Math). Note that the syntax of the CURVEFIT function is displayed on the second line of the ADD-HEAD file. There are two possibilities: CURVEFIT(x, data) where data is a matrix of data points satisfied by the function or CURVEFIT(x, data, ddata) where now the derivative satisfies the matrix of data points ddata. 1. a. Use the CURVEFIT function to find the cubic polynomial passing through the points: (0, 0), (1, 1), (2, 0) and (3, 1). b. What degree polynomial is required to pass through 7 points? (Hint: Make up a 7 point data set and examine the solution.) CHAPTER 4. CURVE FITTING 64 Figure 4.3: Approximation using spline functions 2. Use the CURVEFIT function to find a, b, and c if ax2 + bx + c passes through a. (1, 1), (3, 4), and (4, 4). b. (1, 1), (3, 4), and (4, 1). c. Show that the functions determined in part a and b both have the same slope at x = 2. d. Do you think it is possible that f (1) = 1 f (3) = 4 f 0 (2) = 2 (see equation 2). Use the second form of the CURVEFIT function to find the solution. Note that the ddata is a 1×2 matrix in this case. What does Derive tell you? What if you change the derivative to f 0 (2) = 3/2? Can you explain what the answer means? 4.5. LABORATORY EXERCISES 65 For the following problems you will need to use the variables x1, x2, x3, x4, y0, y1, y2, y3, and y4. As long as you have loaded the ADD-HEAD file these variable will be declared. On the other hand, if you use a variable such as z0 then you will need to declare it by authoring z0:=. See the discussion on page 57. 3. Let (x1 , y1) and (x2 , y2 ) be two points in the plane with x1 6= x2 . Let 1 m = xy22 −y be the slope of the line through these points. The Mean −x1 Value Theorem says that if f (x) is a differentiable function which passes through these points then f 0 (x3 ) = m for some x3 between x1 and x2 . Show that if f (x) has the form ax2 + bx+ c then we can take x3 = (x1 + x2 )/2, i.e., show that f 0 ((x1 + x2 )/2) = m if f (x) has this form. Hint: Solve the system f (x1 ) = y1 , f (x2 ) = y2 for b and c and substitute those values back into ax2 + bx + c. Then show that the derivative of the resulting expression is m when x = (x1 + x2 )/2. Of course this means that all quadratic functions through (x1 , y1 ) and (x2 , y2 ) have the same slope at (x1 + x2 )/2. 4. Use the CURVEFIT function to find the quadratic function f (x) = ax2 + bx + c that satisfies f (x0 ) = y0 f (x1 ) = y1 f (x2 ) = y2 Integrate the resulting function over the interval [x0, x2]. Observe that your answer is a pretty big expression that requires scrolling to view. Now substitute in this expression x1 = (x0+x2)/2 using the button and simplify. Note that x1 is the midpoint of the interval [x0, x2]. The answer should be a very simple formula in terms of x0 , x2 , y0 , y1 and y2 . In the next chapter this calculation will be the basis for the Simpson Method of numerical integration. *5. Suppose we want to find a cubic function f (x) = ax3 + bx2 + cx + d CHAPTER 4. CURVE FITTING 66 such that f (x1 ) = y1 f (x2 ) = y2 f (x3 ) = y3 f 00 (x4 ) = y4 Show that this is always possible if x1 , x2 , and x3 are all distinct and x4 6= (x1 + x2 + x3 )/3. The algebra in this problem gets fairly messy. 6. Let (x1 , y1 ) and (x2 , y2 ) be two points in the plane with y1 > 0, y2 > 0, and x1 6= x2 . Let f (x) = aerx be an exponential function. Show that it always possible to find a and r so that f (x) passes through these points. Hint: you need to solve the equations aerx1 = y1 aerx2 = y2 To do this first solve for a in one of these and substitute the answer into the other and then solve for r. Make sure that your formulas for a and r only involve the data points. 7. Table 4.1 on page 68 shows the population of the US for every decade from 1800–1900. Consider two models for the data: an exponential model P (t) = aert and a linear model L(t) = bt + c. a. Use the data for 1800 and 1810 to determine 2 linear equations in the 2 unknowns b and c. Use to find b and c. b. Do the same thing for the a and r but this time you will need to apply the previous exercise to solve for a and r. c. Show that your model in Part (b) is the same as 5.3er(t−1800) where r is the value you obtained in Part (b). Use properties of the exponential function to explain why this is true. d. What does each model predict for 1830? e. How do the models compare during the first 50 years? 100 years? Do this by graphing both functions and the population data. Adjust the scale to get a good picture. Note: The data in Table 4.1 can be copied from the file F-population. 4.5. LABORATORY EXERCISES 67 f. Make up your own values of a and r in the exponential model and see if you can get a better representation of the data for the last 20 to 30 years. Do this by plotting the model and comparing with the data. g. The population for 1990 is 248.7 million. Use a value of a and r from the previous part to estimate the population in the year 2050. *8. Suppose that data is an n × 2 matrix of data points x1 y1 x2 y2 data := .. . . xn yn where x1 , y1 , . . . have numerical values and x1 < x2 < . . . . We know that plotting this vector in connected mode gives a piece-wise linear graph. You can test this using a sample value for data. Write a function f(x) in DfW which will have the same graph, i.e., between any two consecutive x-values, xk ≤ x ≤ xk+1 , f (x) linearly interpolates the data points. (Hint: Look at equation 5 on page 62 for doing spline function interpolation and use the CHI function as is done there. You will need to use subscript notation to refer to the x, y values. For example, data↓1↓1 is x1 and data↓3↓2 is y3 .) *9. Let (x1 , y1), (x2 , y2), and (x3 , y3 ) be three points in the plane with x1 6= x2 , x1 6= x3 , and x2 6= x3 . Show that all cubic functions, f (x) = ax3 + bx2 + cx + d which go through all three of these points have the same second derivative at x1 +x32 +x3 . (Hint: Just solve the 3 equations in the 3 unknowns b, c, and d in terms of the 4th unknown a. Differentiate twice and substitute in the above value of x. Check that the answer does not depend on a.) CHAPTER 4. CURVE FITTING 68 Table 4.1: Population of the US, 1800–1990 Year Population (millions) 1800 5.3 1810 7.2 1820 9.6 1830 12.8 1840 17.0 1850 23.0 1860 31.4 1870 38.5 1880 50.0 1890 62.9 1900 76.2 1910 92.2 1920 106.0 1930 123.2 1940 132.2 1950 161.3 1960 179.3 1970 203.3 1980 226.5 1990 248.7 Chapter 5 Finding Roots Using Computers 5.1 Introduction This lab explains two techniques for numerically solving equations, Newton’s famous method and the bisection method. If we have any equation we want to solve for x, we can subtract one side from the other to get an equation of the form f (x) = 0. Of course, in case f (x) is a polynomial then solving this equation means finding the roots of f (x).Thus, for quadratic polynomials we would ordinarily use the quadratic formula. However, we will be considering very general functions which typically involve trigonometric functions, logarithms and exponentials and hence algebraic methods are usually hopeless. Newton’s method is called a dynamic process and is related to interesting topics such as chaos and fractals. We will explore these concepts later in this chapter. 5.2 Newton’s Method Newton’s method for finding a solution r to the equation f (x) = 0 is to start with a guess x0 (presumably not too far from r) and form the tangent line to f (x) through (x0 , f (x0 )). Then find the place, call it x1 , that this tangent line crosses the x–axis. Now we repeat this process with x1 in place of x0 . (See Figure 5.1 on the next page.) In this way we obtain a sequence of numbers x0 , x1 , x2 , . . . which, under reasonable conditions, will converge 69 70 CHAPTER 5. FINDING ROOTS USING COMPUTERS to r. Since y − y0 = m(x − x0 ) is the equation of the line through (x0 , y0 ) with slope m, the equation for the tangent line of f (x) through (x0 , f (x0 )) is y − f (x0 ) = f 0 (x0 )(x − x0 ). Solving for x when y = 0 gives x = x0 − f (x0 )/f 0(x0 ). Thus we get the (n + 1)st approximation from the nth by the formula: (1) xn+1 = xn − f (xn ) f 0 (xn ) Figure 5.1: Newton’s method for finding roots In the graphics window of Figure 5.1 the first several approximations in Newton’s method are shown for √ the equation x2 + x − 1 = 0 which has the unique positive solution x = 5/2 − 1/2 ≈ 0.618. The initial guess is x0 = 5. From the point (5, 0) we go up to the curve at the point (5, f (5)) and then follow the tangent line until it intersects the x–axis at the point 5.2. NEWTON’S METHOD 71 (x1 , 0) ≈ (2.36363, 0). The process is now repeated, starting with the guess x1 . It is convenient to view the computations as an iteration process: (2) NG(x) = x − f (x) f 0 (x) which changes a guess x into a (hopefully) better guess NG(x). (Note that xn+1 = NG(xn ).) You can think of NG as standing for ‘Newton guess’ or for ‘next guess’. To make a Derive function to do this for our function f (x) = x2 + x − 1 we define (3) NG(x) := x-(x^2+x-1)/(2x+1) Now starting with x0 and successively applying this function to the previous result produces a sequence of approximations: x0 x1 = NG(x0 ) x2 = NG(x1 ) = NG(NG(x0 )) x3 = NG(x2 ) = NG(NG(x1 )) = NG(NG(NG(x0 ))) .. . which we hope get closer and closer to the exact answer. In the limit we want this sequence of approximations to converge to the root. We can compute several approximates by first Authoring NG(5), and then approximating. Now we can author NG, press the right mouse button and then click (Insert expression) or press F4. This will bring down the highlighted expression in parentheses giving NG(2.36363) which we approximate (just press Simplify instead of OK) again and then repeat this process. A somewhat fancier method is to use the Derive’s ITERATES function. ITERATES(u,x,a,n) simplifies to an (n + 1)-vector whose first entry is a and each subsequent entry is obtained by substituting the previous entry for x in u. Thus, ITERATES(x^2,x,2, 4) returns the vector [2, 4, 16, 256, 65536]. (The function ITERATE is similar, but just gives the last value, so ITERATE(x^2,x,2,4) gives 65536.) We can get the first 4 approximates by authoring ITERATES(NG(x), x, 5, 4) and approximating the result. 72 CHAPTER 5. FINDING ROOTS USING COMPUTERS Loading the utility file ADD-HEAD adds two functions to the system that make computing the Newton iterations easier. The function NEWT(u,x,a) computes the Newton guess of the expression u, in the variable x, starting with an initial guess at x0 = a. In our previous example of f (x) = x2 + x − 1 with starting point x0 = 5 we would enter NEWT(x^2+x-1,x,5). To get a vector containing the starting point and the first 4 Newton iterates you author and simplify NEWT(x^2+x-1,x,5,4). The general syntax is NEWT(u,x,a,k). Looking at the algebra window in Figure 5.1 we see the above function along with the first 4 iterates starting at x0 = 5. The graphic demonstration shows the Newton method in action by plotting a part of the tangent line until it crosses the x-axis. The picture clearly shows how well the Newton method works since one has to zoom-in several times near the actual root in order to see the last two iterations. The utility function DRAW NEWT(u,x,a,k) simplifies to a matrix which plots the figure shown in Figure 5.1. Alternately, that file contains the necessary definition for doing the graphics directly. The basic idea is to make a vector out of several triples of points which have the form (x, 0), the initial guess on the x–axis, (x, f (x)), the corresponding point on the curve, and (NG(x), 0), the place where the tangent to the curve at (x, f (x)) intersects the x–axis. When we graph these points we want the lines connecting them to be drawn. If this is not the case then adjust the Options/Points menu. You might note that a little trick is used in the above of DRAW N in the file F-NEWT. The special form of the VECTOR(u,x,v) function sets x equal to each value in the vector v = [v1 , . . . , vn ] and makes the new vector [u(v1 ), . . . , u(vn )]. √ Example. Suppose we want a numerical approximation of 2. We think of it as a solution to the equation x2 − 2 = 0. Then formula (2) gives the very simple expression: NG(x) = x − x2 − 2 x2 + 2 x 1 f (x) = x − = = + 0 f (x) 2x 2x 2 x We get several approximates by clicking (4) after authoring either NEWT(x^2-2,x,2,5) or equivalently as in the file F-NEWT.MTH (5) ITERATES(x/2+1/x,x,2,5) 5.3. WHEN DO THESE METHODS WORK 73 with precision digits set to 10 decimal places. We get (6) [2, 1.5, 1.41666666, 1.414215686, 1.414213562, 1.414213562] which is accurate to 10 decimal places. In fact, Figure 5.2 shows a remarkable property about Newton approximation: the number of decimal place accuracy approximately doubles with each iteration! Figure 5.2: Each iteration gives twice as many digits 5.3 When Do These Methods Work In our previous examples, we have seen that by starting at a point x0 which is close to the solution r, of the equation f (x) = 0, and computing several iterates of the NG(x) function, i.e. x0 , x1 = NG(x0 ), x2 = NG(x1 ), x3 = NG(x2 ), . . . results in a sequence of approximates which get closer and closer to r. By comparing decimals we see that the number of decimals places in common 74 CHAPTER 5. FINDING ROOTS USING COMPUTERS increases with each new xn . More precisely, the differences |r − xn | can be bounded by 10−mn where the integers mn , which are approximately the number √ decimal places in common, increases with out bound. For example, in the 2 problem above the number of decimals was approximately mn ≈ 2n , i.e., 2, 4, 8, 16, etc. In order for Newton’s method to work we need at least that f (x) is differentiable and f 0 (x) 6= 0, since the derivative appears in the denominator of the formula (2). We would like to find a criteria that guarantees that the sequence xn gets closer and closer to r and that the number of decimal places in common, mn , increases without bound. As an example, suppose that on some interval I = [r − a, r + a], with r as a midpoint, we know that | NG0 (x)| ≤ λ < 1 for all x in I. Take x0 in I as our starting point and observe that NG(r) = r. By applying the Mean Value Theorem we get that |x1 − r| = | NG(x0 ) − r| = | NG(x0 ) − NG(r)| = | NG0 (c)(x0 − r)| where c is some point between x0 and r. Hence, c is in the interval I and therefore | NG0 (c)| ≤ λ by our assumption. Thus, the above yields that |x1 − r| = λ|x0 − r| < |x0 − r| and so x1 is indeed closer to r than x0 . In addition, this means that x1 is in the interval I so that we can repeat this argument with x1 as our starting point. Then, the above inequality becomes |x1 − r| = | NG(x0 ) − r| ≤ λ|x0 − r| |x2 − r| = | NG(x1 ) − r| ≤ λ|x1 − r| ≤ λ2 |x0 − r| .. . |xn − r| = | NG(xn−1 ) − r| ≤ λn |x0 − r| which shows that the xn ’s are getting closer and closer to r. To estimate the number of decimals in common take the special case that λ = 0.1 = 10−1. Then, |xn − r| ≤ 10−n |x0 − r|, i.e., mn = n, and we see that we gain one decimal place with each computation. 5.3. WHEN DO THESE METHODS WORK 75 In general, the same sort of thing will occur with any 0 < λ < 1. If λ is greater than 0.1 then the number of decimals mn will increase at a slower rate but nevertheless it can be shown to increase without bound. For example, in Derive if we approximate VECTOR(1/2^n,n,1,16,3) then we get [0.5, 0.0625, 0.0078125, 0.000976562, 0.000122070, 1.5258710−5] which suggests that mn ≈ n/3. In fact, if your numerically solve the equation 2−n = 10−m for m using Derive you will get m = 0.301029n. If we assume that f 00 (x) exists and that f 0 (x) 6= 0 on I we can compute NG0 (x) as follows: f (x) d 0 x− 0 NG (x) = dx f (x) 0 2 f (x)f 00 (x) f (x) − f (x)f 00 (x) = . =1− f 0 (x)2 f 0 (x)2 Since f (r) = 0 we see that NG(r) = 0! Thus, not only is | NG0 (x)| less than one near r but it can be made as small as you like. This follows from the continuity of the function NG(x) which in turn follows from the continuity of f 0 (x) and the fact that it is never zero near r. The implication of this fact is a much faster rate of convergence, i.e., the mn increases much faster than the above computations suggest. Theorem 1. Suppose f (r) = 0 and that f 00 (x) is continuous in some open interval I which has r as its midpoint. If f 0 (r) 6= 0 then the iterates of NG(x) = x − f (x) f 0 (x) converge to r provided the starting point x0 is sufficiently close to r. More precisely, the interval I can be chosen small enough so that there is a constant M satisfying: (7) | NG(x) − r| < M|x − r|2 whenever x is in the interval I. Before we prove this fact, let’s see what it really means. Suppose for example that M = 50 and we pick x in I that is within 2 decimals places of 76 CHAPTER 5. FINDING ROOTS USING COMPUTERS the exact value r, i.e., |x − r| < .01. The above relationship then says that our Newton guess starting at x, NG(x), satisfies: | NG(x) − r| < M|x − r|2 < 50(.01)2 = .005 and since .005 is much smaller than .01 we have a big improvement over our initial guess of x. Moreover, since our new guess is closer to r than our initial guess we see that it is also in the interval I and hence we can repeat the same calculation using NG(x) in place of x. We could make further calculations, as above, to see how rapidly the sequence of approximates converges to the exact root r or we could have Derive do it for us. If we author the expression ITERATES(50 t^2, t, .01, 5) and simplify we get [0.01, 0.005, 0.00125, 7.812510−5, 3.0517510−7, 4.6566110−12] which clearly shows the very rapid rate of convergence to the exact answer r. Proof. By making the interval I a little smaller if necessary we may assume that both f 0 , f 00 are continuous and bounded on I. Let us assume that |f 0 (x)| ≤ A and |f 00 (x)| ≤ B for x in I. Similarly, since f 0 (r) 6= 0 we may assume, again by making I a little smaller if necessary, that |f 0 (x)| ≥ C > 0 or equivalently 1 |f 0(x)| ≤ 1 C for x in I. Note that in particular this means that NG(x) is defined for x in I. Put M = AB/C 2 . We have observed that NG(r) = r and NG0 (r) = 0. Hence, by using the Mean Value Theorem twice and our formula for NG0 (x) we get NG(x) − r = NG(x) − NG(r) = NG0 (c1 )(x − r) f (c1 )f 00 (c1 ) f 00 (c1 ) = (x − r) = (f (c1 ) − f (r))(x − r) f 0 (c1 )2 f 0 (c1 )2 f 00 (c1 ) 0 = 0 f (c2 )(c1 − r)(x − r) f (c1 )2 5.3. WHEN DO THESE METHODS WORK 77 where c1 , c2 are between x and r and hence in the interval I. Using the bounds for f 0 , f 00 and 1/f 0 above shows that (7) holds because | NG(x) − r| ≤ A B|c1 − r||x − r| ≤ M|x − r|2 C2 which is what we needed to prove. For another illustration of how fast the Newton method converges when NG0 (r) = 0 let us assume that the constant M in (7) is one or less. If we make an initial guess x0 which is in I and approximates r to n decimal places, i.e., |x0 − r| < 10−n then the first approximate x1 = NG(x0 ) satifies |x1 − r| = | NG(x0 ) − r| ≤ M|x0 − r|2 < 10−2n which means that x1 approximates r to twice as many decimal places as x0 . This doubling property was observed numerically in an earlier example. The case when M > 1 is similar and is discussed in an exercise. In dynamic systems like this, a point r with NG0 (r) = 0 is called a super attractor . Once x gets close to a super attractor r, repeated applications of NG will move it towards r very quickly. The next theorem investigates a situation where 0 < NG0 (r) < 1. In this case N k (x) still tends to r but not nearly as fast. In this case r is no longer a super attractor but is simply an attractor . Theorem 2. Suppose that f (r) = 0 and that f (x) = (x − r)m g(x) where g(x) is differentiable, m is a positive integer and g(r) 6= 0. Then, NG(x) is defined for all x 6= r which are sufficiently close to r and the iterates converge to r. Proof. Since f 0 (r) = 0 for m > 1 (check!) it is not clear that we can even define NG(x) for x near r. But (8) f 0 (x) = m(x − r)m−1 g(x) + (x − r)m g 0 (x) = (x − r)m−1 [mg(x) + (x − r)g 0(x)] ≈ (x − r)m−1 mg(r) and since g(r) 6= 0 it is easy to see that the bracketed expression above can not be zero for all x near to r and hence the same is true of f 0 (x) provided x 6= r. CHAPTER 5. FINDING ROOTS USING COMPUTERS 78 Now using (8) to simplify NG(x) (do this using Derive) we get (m − 1)g(x) + (x − r)g 0(x) NG(x) − r = . x−r mg(x) + (x − r)g 0 (x) When x = r, the right hand side above simplifies to (m − 1)/m which is less the one. This means that we can find an interval I, with midpoint r, and a number 0 < λ < 1 such that | NG(x) − r| ≤ λ|x − r| for all x in the interval I. As we argued earlier in this section, this means that starting at x0 in I we get the sequence of approximates xn satisfying |xn − r| ≤ λn |x0 − r| which shows that the xn ’s converge to r. 5.4 Complex Numbers, Fractals and Chaos∗ 2 Which root √ √ does Newton find? Of course f (x) = x − 2 has two roots, 2 and − 2. If√our initial guess is any positive number, Newton’s method √ will converge to 2 and, if it is any negative number, to − 2. If the initial guess is 0 the method fails since NG(0) is not defined. The situation for this f (x) is pretty simple but that is not always the case. To get a clearer picture of what can happen we need to discuss the complex numbers. Complex Numbers Recall that a complex number has the form a + b i, where a and b are real numbers and i is a square root of −1, i.e., i2 = −1. In Derive we input i by using the symbol bar or by typing #i. This is displayed with î. The basic operations with complex numbers are the same as real numbers; namely, addition, subtraction, multiplication, division and distance. • Addition and Subtraction. You do the real and imaginary parts separately: (a + b i) + (c + d i) = (a + c) + (b + d) i (a + b i) − (c + d i) = (a − c) + (b − d) i ∗ 5.4. COMPLEX NUMBERS, FRACTALS AND CHAOS 79 • Multiplication. Do this as usual except replace i2 with -1: (a + b i)(c + d i) = ac + ad i + bd i + bd i2 = ac + ad i + bd i − bd = (ac − db) + (ad + bc) i • Division: You can divide any complex number a + b i by any non-zero complex number c + d i. This means that c2 + d2 > 0, i.e., both c and d can not both be zero. We define the complex conjugate w̄ = c − d i. (In Derive this is computed using CONJ(w).) Then we observe that w w̄ = (c + d i)(c − d i) = c2 − (d i)2 = c2 + d2 and so the formula for the reciprocal is w̄ c−di c d 1 = = 2 = 2 − 2 i. 2 2 w w w̄ c +d c +d c + d2 The formula for the quotient is then given by (a + b i)(c − d i) a + bi = c+di (c + d i)(c − d i) (ac + bd) + (bc − ad) i = c2 + d 2 ac + bd bc − ad = 2 + 2 i c + d2 c + d2 • Distance: The modulus or absolute √ value of a complex number z, where z = a + b i, is defined as |z| = a2 + b2 . The distance between two complex numbers z, w is defined as |z − w|, i.e., the modulus of their difference. When we plot complex numbers as points in the plane (see below) then this distance formula is the same as the usual distance formula between points in the plane. In Derive the modulus is computed using ABS which is the absolute value function. • Real and Imaginary Parts: In the representation of a complex number as z = a + b i; where a,b are real numbers, we say that a is the real part of z and that b is the imaginary part of z. Using the complex conjugate defined above we have the following formulas: z − z̄ z + z̄ and b = =z = . 2 2i In Derive the corresponding these are computed as RE(z) and IM(z). a =0. We call 2 an attractive √ fixed point 2. If we start and the right half plane is called the basin of attraction for √ √ with x0 = a + b i where a < 0 it will converge to − 2, so − 2 is also an attractor with the left half plane as its basin of attraction. What happens if we start with a point on the imaginary axis (the y–axis x0 = b i? Simplify and plot the expression DRAW COMPLEX(NEWT(x^2-2,x,#i,25)) Notice that all the values are purely imaginary (they only have an i component) and that they seem to bounce around randomly. Moreover, if you author DRAW COMPLEX(NEWT(x^2-2,x,1.01#i,25)) you’ll notice that the corresponding entries of the answers are approximately the same for the first few terms but very quickly seem to have no relation to 82 CHAPTER 5. FINDING ROOTS USING COMPUTERS Figure 5.3: Newton’s method with complex starting point each other. Here’s a nice way to do this: Define the first set of points to be data1 and the second set to be data2. Author the vector [data1,data2] and simplify. Then scroll though the matrix to compare entries. In other words, even though the two starting points above; namely i and 1.01i are quite close together their long-term behavior seem completely different. The above phenomenon is what is known as chaos. We can illustrate this last property graphically by looking at the √ equation 2 2 x √+ 2 = 0 rather than x − 2 = 0. The former equation has roots 2 i and − 2 i. Just as before if we start with any point a+ib in the upper half of the complex plane (b > 0), the Newton iterates of the function x2 + 2 converge √ √ to 2 i and any point in the lower half plane (b < 0) converges to − 2 i. Test this by plotting DRAW COMPLEX(NEWT(x^2+2,x,1+#i,5)) But we get chaos on the real axis. To see this chaos plot the function x2 + 2 and the output to DRAW NEWT(x^2+2,x,2,4) in connected mode, see Figure 5.4 on the next page. ∗ 5.4. COMPLEX NUMBERS, FRACTALS AND CHAOS 83 Figure 5.4: Chaos x3 − 1. This has three roots: x = 1, x = −1/2 + √ Now consider f (x) = √ i 3/2, and x = −1/2 − i 3/2. This is easy to do in Derive just Solve the equation x3 − 1 = 0. Each of these is an attractor with a basin of attraction. However the shapes of these basins of attraction are really quite interesting and bizarre. Figure 5.5 on the following page shows the basin of attraction for the root x = 1 in white. The basins of attraction of both of the other roots are black. In Figure 5.5 the center is the origin in the complex plane and the right hand edge has x = 2. So the point (1, 0) (i.e., 1+0 i) is between the center and the right hand edge. A color version of this figure that indicates the number of iterates needed to converge can be viewed on our World Wide Web home page at http://www.math.hawaii.edu/lab/newton.html This web page contains an interactive Java applet that shows the iterations in Newton’s method. You click a complex starting point and the applet shows the first five iterations. Try it! 84 CHAPTER 5. FINDING ROOTS USING COMPUTERS Figure 5.5: Basins of attraction of x3 − 1 in the complex plane Constructing the Julia set The set of points where Newton’s method fails, that is, the set of points x0 where the sequence (9) x0 , NG(x0 ), NG(NG(x0 )), . . . fails to converge, is called the Julia set for NG(x). In the example f (x) = x3 −1 these are the points on the edge or boundary of the basin of attraction. As the picture in Figure 5.5 shows this set can be very complicated, it looks a little like a necklace with infinitely many smaller and smaller loops coming out in many different directions. There are two basic methods for constructing this set. Since NG(x0 ) is not even defined when f 0 (x0 ) = 0 this is a good place to start. If x is a solution of NG(x) = x0 then the third term of the sequence (9) is not defined and so x will be in the Julia set. In the case when f (x) = x3 − 1 the equation above has ∗ 5.4. COMPLEX NUMBERS, FRACTALS AND CHAOS 85 three solutions. For each of these there are three more obtained by solving a similar equation or in other words finding the points where NG(NG(x)) = x0 . Continuing in this way we get a close approximation to the Julia set. The actual set is obtained by taking limits of these points. This method is called the backward method and is done in the file F-JULIA-BACKWARD for the polynomial x3 − 3x which has√critical points at ±1. This function has three real roots at x = 0 and x = ± 3 and the Julia set somehow has to separate the three basins of attraction corresponding to these roots. See Figure 5.6 for a picture of it’s Julia “necklace”. Figure 5.6: Bad Newton starting points for x3 − 3x = 0 in the complex plane The trouble with the backward method is that it uses the cubic formula for solving 3rd order equations and this formula is pretty complicated. Even worst is the fact that there is no analogous formula for degrees 5 or greater. To get around this problem there is the “forward method” which involves simply looking at the sequence: NG(x0 ), NG(NG(x0 )), NG(NG(NG(x0 ))), . . . 86 CHAPTER 5. FINDING ROOTS USING COMPUTERS and checking whether it gets closer and closer to root or else just wanders around forever. Since you have to do this for each point or pixel in the graph this can be a very lengthy computation. A number of shortcuts and tricks are typically employed and you can study the file F-JULIA-FORWARD to see how we did it. Or you can just check out the pictures; see Figure 5.7. Figure 5.7: Basins of attraction for x3 − 3x = 0 5.5 Bisection Method∗ We now consider a very simple technique that is applicable to any continuous function f (x). If f (x) is continuous and f (a) < 0 and f (b) > 0, i.e., it is below the x–axis at a and above the x–axis at b, then the Intermediate Value Theorem tells us that f (x) must have a zero between a and b. Assume a < b. , the midpoint of a and b The bisection method evaluates f (x) at x = a+b 2 ) > 0 then there (which is why it is called the bisection method). If f ( a+b 2 must be a root in the interval [a, (a + b)/2]; otherwise there must be a root in the interval [(a + b)/2, b]. In the former case we take the interval [a, (a + b)/2] 5.5. BISECTION METHOD ∗ 87 and apply the bisection method to it; otherwise we use [(a + b)/2, b]. At each stage the root lies in an interval that is only half the size of the previous stage. So we can eventually find the root to any number of decimal places. We can automate this process by authoring two functions: F(x) := BIS2(a,b) := IF(f(a)f((a+b)/2)<0, [a, (a+b)/2], [(a+b)/2, b]) BIS(v) := BIS2(v SUB 1, v SUB 2). The main function is BIS(v) and BIS2(a,b) is a helper function. The argument v to BIS is a vector with two entries, e.g., [a, b]. The Derive function SUB, which we discussed in the previous section, returns the parts of a vector so that [a,b] SUB 1 = a and [a,b] SUB 2 = b. So BIS starts with a vector like [a,b] and calls BIS2(a,b). This then uses the values f (a) and f ((a + b)/2) to decide if there is a root in [a, (a + b)/2] or in [(a + b)/2, b]. In the discussion above we assumed that f (x) < 0 and that f (b) > 0. The way we have defined BIS it will work also in the case f (x) > 0 and f (b) < 0. To do this we test if the product f (a)f ((a + b)/2) is negative. If it is, then one of f (a) and f ((a + b)/2) is negative and the other is positive. In this , f ( a+b )) lie on opposite sides of the x–axis case the points (a, f (a)) and ( a+b 2 2 and so there must be a root in the interval [a, (a + b)/2]. In the other case, f (a)f ((a + b)/2) is positive and so they have the same sign. In this case f ((a + b)/2) and f (b) must have the opposite signs (why?) and so there is a root in [(a + b)/2, b]. Let us try the equation ln x = 1 which has the (unique) solution x = e = 2.718 . . . . Of course we are finding the root of ln x − 1 so we author f(x) := ln(x) - 1 and apply BIS. Graphing f (x) shows that there is a root between 2 and 3 so we author BIS([2,3]). This returns [2.5, 3], indicating that 2.5 < e < 3. Now we want to apply BIS to the answer [2.5, 3]. You can do this several times by choosing author, typing BIS, and then inserting the highlighted vector. Once again we have an iteration process and we can use the ITERATES function that does this for you. Using this technique, we author ITERATES(BIS(v),v,[2,3],10) and then approximate it to see how well this approximates e, see Figure 5.8 on the following page. 88 CHAPTER 5. FINDING ROOTS USING COMPUTERS Figure 5.8: Bisection method for finding roots An easier way to see the bisection method in action is to use the function BISECT(u,x,v,k) in the utility file ADD-UTIL. To get the above results we would simply enter BISECT(ln x-1,x,[2,3],10) and the press the apbutton. It is interesting to compare the results of the proximation bisection method with the Newton method of the previous section. The bisection method is fairly fast at getting a good approximation but not nearly as fast as the Newton method. The bisection method will work for any f that is continuous on the interval [a, b] and f (a) and f (b) have opposite signs. It is easy to see that after n iterates the error is at most (b − a)/2n . (In fact this is the width of the resulting interval. If we choose the midpoint as our estimate, the error will be at most (b − a)/2n+1 .) 5.6. LABORATORY EXERCISES 5.6 89 Laboratory Exercises Start off your lab by Loading the ADD-HEAD file (use File/Load/Math). Note that the syntax of the NEWT function is displayed on the second line of the ADD-HEAD file. There are two possibilities: NEWT(u,x,a) where a is the starting point in Newton’s method applied to the expression u in the variable x. Alternately, the function NEWT(u,x,a,k) gives a vector containing the intial guess a followed by the first k approximates. The function DRAW NEWT(u,x,a,k) produces the graphical demonstration of the Newton method. √ 2 1. The equation x2 = 2 has √ solutions x = ± 2. Use the function x − 2 and NEWT to estimate 2. a. Give the 5th iterate starting at x = 10 b. Plot the graph of x2 − 2 and the output to DRAW NEWT(x^2-2, x, 10, 5). c. What happens when your start at x = −10? d. What’s wrong with the starting point x = 0? Explain this both numerically and graphically. 2. In a manner similar to Problem 1, use NEWT to estimate √ 3 7. a. Give the 5th iterate starting at x = 2. b. By comparing with the approximate given by Derive how many decimal places (roughly) does the Newton approximations share with the actual answer. Note that you may need to increase the number of digits you are working with (see Section 0.6). 3. Plot the graphs of x2 and sin x. a. Determine graphically where the two graphs intersect. Give a rough estimate of the accuracy of this method? (Hint: If you use the right arrow key to change the position of the crosshair, how much does its x–coordinate change?) b. Next use Newton’s method to find all solutions to x2 − sin x = 0. Give the 5th iterate starting at x = 2. CHAPTER 5. FINDING ROOTS USING COMPUTERS 90 c. Solve this equation numerically by using Solve/Numerically2 menu. Compare the solution you get using DfW’s SOLVE function with your approximation above using Newton’s method. 4. Let f (x) = x3 − 5x. Graph f (x). a. Use Solve to find the all roots of x3 − 5x = 0. b. Plot the output to DRAW NEWT(x^3-5x,x,1,5) and analyze the first 5 iterates in the Newton approximation method starting at x = 1. Explain in words what goes wrong when you start at x = 1. c. Do the same but with x0 = 1.01 and with x0 = 0.99. 5. Again let f (x) = x3 − 5x. a. Find the formula for NG(x) for this f . b. Find a point x0 where is NG(x) undefined. (There are two such points; find either one.) Give the exact answer and then approximate it. c. Use Derive’s Solve/Numerical2 to solve NG(x) = x0 . Call the answer x1 . *d. Do this once more, that is, Solve/Numerical2 NG(x) = x1 . Call the answer x2 . If you continued this forever what do you think the sequence x0 , x1 , x2 , x3 . . . would look like? limn→∞ |xn | is? What are their signs? What do you think e. Choose any numbers a and b which satisfy |x2 | < a < |x1 | < b < |x0 | To which root does Newton’s method converge if we start with a? with b? 2 In DfW5 you choose Solve/Expression and then select the Numerically solution method option. 5.6. LABORATORY EXERCISES 91 6. Let f (x) = x2 + 1. Graph f (x). Find 10 iterates of Newton’s method starting with x0 = 0.5 and x0 = 0.501. Explain why you think the successive approximations don’t seem to be converging to anything. 7. Use the definitions for adding and multiplying complex numbers given in Section 5.4 on page 78 to answer these problems using pencil and paper and then check your computations using Derive. Recall that the definition of the complex conjugate is a + b i = a − b i and√that in Derive you use the function CONJ. The modulus is |a + b i| = a2 + b2 and in Derive you use the function ABS, i.e. absolute value. a. (1 + 2i) + (3 − i) b. (1 + 2i) + (3 − i) c. (1 + 2i)(3 − i) d. (1 + 2i)(3 − i) e. |(1 + 2i)(3 − i)| f. |(1 + 2i)(3 − i)| g. 1 + 2i 3−i h. 2+i i. = j. <(2 + i 1 + 2i 3−i 1 + 2i 3−i 1 + 2i ) 3−i 8. Let z = a + b i and w = c + d i, where a, b, c and d are real numbers. Recall that the definition √ of the complex conjugate is z̄ = a−b i and that the modulus is |z| = a2 + b2 . Verify the equations below using pencil and paper and then check your computations using Derive. Note that in Derive you use the function CONJ for the complex conjugate and ABS for the modulus. Verify equations in Derive by authoring their difference and simplifying. You should get zero if the two expressions are equal. a. z + w = z̄ + w̄ b. z − w = z̄ − w̄ c. zw = wz d. zw = z̄ w̄ e. |z|2 = zz̄ f. |zw| = |z||w| 2 Now let P (x) = x + 2x + 3 be a typical quadratic polynomial. Use the above relations to show that: g. P (z) = P (z̄) 92 CHAPTER 5. FINDING ROOTS USING COMPUTERS The above relation implies that P (z) = 0 if and only if P (z̄) = 0 so that the two roots of P (x) = 0 are conjugates to each other. Use Solve to verify this fact by computing the roots from the quadratic formula. 9. Use the discussion about complex numbers in Section 5.4 and the utility function DRAW COMPLEX to answer these questions. a. Compute the first ten powers of 1 + i and plot the result. b. Compute the first ten powers of c. Compute the first ten powers of 1 + 12 i and plot the result. 2 √1 + √1 i and plot the result. 2 2 d. One of the above examples spirals in toward the origin. What geometric conditions on a complex number z = x + y i do you think would force its powers to spiral into the origin? The rate of the convergence of Newton’s method to a solution r of f (x) = 0 is determined by | NG0 (r)|. Since NG(r) = r we say that r is a fixed point for NG(x). If 0 < | NG0 (r)| < 1 then r is said to be an attractive fixed point because nearby points are drawn to r by iterating. If NG0 (r) = 0, then r is called a super attractive fixed point. The hypotheses of Theorem 1 on page 75 imply that NG(r) = r and NG0 (r) = 0 which guarantees that the convergence was very fast. In the following problems you explore situations where NG0 (r) 6= 0. As long as | NG0 (r)| < 1 Newton’s method will still converge to r if x0 is close enough to r, but not as fast as the super attractive case. *10. Theorem 1 had the hypothesis that f (r) = 0 and f 0 (r) 6= 0. In this problem we explore what happens to a function when f 0 (r) = 0. Let f (x) = x(x2 − 2)2 . a. Graph f (x) and plot DRAW NEWT(x(x^2-2)^2,x,3,5) (rescale to get a good picture). b. Find the first 10 Newton √ iterates starting with x = 2. How fast are they approaching 2 compared with the example shown in formulas (4) and (6)? (Use 10 digits precision.) √ √ c. Compute (exactly)√NG( 2) and NG0 ( 2), where NG is defined by formula (2). Is 2 a super attractor? 5.6. LABORATORY EXERCISES 93 d. Find a and b so that a 6= b and NG(a) = b and NG(b) = a. (Hint: Start by visualizing this situation graphically. Then try guessing an approximate solution by looking at the graph and experimenting with the DRAW NEWT function. Finally, use algebra to solve the equation: NG(NG(a)) = a for a and then put b = NG(a).) √ e. Suppose now that f (x) = x(x2 − 2)3 . Find NG0 ( 2). What do √ you think NG0 ( 2) would be for f (x) = x(x2 − 2)k ? (Look up Theorem 2 on page 77 to see if this situation is a consequence of that result.) 11. The function f (x) = x1/3 has a root at x = 0. Find NG(x), NG0 (x), and NG0 (0). Find 10 iterates of Newton’s method starting with x0 = 0.1. (Note: Make sure that the Precision Mode is set to Exact or else there may be problems with this exercise.) 12. Let x1 , x2 , . . . be the Newton iterates starting at x0 , i.e., x1 = NG(x0 ) and xn+1 = NG(xn ) for n = 1, 2, . . . . In Theorem 1 on page 75, it is proved that there is an interval I, with midpoint r, and a constant M such that |xn+1 − r| ≤ M|xn − r|2 whenever xn is in the interval I. Assume that x0 is in the interval I and satisfies |x0 − r| ≤ 1 10M where M is the above constant. Use pencil and paper (and perhaps mathematical induction) to prove: a. Each xn is in the interval I. b. The inequality n |xn − r| ≤ M −1 10−2 holds for n = 0, 1, 2, . . . . 94 CHAPTER 5. FINDING ROOTS USING COMPUTERS c. Check your work above by having Derive calculate ITERATES(mt^2, t, 1/(10m), 10). If you Approximate the result rather than simplifying then the answer will be expressed using powers of 10 which makes for easier reading. d. Interpret the above rate of convergence into the number of decimal place accuracy achieved with each approximate xn . √ 13. Use the bisection method to estimate 2. *14. The light area in Figure 5.5 on page 84 shows the basin of attraction of the root 1 when using Newton’s method on x3 − 1. The origin of the complex plane is in the middle of this figure. Note that most of the negative real axis (the negative x–axis) is in the white area. This means that starting with most negative real numbers, Newton’s method will converge to 1. Try this for x0 = −1 and −2. If you look closely at the figure you see that black pinches down on the negative real axis at various points. Find the value of the first such point to the left of the origin. Chapter 6 Numerical Integration Techniques 6.1 Introduction This lab discusses numerical integration. Numerical integration is described in most calculus books and is sometimes covered in second semester calculus. You may want to look over this part of your calculus text. A function is called elementary if it is made up of sums, products, powers, and compositions of the trig functions and ln x and ex . Although the derivative of any elementary function is elementary, not all such functions have elementary antiderivatives. For Rexample, there is no elementary function whose derivative is sin(x2 ), i.e., sin(x2 ) dx is not an elementary function. Consider the problem Z 1 sin(x2 ) dx −1 Even though sin(x2 ) has no elementary antiderivative, the area defined by the integral certainly exists. So how do we find it? We use numerical integration. Rb Consider the integral a f (x) dx, and for simplicity assume f (x) ≥ 0 and that a < b. The idea of numerical integration is to choose intermediate points a = x0 < x1 < x2 < · · · < xn = b and estimate the area in the strip below f (x) for xi ≤ x ≤ xi+1 and then add up these estimates; see Figure 6.2 on page 100. Of course the width of this strip is xi+1 − xi . The height varies with x. Some of the most common ways of estimating the area of the strip 95 CHAPTER 6. NUMERICAL INTEGRATION TECHNIQUES 96 are: • Left endpoint: f (xi ) (xi+1 − xi ) • Right endpoint: f (xi+1 ) (xi+1 − xi ) • Midpoint: f( • Trapezoid: 1 [f (xi+1 ) + f (xi )] (xi+1 − xi ) 2 1 xi+1 + xi f (xi+1 ) + 4f ( ) + f (xi ) (xi+1 − xi ) 6 2 • Simpson’s Rule: xi+1 + xi ) (xi+1 − xi ) 2 The last one, Simpson’s Rule, is based on the best quadratic approximation to f (x). This basic idea was derived in Exercise 4 on page 65 in Chapter 4. Section 6.5 on page 104 has a detailed explanation. Usually we choose the xi ’s equally spaced, so that (1) xi = a + b−a i n b−a . Thus, if we use the left endpoint Of course, in this case, xi+1 − xi = n approximation, we get Z b n−1 b−aX (2) f (x) dx ≈ f (xi ) n i=0 a Notice that we factor out the term than multiplying every term. 6.2 b−a and multiply by the sum rather n An Example Formula (2) suggests how we might do numerical integration with Derive. Let u be the expression for f (x). We can define a Derive function for the left endpoint method by LEFT(u,x,n,a,b) := (b-a)/n * SUM(SUBST(u, x, a + k*(b-a)/n), k, 0, n-1) 6.2. AN EXAMPLE 97 (Recall that SUBST(u, x, a) substitutes a for x in u so SUBST(u, x, a+k(b-a)/n) really evaluates u at x = a + k(b − a)/n.) LEFT is already defined for you in the file ADD-UTIL. All of the other methods mentioned above are also defined in that file with the names: RIGHT, MID, TRAP, and SIMP. Now let’s try an example. Although we would normally use these approximations for integrating expressions without an elementary antiderivative, we can test how good they are by applying them to something we do know how to integrate: Z 2 1 dx = ln 2 ≈ 0.693147180559 1 x To use the left endpoint method with n = 10 intervals, we would just author and then approximate LEFT(1/x, x, 10, 1, 2) Doing this gives the answer 0.718771. Similarly if we wanted to use the trapezoid method we would author and approximate TRAP(1/x, x, 10, 1, 2) which gives 0.693771. We want to compare the accuracy of these methods of approximation and also see how much the accuracy is improved by increasing n. We will try them for n = 10, 100, 1,000 and 10,000. A fancy way to see and compare approximation values, using the left endpoint rule for a range of n is to start by authoring the vector [10^n,LN(2),LEFT(1/x,x,10^n,1,2),LEFT(1/x,x,10^n,1,2)-LN(2)]. Then, use the Calculus/Vector menu to produce vector([10^n, LN(2), LEFT(1/x,x,10^n,1,2), LEFT(1/x,x,10^n,1,2) - LN(2)], n, 1, 4) where the Variable n varies from a Starting value of 1 to an End value of 4. Approximating this expression yields a 4 × 4 matrix with the first column being the number of partitions, the second column being the exact value, the third column being the approximate value obtained from the left endpoint 98 CHAPTER 6. NUMERICAL INTEGRATION TECHNIQUES Figure 6.1: Approximating ln 2 with left endpoint method method and the fourth column being the error. See Section 0.14 on page 18 for more discussion on the vector function. Notice from Figure 6.1 that the accuracy in this method seems to be roughly 1, 2, 3 and 4 digits respectively. This is in fact the case and it can be proved that using 10n subdivisions yields an accuracy of n decimal places. This is not very efficient since it requires a billion computations (109 ) to achieve calculator accuracy of 9 digits. Try comparing computation times for various powers of 10 to see how this rapidly becomes impractical. If we try to obtain simple calculator accuracy of 8-12 decimal places, then this can take hours on a PC which is impractical. It is for this reason that we investigate the other methods for computational purposes. By replacing the left endpoint method with the trapezoid method in the computation in Figure 6.1 we see a remarkable difference. The accuracy now appears to be approximately 2, 4, 6 and 8 digits respectively. Thus, the 4 decimal place accuracy achieved by the left endpoint method using 10,000 rectangles is equivalent to the trapezoid method using only 100 trapezoids. We can summarize the theoretical error for these methods as follows. It 6.2. AN EXAMPLE 99 can be shown that error in using the left endpoint method is no greater than 1 (b − a)2 0 (3) max |f (x)| . x∈[a,b] 2 n On the other hand, the error in using the trapezoid method is no greater than (b − a)3 1 00 max |f (x)| 2 . (4) 12 x∈[a,b] n In our example (with f (x) = 1/x, a = 1 and b = 2) we have the bracketed quantity in (4) is equal to 1/6 so that the error is no greater than n−2 /6. Thus, n = 100 indeed yields an error of less than .00002 or approximately 4 decimal digits. You might want to modify the previous table we did in Derive to add another column displaying this theoretical error estimate (3) (and (4) for the trapezoid method) and compare it to the actual error. Although the trapezoid method is quite accurate and fairly efficient, the Simpson’s Rule is vastly more efficient. The error in using the Simpson method is no greater than 1 (b − a)5 (4) max |f (x)| 4 . (5) 180 x∈[a,b] n Notice the main difference between (4) and (5) is that we now have an error which is roughly 1/n4 (the bracketed quantity in our example is 24/180). Thus, with n = 10 we obtain the same accuracy as n = 100 in the trapezoid method or n = 10, 000 in the left endpoint method. A table illustrating these differences can be obtain by approximating vector([LEFT(1/x,x,10^n,1,2) - LN(2), TRAP(1/x,x,10^n,1,2) - LN(2),SIMP(1/x,x,10^n,1,2) - LN(2)], n,1,4). These functions are available by doing Load/Utility with the file ADD-UTIL. Seeing the accuracy of SIMP(1/x, x, 104 , 1, 2) requires 16 digits of accuracy. Recall from Section 0.6 how to increase the accuracy of a calculation. To get a geometric feeling for why the trapezoid method is so much better than the left endpoint method one need only draw a sketch comparing the two methods. It’s possible to graphically represent these approximations using Derive. Recall from Chapter 4 that one can plot a collection of points, 100 CHAPTER 6. NUMERICAL INTEGRATION TECHNIQUES (x1 , y1), (x2 , y2), . . . , (xn , yn ), by plotting an n × 2 matrix. Thus, a rectangle can be drawn by plotting a 5 × 2 matrix. (Note: The 5th point is the same as the first point so that the figure is closed.) In order to draw n rectangles, one plots an n-vector with entries corresponding to each of the rectangles. This vector resembles a 5 × 2n matrix but in facts its a vector with matrix entries. To generate this vector use the function DRAW LEFT(u,x,n,a,b) for the left endpoint method and DRAW TRAP(u,x,n,a,b) for the trapezoid method. Both of these are defined in ADD-UTILe. Figure 6.2 illustrates both of these. One must zoom in a bit to see that the trapezoid is actually different from the original curve (even for n = 4). Figure 6.2: Rectangular vs trapezoidal approximation 6.3 Theorem on Error Estimates∗ Let us indicate how one obtains some of these error estimates by proving the following theorem: ∗ 6.3. THEOREM ON ERROR ESTIMATES 101 Theorem 1. Suppose that f (x) is a continuous function on the interval [a, b]. The following hold: (a) If f 0 (x) is bounded on the interval [a, b], then the error in approximating Rb f (x) dx with LEFT(f (x), x, n, a, b) is proportional to 1/n. a (b) If f 00 (x) is bounded on the interval [a, b], then the error in approximating Rb f (x) dx with TRAP(f (x), x, n, a, b) is is proportional to 1/n2 . a (c) Finally, if f (4) (x) is bounded then the error in approximating the integral using Simpson’s Rule SIMP(f (x), x, n, a, b) is proportional to 1/n4 . Proof. We’ll prove parts (a),(b) and leave (c) to a more advanced text. We first show that the error obtained by approximating a function f (x), over the k th sub-interval [xk−1 , xk ], by the constant f (xk−1 ) is proportional to 1/n. (xk is defined by (1).) This estimate uses the Mean Value Theorem as follows: for xk−1 ≤ x ≤ xk we have |f (x) − f (xk−1 )| = |f 0 (cx )(x − xk−1 )| ≤ max |f 0 (x)| x∈[a,b] (b − a) . n This bounds how much f (x) and f (xk−1 ) can differ for x between xk−1 and xk ; and this means the error in using the left endpoint estimate for the strip between xk−1 and xk is at most the width of the strip, (b − a)/n, times this bound. Adding this over all n strips gives Z b 1 2 0 f (x) dx − LEFT(f (x), x, n, a, b) ≤ (b − a) max |f (x)| x∈[a,b] n a which is the desired result. This completes the proof of part (a). The proof of part (b) is similar except it uses the Mean Value Theorem three times. We estimate the error from approximating f (x) by the linear function obtained from the endpoints values f (xk−1 ) and f (xk ). Thus, for xk−1 ≤ x ≤ xk we have f (xk ) − f (xk−1 ) f (x) − · (x − xk−1 ) + f (xk−1 ) xk − xk−1 f (xk ) − f (xk−1 ) = (f (x) − f (xk−1 )) − · (x − xk−1 ) xk − xk−1 = |f 0(c1 )(x − xk−1 ) − f 0 (c2 )(x − xk−1 )| = |f 00 (c3 )||c1 − c2 ||x − xk−1 | 2 b−a 00 ≤ max |f (x)| x∈[a,b] n 102 CHAPTER 6. NUMERICAL INTEGRATION TECHNIQUES and thus at each point the error is proportional to 1/n2 and so is the integral over [a, b]. More precisely, Z b 1 3 00 f (x) dx − TRAP(f (x), x, n, a, b) ≤ (b − a) max |f (x)| 2 x∈[a,b] n a We note that the error estimates above differ from (3) and (4) only in the constant term and not the power of n. To obtain the better constant more careful estimation needs to done in the above argument. On the other hand, the constants obtained above suffice for most applications. 6.4 More on Error Estimates∗ In order for any method of approximation to be useful we must know something about the error. The error estimates given in equations (4) and (5) usually work quite well. But they do require certain boundedness assumptions which are not always true. Consider Z 1 dx (6) 3/2 0 1+x Use Derive to graph g(x) = 1/(1 + x3/2 ). Notice that the graph is pretty tame; there are no wild oscillations and it would appear that the trapezoid method could be used to obtain a good approximation of (6). In fact it does give a good approximation. In order to use (4) to estimate the error in using the trapezoid rule to . Use Derive to do this. Note that g 00 (0) evaluate (6) we need to find g 00√ is undefined; but that limx→0+ xg 00 (x) = − 34 . This means that g 00 (x) ≈ − 34 x−1/2 and hence is not bounded on [0, 1] so that (4) gives us no information about the error. We can work around this problem by noticing that for each n we can apply (4) to the interval [ n1 , 1] instead and use a different technique for that first interval. Thus, using |g 00 (1/n)| for the maximum on [1/n, 1] (check that this is valid for all large n), we obtain from (4) that Z 1 √ 1 c g(x) dx − TRAP(g(x), x, n − 1, 1/n, 1) ≤ c n · ≈ . (n − 1)2 n3/2 1/n 6.4. MORE ON ERROR ESTIMATES ∗ 103 On the small interval we observe that g(x) is decreasing for x > 0 and that g(0) − g(x) = x3/2 /(1 + x3/2 ) ≤ x3/2 . Thus, by comparing areas we see that Z 1/n g(x) dx − TRAP(g(x), x, 1, 0, 1/n) ≤ 0 1 1 1 (g(0) − g( )) ≤ 5/2 . n n n Combining these estimates shows that the error obtained using the trapezoid method is proportional to n−3/2 (which is the larger of the two errors). This is a better result than 1/n but not as good as 1/n2 . Actually, one can improve the 3/2-power a little by refining these estimates. The next question is what can you do without explicit estimates like the above but only using monotonicity or convexity of the graph. If f Ris increasb ing on [a, b] notice that the left endpoint method of estimating a f (x) dx always underestimates the integral while the right endpoint method overestimates it. Similarly, if f is decreasing the opposite inequalities hold. If we let LEFT(f (x), x, n, a, b) and RIGHT(f (x), x, n, a, b) be the left and right endpoint estimates then: Z b f (x) dx ≤ RIGHT(f (x), x, n, a, b) (7) LEFT(f (x), x, n, a, b) ≤ a if f 0 (x) ≥ 0 on [a, b] and Z b (8) RIGHT(f (x), x, n, a, b) ≤ f (x) dx ≤ LEFT(f (x), x, n, a, b) a if f 0 (x) ≤ 0 on [a, b] See Figure 8.2 on page 143 which makes these relations quite obvious. A similar relation holds between the trapezoid and midpoint methods but depends on the concavity, i.e., the second derivative of f rather than the slope, i.e., the first derivative of f . If we let TRAP(f (x), x, n, a, b) and MID(f (x), x, n, a, b) be the trapezoid and midpoint estimates then Theorem 2. If f is concave up on [a, b], i.e., f 00 (x) ≥ 0, then Z MID(f (x), x, n, a, b) ≤ b f (x) dx ≤ TRAP(f (x), x, n, a, b) a 104 CHAPTER 6. NUMERICAL INTEGRATION TECHNIQUES If f is concave down on [a, b], i.e., f 00 (x) ≤ 0, then Z b f (x) dx ≤ MID(f (x), x, n, a, b) TRAP(f (x), x, n, a, b) ≤ a Figure 6.3 shows why this is true. It has two graphs of the same function which is concave up. the line in the left part shows the trapezoid used in the trapezoid rule. Clearly it overestimates the integral. The midpoint rule is illustrated in the right graph. The midpoint rule gives the area under the line AB. The line CD is the tangent line through the midpoint. The area below AB is the same as the area below CD (why?). So both are the midpoint estimate. But clearly the area under CD is less than the area under the curve. D A B C Figure 6.3: Trapezoid and midpoint rule for concave functions 6.5 Deriving Simpson’s Rule∗ Simpson’s Rule uses the quantity x1 + x2 1 f (x1 ) + 4f ( ) + f (x2 ) (x2 − x1 ) (9) 6 2 6.6. LABORATORY EXERCISES 105 Rx to approximate x12 f (x) dx. The can be derived by solving for the quadratic g(x) = ax2 + bx + c which passes through the 3 points (x1 , y1 ), (x2 , y2) and (x3 , y3 ); where yi = f (xi ) and x3 = (x1 + x2 )/2 Rwhich is simply the midpoint x or average of x1 and x2 . One then computes x12 g(x) dx and uses this for our approximation. Now the algebra involved in this computation is fairly formidable and yet the beauty of it is that the answer (given in (9)) is so simple. That’s why the formula for Simpson’s Rule looks hardly any different from the formula for the left endpoint rule and as a result the computation times are approximately the same. Now the algebra involved is the same as that of Chapter 4. We solve 3 equations for the unknowns a, b and c, then we integrate the result. Alternately, we can make the derivation into a two step process by using the function CURVEFIT(x,data) where the data matrix is y1 x1 y2 data := x2 x1 +x2 y3 2 The resulting quadratic polynomial contains some pretty large expressions involving xi and yi . Nevertheless, one need only integrate this expression over the interval x1 ≤ x ≤ x2 to get the desired result. 6.6 Laboratory Exercises Start off your lab by Loading the ADD-HEAD file. After you have done this the functions described in Section 6.2: LEFT, MID, TRAP, and SIMP, which compute the integral approximations using respectively the left endpoint method, the midpoint method, the trapezoid method and Simpson’s rule, will all be defined. In addition the functions DRAW LEFT and DRAW TRAP, which draw the rectangles and trapezoids used in the graphical demonstration of Figure 6.2 on page 100, will be defined. 1. a. Use Derive to verify the formula Z 1 4dx π= 2 0 1+x b. Plot the graph of f (x) = 4/(1 + x2 ) and verify that this function is decreasing on the interval [0,1]. 106 CHAPTER 6. NUMERICAL INTEGRATION TECHNIQUES c. Evaluate LEFT(4/(1 + x2 ), x, 1000, 0, 1) and the similar quantity using the RIGHT function. Then, use part (b) along with equation 8 on page 103 to determine how accurate an approximation either of these numbers is to π. 2. Evaluate TRAP(1/x, x, n, 1, 2) and SIMP(1/x, x, n, 1, 2) for n = 10, 100, and 1, 000. Also use Derive to find ln 2 using 15 decimal place precision. Which of the 6 approximations above (if any) gives ln 2 to 10 or more decimal places? 3. Use the trapezoid method and Simpson’s Rule to approximate each of the following integrals. Use n = 10, 20, and 30. Derive has its own method of doing approximate integration. Find the answer it gets. You can do this by authoring the integral and choosing approximate. Compare the decimal accuracy of the Simpson approximates with the one computed by Derive above. Z 3 Z 1 1 2 sin(x ) dx b. dx a. 3 −1 0 1+x 4. Using the midpoint method MID(1/x, x, n, a, b), approximate ln 10 (= R 10 (1/x)dx) using n = 10, 100, 1000 and compare your answers with 1 Derive’s approximation. 5. For the following integrals use the error estimate (4) described above to find an n large enough so that the trapezoid method will give an approximation of the integral with error at most 0.005. Give both the approximate value of the integral and the smallest n which guarantees (using formula (4)) that you will be within this error, and also give M2 = max{|f 00 (x)| : a ≤ x ≤ b}. Hints: Use Derive to find f 0 , f 00 , and f 000 . For the first integral below, you can easily see that the maximum for |f 00 | occurs when x = 1. For the second, solve f 000 (x) = 0; this tells you where the maximums of |f 00 (x)| can occur, and, using this (and maybe some plotting), you can find M2 . For the third integral don’t forget that M2 if the maximum of the absolute value of f 00 (x) on [0, 2]. Once you have M2 , find n large enough so that the error given in (4) is at most 0.005. 6.6. LABORATORY EXERCISES Z Z e2 a. ln x dx b. 1 Z c. 0 107 2 2 1 2 1 dx 1 + x2 1 dx 1 + x2 6. Do the same as the last problem, but use Simpson’s Rule this time and of course use formula (5) instead of (4). 7. Suppose that f (x) = cx + d for some constants c and d. a. Use the MID function to verify that Z b f (x) dx = MID(f (x), x, n, a, b) a for all n. (Hint: To show that two different looking expressions are equal, try Simplifying their difference.) b. Assuming that a, b, c and d are all positive use pencil and paper to verify the result in (a) by using simple geometric considerations. c. Explain why the area below AB is the same as the area below CD in Figure 6.3. 8. Find where 1/(1 + x3/2 ) is concave up and where it is concave down in the interval [0, 1]. Use Theorem 2 to give lower and upper estimates for Z 1 dx . 3/2 0 1+x Use n = 20 for all numerical estimates. 9. Prove the following simple relationship between the trapezoid, midpoint, and Simpson’s rules: SIMP(f (x), x, n, a, b) = 2 1 TRAP(f (x), x, n, a, b) + MID(f (x), x, n, a, b) 3 3 108 CHAPTER 6. NUMERICAL INTEGRATION TECHNIQUES Hint: First define f (x) to an unspecified function by Authoring f(x) :=. Now Author and Simplify the two expressions SIMP(f(x),x,n,a,b) (1/3) TRAP(f(x),x,n,a,b) + (2/3) MID(f(x),x,n,a,b) Finally simplify the difference of the two resulting expressions. 10. Do the calculations needed to verify Simpson’s rule as outlined in Section 6.5. This is the same problem as Exercise 4 in Chapter 4. 11. Suppose that f (x) = cx2 + dx + e for some constants c, d and e. a. Use the SIMP function to verify that Z b f (x) dx = SIMP(f (x), x, n, a, b) a for all n. (Hint: To show that two different looking expressions are equal, try Simplifying their difference.) b. Explain why Simpson’s rule gives the exact answer whenever the integrand is a quadratic polynomial. (Hint: Study the derivation in Section 6.5) c. Show that part (a) holds even when f (x) is an arbitrary degree 3 polynomial. d. Show that the error estimate (5) for Simpson’s rule implies the result in part (c). Chapter 7 Taylor Polynomials 7.1 Polynomial Approximations Suppose we want to approximate a function f (x) by a polynomial f (x) ≈ Pn (x) = a0 + a1 x + a2 x2 + · · · + an xn = n X ak xk . k=0 One natural way to to do this is to require that f (0) = Pn (0), f 0 (0) = Pn0 (0), (k) f 00 (0) = Pn00 (0), etc., i.e., f (k) (0) = Pn (0) for k = 0, . . . , n. This gives n + 1 equations for the n + 1 unknowns a0 , . . . , an . If we differentiate, say P3 (x), several times these equations become quite clear: (1) (2) (3) (4) P3 (x) = a0 + a1 x + a2 x2 + a3 x3 P30 (x) = 1 · a1 + 2 · a2 x + 3 · a3 x2 P300 (x) = 2 · 1 · a2 + 3 · 2 · a3 x P3000 (x) = 3 · 2 · 1 · a3 Setting x = 0 in the first of these equations gives a0 = f (0). Setting x = 0 in the second of these equations gives 1 · a1 = f 0 (0). Taking more derivatives and setting x = 0, we get 2 · 1 · a2 = f 00 (0), 3 · 2 · 1 · a3 = f 000 (0). By thinking about factorials, you can see the pattern evolving: the general term (solving for ak ) is (5) ak = f (k) (0) k! for 109 0≤k≤n CHAPTER 7. TAYLOR POLYNOMIALS 110 Pn (x) is what is known as the nth Taylor polynomial for f (x): (6) Pn (x) = n X f (k) (0) k=0 k! xk The coefficient of xk in Pn (x) is just f (k) (0)/k! (which is the same for all n as long as n ≥ k). This quantity is called the k th –Taylor coefficient for f (x). As our first application, notice that it follows from (5) that the graph of y = P1 (x) is just the tangent line to the curve y = f (x) at the point (0, f (0)). We studied this method of approximation extensively in Section 2.2. Thus, since the tangent line yields the best degree-one approximation to the function, near the point x = 0, it is reasonable that guess that Pn (x) is the best nth –degree approximation, near x = 0. To have Derive compute a Taylor polynomial for a function first select the Calculus/Taylor menu, then enter the function in the form, enter some integer n, say n = 5, for the Degree and leave the Point1 value at its default value of 0. This results in the expression TAYLOR(f(x),x,0,5). An alternate approach after becoming familiar with its syntax is to simply author this expression. See Figure 7.1 on the facing page for some of the basic examples and a comparison of the graph of f (x) = 1/(1 − x) and it’s 5th degree Taylor polynomial approximation. An interesting exercise is to load the file F-TAY0 which contains the expressions from Figure 7.1 and compare graphically the various functions with their Taylor polynomials of different degrees. 7.2 Examples As we see from Figure 7.1 on the next page, the formulas for the Taylor polynomials for the function f (x) = 1/(1 − x) are pretty easy to guess after looking at a few examples: Pn (x) = 1 + x + x2 + x3 + · · · + xn . Since the graphs of these polynomials appear to approximate the graph of the function f (x) to a high degree of accuracy as n gets larger and larger (at 1 For now we just take the Point value to be 0. Later, in Section 7.6 we discuss how to use this variable. 7.2. EXAMPLES 111 Figure 7.1: Basic examples of Taylor polynomials least for values of x satisfying −1 < x < 1) we conjecture that (7) ∞ n X X 1 = 1 + x + x2 + x3 + · · · = lim xk = xk . n→∞ 1−x k=0 k=0 The three dots in the above formula means that you are to keep adding more and more terms forever. Since adding an infinite list of numbers together looks like an impossible task, we define this in terms of limits. That is what we mean by the last expression above. More generally, we denote an infinite series by ∞ n X X ak = lim ak . k=0 n→∞ k=0 Of course, any time we discuss limits we need to worry about whether or not the limit exist! When the aboveP limit exists for an infinite series with ak is convergent. Otherwise, we say terms ak we then say that the series the series is divergent. We will thoroughly discuss this topic in Chapter 8. In case you already know something about infinite series you might notice CHAPTER 7. TAYLOR POLYNOMIALS 112 that our conjecture in (7) above is in fact the most famous example of an infinite series; namely, it is the geometric series. We got the form of the Taylor polynomials above by the method of pattern recognition, looking at lots of examples using Derive and then guessing at the general result. To verify this result we must use (5) to compute the Taylor coefficients. We will need to show f (k) (0) = k!. Using Derive we can make a table of derivatives by authoring VECTOR([k, DIF((1-x)^-1,x,k)], k, 0, 4) and then simplifying. The answers seem to follow the pattern k!/(1 − x)k+1 which can be verified by having Derive check that: DIF((1-x)^(-k-1) k!,x) = (1-x)^(-k-2) (k+1)! (Try this for yourself). Note that in Figure 7.1 the 5th degree Taylor polynomial approximation gives a very good approximation on the interval [−.5, .5]. As we mentioned earlier, you should Load the file F-TAY0 and experiment with higher degree approximations to see how the interval size improves, but the graphical evidence suggests the infinite series representation is only valid for −1 < x < 1 (even though the function appears well behaved near x = −1). We will demonstrate this fact later. Three other important examples are the series for ex , sin x, and cos x. If we look carefully at Figure 7.1 we might guess the pattern for the exponential function because the denominators 1, 1, 2, 6, 24, 120 are just k! as k varies from 0 ≤ k ≤ 5. On the other hand, equation (5) gives the required formula Thus, in this easily since all derivatives f (k) (x) = ex and so are 1 at x = 0. P (k) th case f (0)/k! = 1/k! so the n Taylor polynomial is simply nk=0 xk /k! = 1 + x + x2 /2! + · · · + xn /n!. Now, if we can also take the limit as in the case of the geometric series, then (8) x e = ∞ X xk k=0 n X x2 xk =1+x+ + · · · = lim . n→∞ k! 2! k! k=0 In fact, the series above does converge, for all values of x, to the exponential function. Moreover, it is this series that forms the basis for numerical calculations of the exponential function on computers and calculators. Section 7.5 will give a complete explanation of this matter. 7.2. EXAMPLES 113 Figure 7.2: Taylor polynomials for sin x We can proceed in a like manner to compute the Taylor polynomials for the sine and cosine functions. The only problem is that the pattern for the successive derivatives is a little trickier. Let us discuss the function f (x) = sin x since the analysis of the cosine function is similar. If we make a vector of f (k) (x) with 0 ≤ k ≤ 4 we get [sin x, cos x, − sin x, − cos x, sin x] and it is clear that the pattern will repeat in groups of 4 with f (4k) (x) = sin x. Substituting x = 0 gives the pattern [0, 1, 0, −1] and hence every even power of x, i.e., x0 , x2 , x4 , . . . , will have a zero coefficient; whereas, the odd power x2k+1 will have the coefficient (−1)k /(2k+1)! by (5). See Figure 7.2 for several Taylor polynomials of the sine function. The only unfortunate part about making these computations in Derive is that the factorials are expanded to their integer values which makes it difficult to recognize the patterns. On the other hand, it’s easy to see how fast the factorials in the denominator grow which means that the added terms are quite small in magnitude. At any rate, the Taylor polynomials form the partial sums of an infinite series representation of sin x which is convergent for all −∞ < x < ∞. This series 114 CHAPTER 7. TAYLOR POLYNOMIALS and the one for cos x are given below: (9) X x3 x5 x2n+1 + + ··· = (−1)n sin x = x − 3! 5! (2n + 1)! n=0 (10) X x2 x4 x2n cos x = 1 − + +··· = (−1)n 2! 4! (2n)! n=0 ∞ ∞ Figure 7.3: Approximating sin x with its Taylor polynomials Next we want to graph several of these Taylor polynomials and compare them with the graph of sin x. This is done in Figure 7.3. Another instructive exercise is to plot 3 or more Taylor polynomials all at once by making a vector of the functions and then plotting the vector. As each successively higher degree polynomial is plotted, the range of close approximation gets larger and larger. Curiously, one sees from Figure 7.3 that the approximation is good up to a point and then is very bad thereafter. The basic idea in approximating is simply to take more terms; i.e., use a higher degree Taylor polynomial, to obtain more accuracy. An example of a more precise question 7.3. TAYLOR’S THEOREM WITH REMAINDER 115 we shall be interested in is: What degree n is needed for approximating the sine function on the interval [0, π/2] to within 6 decimal places? 7.3 Taylor’s Theorem with Remainder We are interested in how accurately a Taylor polynomial approximates f (x) and for what values of x does the Taylor series converge to f (x). The basic result is the following theorem: Theorem 1. Suppose that f (x) is (n + 1)–times continuously differentiable on the interval [0, b]. Let the nth degree Taylor polynomial be denoted by Pn (x). Then, for any 0 ≤ x ≤ b we have (11) |f (x) − Pn (x)| ≤ max |f (n+1) (t)| · 0≤t≤x |x|n+1 |x|n+1 =M· (n + 1)! (n + 1)! where we abbreviate the maximum by M. Furthermore, the theorem also holds when the defining interval is [−b, 0] for some positive b. The only change is that now −b ≤ x ≤ 0 and the maximum in (11) is taken over the interval x ≤ t ≤ 0. Observe that the error estimate in (11) is similar to those we obtained for the approximate integral formulas (Trapezoid method, Simpson’s rule) in that they depend on the maximum of a high order derivative, look back at the formulas on page 99. Also, notice that when n = 0 then (11) follows immediately from the Mean Value Theorem and in fact, you can think of (11) as a higher order Mean Value Theorem. The proof is based on a simple application of the integration by parts formula; namely, for any continuously differentiable function g(t) which satisfies g(0) = 0, then Z (12) 0 x (x − t)m dt = g(t) m! Z 0 x g 0(t) (x − t)m+1 dt (m + 1)! m = 0, 1, . . . Just put u = g(t) and v = (x − t)m+1 /(m + 1)! and apply the integration by parts formula. Notice that the integrated terms, i.e., the uv|x0 terms, vanish because g(0) = 0 at the left endpoint and (x − t)m+1 is zero when t = x. CHAPTER 7. TAYLOR POLYNOMIALS 116 Proof. Put g(t) = f (t) − Pn (t) let M be the maximum of |f (n+1) | on the interval [0, x]. By the definition of the Taylor polynomial, observe that g (m) (0) = 0 for m = 0, 1, . . . , n and g (n+1) (t) = f (n+1) (t) where the second fact follows since the (n + 1)st –derivative of any degree n polynomial is zero (look back at (1) on page 109). Now we get to apply (12) to g 0 , g 00 , . . . , g (n) with the result that Z x Z x Z x (x − t)2 0 00 000 dt g (t) dt = g (t)(x − t) dt = g (t) 2 0 0 0 Z x (x − t)n dt = ··· = g (n+1) (t) n! 0 and hence that Z x f (x) − Pn (x) = g(x) − g(0) = g 0 (t) dt 0 Z x Z x (x − t)n (x − t)n (n+1) dt = dt . = g (t) f (n+1) (t) n! n! 0 0 We take absolute values of the left and right-hand sides of the above to get Z x (x − t)n |f (x) − Pn (x)| ≤ dt |f (n+1) (t)| n! 0 Z x xn+1 (x − t)n ≤ dt = M M n! (n + 1)! 0 which proves the theorem. 7.4 Computing the Sine Function First observe that we don’t need to compute, for example, sin 100 directly since the sine function is 2π periodic. We just set x = 100 − 2kπ where the integer k is chosen so 0 ≤ x < 2π. In Derive we simplify the function MOD(100, 2π) to get k = 15 and x = 5.75221 approximately. Now it’s an interesting exercise to use the properties of the sine function to reduce the computation to the interval [0, π]. For example, if π < x < 2π then sin x = − sin(2π − x) where now 0 ≤ 2π − x < π. Similarly, you can use 7.4. COMPUTING THE SINE FUNCTION 117 the identity sin(π − x) = sin x to reduce the problem to the smaller interval [0, π/2]. It’s even possible to reduce the interval to [0, π/4]. We can use formula (11) to estimate the error in using the Taylor polynomial to estimate sin x. The computation of M = max |f (n+1) | might look a little formidable at first but we observe that any derivative is equal to either ± sin t or ± cos t and in either case M ≤ 1. Thus, we can take M = 1 and achieve 6 decimals of accuracy by determining the smallest integer n satisfying |x|n+1 ≤ 10−6 (n + 1)! (13) For approximations on the interval [0, π/2] we could just take the worst case by setting x = π/2 in the above. We now have reduced the problem to solving (13) for the smallest possible integer n. Unfortunately, the factorial expression means that we can’t use simple algebra to solve this inequality. A simple numerical approach would be to make a table with n in the first column and the above expression in the second column. Examining the data will result in an answer provided n is reasonably small. We did this earlier on page 138 when we studied the ratio test. If this fails, as with the 1/k 2 series, you might try testing various powers of 10. Both of these techniques are easy to do using the vector function. (In the next section we present another way of finding n.) In Figure 7.4, see the file F-TAY3, we analyze sin 100 by reducing the computation to a smaller value of x (x = 0.530973), determining which n yields an error of less than 10−6 (n = 7) and then computing using P7 (0.530973). Observe that for the sine function P2n+1 (x) = P2n+2 (x) and so for the error computation (13) we use the higher power 2n + 3 instead 2n + 2 and hence (14) | sin x − n X k=0 (−1)k |x|2n+3 x2k+1 |≤ (2k + 1)! (2n + 3)! for n = 0, 1, . . . Lastly, let us observe that the right hand side of (14) tends to zero for any x. After all, for x fixed, the ratio of terms above is 1 |x|2 |x|2n+5 (2n + 3)! · ≤ = 2n+3 (2n + 5)! |x| (2n + 5)(2n + 4) 2 for all large n. Thus, |x|2n+3 /(2n + 3)! ≤ cx /2n (or for that matter |x|n /n! ≤ cx /2n ) for some constant cx and the sequence tends to zero because 1/2n → 0. CHAPTER 7. TAYLOR POLYNOMIALS 118 By applying Theorem 1 we see that the Taylor series converges for all x and we indeed have the representation X x2n+1 x3 x5 + +··· = (−1)n 3! 5! (2n + 1)! n=0 ∞ (15) sin x = x − which is valid for all −∞ < x < ∞. In a similar manner we establish (10) on page 114. Figure 7.4: Approximating sin 100 within 6 decimals 7.5 Computing the Exponential Function. Now let’s repeat the above procedure for ex . We use the partial sums of (8) for approximating and (11) for determining the number of terms to use. Let’s assume x > 0. Since f (n+1) (x) = ex is an increasing function, we can take M = ex or more conveniently we will replace e with the larger value 3. 7.5. COMPUTING THE EXPONENTIAL FUNCTION. 119 Thus, ex − (1 + x + (16) xn 3x xn+1 x2 +···+ ) < 2! n! (n + 1)! and so we need only find n so that the right-hand side is sufficiently small. We would like to define a function in Derive to determine the number of terms n necessary to achieve 6 decimals places, rather than looking at tables. First of all, recall from the previous section that 3x xn+1 =0 lim n→∞ (n + 1)! for all values of x. Hence we are guaranteed that there is a first n for which the above quantity is less than 10−6 . Moreover, this proves that the Taylor series converges for all x, by Theorem 1, to ex . Thus, as stated earlier x e = ∞ X xk k=0 n X x2 xk =1+x+ + · · · = lim n→∞ k! 2! k! k=0 for all −∞ < x < ∞. Now consider the functions 1: 2: 3x xk < 10−6 , k-1, N1(x,k+1)) N1(x,k) := IF( k! N(x) := N1(x,1) and consider what happens when you Simplify N(5). The N-function computes the N1-function with a starting value of k = 1. The error expression is compared to 10−6 and if successful then k − 1 is the value of N(5); otherwise, k is increased by one and the process continues. Eventually, we get to a large enough k so that the comparison with 10−6 is successful and that value of k − 1 is returned as the value of the function. The function N1 is called a recursive function because its definition refers to itself. Care has to exercised with such functions to make sure that they eventually return a value and don’t continue computing forever (press the Esc if this happens). See Figure 7.5 and load the file F-TAY4 where these functions are used to define a new version of the exponential function (for x ≥ 0) which is accurate to 6 decimal places. A comparison of this function with the built in version obtained by approximating shows that the build in function is faster but the accuracy is the same for the first 6 decimals using P25 (x). CHAPTER 7. TAYLOR POLYNOMIALS 120 Figure 7.5: Approximating e5 within 6 decimals 7.6 Taylor Expansions About x = c Up to this point we have been approximating functions near x = 0. Suppose instead we want to approximate f (x) near x = c. A simple approach is to define g(x) = f (x + c) and approximate g(x) near x = 0 as before. Observe, that for x ≈ c we then have f (x) = g(x − c) ≈ Pn (x − c) = n X ak (x − c)k k=0 where Pn is the Taylor polynomial for g(x) and hence ak = f (k) (c) g (k) (0) = . k! k! By the above observation it makes sense to define Pn (x, c) = n X f (k) (c) k=0 k! (x − c)k 7.6. TAYLOR EXPANSIONS ABOUT X = C 121 to be the nth –Taylor polynomial of f (x), expanded about the point x = c. In Derive we just enter TAYLOR(f(x),x,c,n) or put the Point variable equal to c if we use the menu method. Similarly, the Taylor series expansion about the point c is f (x) = ∞ X f (k) (c) k=0 k! (x − c)k provided this series converges to f (x). To discuss convergence of the above we use Theorem 1 applied to the function g(x) = f (x + c). We do the same thing when we are computing with Derive. The advantage of this method for Derive is that if the fifth Taylor polynomial of f (x) around c is say P 5 k k=0 ak (x − c) , Derive will expand the powers of x − c so you get an expression like b5 x5 + b4 x4 + b3 x3 + b2 x2 + b1 x + b0 , and you won’t be able to see what the ak ’s are. Thus, If you want a Taylor polynomial of f (x) expanded about the point c, it is best to find the Taylor polynomial of f (x + c) expanded about 0. A nice illustration of this technique is to examine Figure 7.6 on the next page where f (x) = ln x is plotted along with P5 (x, 1). Since ln 0 is not even defined it would be foolish to think about its Taylor expansion about x = 0, however, expanding about x = 1 is a reasonable alternative. Notice that TAYLOR(ln x,x,1,5) produces a messy result in which the 6th term is hard to guess but that there is a clear pattern in TAYLOR(ln (x+1),x,0,5). In fact, it can be shown that X (−1)k+1 x2 x3 + ··· = xk , ln(1 + x) = x − 2 3 k k=1 ∞ (17) −1 < x ≤ 1 although the proof that the series converges to ln x on the interval 0 < x ≤ 1/2 is straightforward, see Exercise 2, is quite a bit harder than our earlier examples to get the full interval 0 < x ≤ 1. You can load the file F-LOG and try approximating ln x with higher degree Taylor polynomials to see if you can confirm the above representation. The full convergence problem for the logarithm function will be studied in Chapter 9. 122 CHAPTER 7. TAYLOR POLYNOMIALS Figure 7.6: Taylor expansion of the logarithm function 7.7 Interval of Convergence The Taylor series for f (x) = sin x, cos x, or ex converges to f (x) for all values of x. This means that, by taking the degree large enough, the Taylor polynomials of these functions will approximate f (x) accurately on arbitrarily large intervals. However, the geometric series (7) only converged for |x| < 1 and so the Taylor polynomial will approximate 1/(1−x) only on this interval. Of course, 1/(1 − x) is not continuous at x = 1 and hence it is not surprising that the Taylor polynomials will not converge at x = 1. Surprisingly, this divergence at x = 1 turns out to influence the convergence of the series for negative values of x! It is an important basic theorem about the convergence of Taylor series that if the series converges at a point x1 6= 0, then it also converges at all |x| < |x1 |. Thus, any Taylor series which diverges at x = 1 cannot converge at any x < −1. Why? If it did converge say at x1 = −2, then it would also converge at x = 1. But it diverges for x = 1 so it cannot possibly converge at x1 = −2 (or any |x| > 1). This fact also leads to the observation that the set of points x where the Taylor series converges must 7.7. INTERVAL OF CONVERGENCE 123 be an interval which is centered about the origin. Actually, there are four possibilities for the interval of convergence: (−r, +r), (−r, +r], [−r, +r) or [−r, +r] for some 0 ≤ r ≤ +∞.2 This number r is called the radius of convergence. Now consider the function 1/(1 + x2 ). We can obtain the Taylor series for this function by substituting −x2 for x in (7): X 1 2 4 6 = 1 − x + x − x + · · · = (−1)k x2k 1 + x2 k=0 ∞ (18) As before we can use Derive to plot several of the Taylor polynomials for this function; see Figure 7.7. Figure 7.7: Graphically finding the radius of convergence Notice that although the higher degree polynomials do a better job of approximating the function for |x| < 1, none of them work outside of this 2 We need to allow the notation r = +∞ so that the set of all real numbers can be represented as the interval (−r, r). 124 CHAPTER 7. TAYLOR POLYNOMIALS region. This strongly suggests that the radius of convergence of 1/(1 + x2 ) is Pr∞ = 1. This can be proved by observing the following: if the series s = k=1 ak converges then the terms ak → 0. This is because an = sn − sn−1 → s − s = 0. Now, in our case |ak | = |x|2k → ∞ whenever |x| > 1. So even though the function 1/(1 + x2 ) is defined and differentiable to all orders on the whole real line, the radius of convergence of its power series is r = 1. It is therefore impossible to deduce the radius of convergence for a function by looking at its graph. In the case of our example 1/(1 + x2 ), an interesting explanation as to why r = 1 can be based on the fact that x2 + 1 has a complex root at the point x = i, which a distance one from the origin. We will not pursue this approach here but let us say that this application of complex numbers turned out to be one the the great triumphs for this man-made invention. 7.8 Laboratory Exercises 1. Start by declaring f (x) to be a function, i.e., Author F(x):=. Use the Calculus/Taylor series menu to produce the expression TAYLOR( F(x), x, 0, 5) and then edit this expression by replacing the 5 with n (note that the Taylor menu requires integer values for the degree). With this last expression highlighted, use the Calculus/Vector menu twice, with the Variable set to n, Start value 4, End value 10 and Step size 1 to produce the two expressions: VECTOR(TAYLOR( F(x), x, 0, n), n, 4, 10, 1) VECTOR([n, TAYLOR( F(x), x, 0, n)], n, 4, 10, 1) For each of the functions below do the following: (i) Define f (x) to be the given function and plot its graph in the color red. (ii) Simplify the first vector function above to make a 7–vector which has the degree n Taylor polynomial, expanded about x = 0, for n = 4, . . . , 10 as its entries. (iii) Graph this vector to plot each of these Taylor polynomial in succession. It is probably best to plot the first 2-3 polynomials individually first and then the entire vector so that you can see how 7.8. LABORATORY EXERCISES 125 their graphs are getting closer and closer to the graph of f (x). You might need to scale your pictures appropriately. (iv) Simplify the second vector function to make a 7 × 2–table that has the degrees n in the first column and Pn (x) in the second column. (v) Use your table to guess what the infinite Taylor series expansion is. *(vi) Prove that in each case, the Taylor series expansion converges to the function and determine the interval of x’s for which it is valid. In parts (b), (c) use the geometric series (2) on page 132 and the fact that the series converges only for −1 < x < 1. x2 x8 +···+ +x 8 2 1 b. f (x) = 3−x 1 (Hint: For the pattern recognition you will need c. f (x) = 2 x +2 to change the output mode to Rational. Use the Declare/Algebra state menu to access the Output menu.) a. f (x) = 2. Let f (x) = − ln(1 − x). We want to determine the Taylor series for f (x) and prove that it converges to f (x) using Theorem 1 on page 115. a. Compute the first several derivative of f (x) and guess at a general formula for f (n) (x) for all n = 0, 1, 2, . . . . b. Use part a to establish the Taylor series of f (x) and hence if the Taylor series converges to f (x) we would have: (19) ln 1 1−x = ∞ X xk k=1 k =x+ x2 x3 + + ... 2 3 c. Use Theorem 1 to show that the (1) holds for any −1 ≤ x ≤ 1/2. (Hint: Carefully compute the right-hand side of (11) on page 115. Then, show that the error estimate tends to zero as n → ∞ only for −1 ≤ x ≤ 1/2.) CHAPTER 7. TAYLOR POLYNOMIALS 126 d. Show that taking x = −1 in (19) leads to another series representation of ln 2; namely, ln 2 ≈ 1 − 1 1 1 + · · · + (−1)n+1 2 3 n Analyze how quickly these approximates converge to ln 2 by making tables of numerical computations. What value of n is needed for 2-decimal place accuracy? e. It turns out that (19) actually holds for all −1 ≤ x < 1 and the radius of convergence is r = 1. By computing Pn (x) for several n and comparing their graphs with f (x), show that the Taylor polynomials seem to converge to f (x) on the full interval −1 ≤ x<1 3. For each of the functions below do the following: (i) Do parts (i)–(iv) of Problem 1 using these functions. (ii) By comparing the graph of the function with several Taylor polynomials make a guess at the interval of x’s for which the Taylor expansion is valid, see Section 7.7. (iii) Give further support for your answer in (ii) by picking some nonzero x1 (where the Taylor representation is valid) and numerically comparing the function’s value at x1 with that of several of its Taylor polynomials. Recall that tan−1 x is entered as atan x in Derive. a. 1 (x + 1)2 c. e−x b. tan−1 x 2 4. Load the file F-TAY3 and following the methods of Section 7.4 compute sin 7. Which degree Taylor polynomial should you use to get an error of less than 10−6 ? 5. In this problem we approximate e5 using the methods in Section 7.5. a. Express e5 using the Taylor series representation of the exponential function. 7.8. LABORATORY EXERCISES 127 b. Compare the numerical value of e5 using approximate with the value of the first several Taylor polynomials. How many terms appear to needed for 6 decimal place accuracy? c. We now want to use Theorem 1 on page 115 to obtain a precise estimate of e5 within 10−6. Compute an upper bound on the error estimate on the right-hand side of (11) for several n. Do this by first giving an upper estimate for M and then making a list of several error estimates until the value becomes less than 10−6 . d. What is your estimate for e5 and how many terms do you need? 6. The functions f (x) = sin x has only odd powers in its Taylor series expansion. This property can be explained by the fact that f (x) satisfies the equation f (−x) = −f (x) as do all odd powers of x. It is because of this that we call any such f (x) an odd function. Similarly, a function is an even function if f (−x) = f (x) holds for all x, as do all even powers of x. a. Prove that f (2k) (0) = 0 for k = 0, 1, . . . and any odd function f (x). b. Prove that f (2k+1) (0) = 0 for k = 0, 1, . . . and any even function f (x). *7. Recall from our discussion of complex numbers in Section 5.4 on page 78 that a complex number is of the form α = a + b i where a, b are real numbers and i satisfies i2 = −1. Our goal in this exercise is define the complex exponential eαx in such a way that the basic formula: (20) d αx e = αeαx dx is still valid. We will use Taylor polynomials as a guidepost to the correct definition. a. Find the 6th degree Taylor polynomial P6 (x) for the function eαx (enter the α symbol using the symbol bar). Be sure to expand out your answer into powers of x. CHAPTER 7. TAYLOR POLYNOMIALS 128 b. Substitute i for α into P6 (x) (Recall that i is entered in DfW using the symbol bar). Compute the real and imaginary parts of the resulting expression using the Derive functions RE(...) and IM(...). c. Now find the 6th Taylor polynomial for cos x and for sin x. Verify that that 6th Taylor polynomial for cos x is the same as the real part of P6 (x) above and the 6th Taylor polynomial for sin x is the same as the imaginary part of P6 (x). (Hint: The verification for the Taylor polynomial for sin x is a little tricky. Try expanding out the imaginary part of P6 (x) using the Simplify/Expand menu. d. Another way of obtaining the previous result is to multiply the Taylor polynomial for sin x by i and add it to the Taylor polynomial for cos x and compare the result with the Taylor polynomial P6 (x) above. Verify that these expressions are the same. e. These computations suggest that we define the complex exponential eix by the formula (21) eix = cos x + i sin x . In fact, this is the Euler Formula which is one of the most fundamental equations with complex numbers. Verify that using this definition, (20) with α = i is valid. f. Lastly, use the definition (22) eαx = e(a+b i)x = eax eibx = eax (cos bx + i sin bx) to verify (20) for general complex α. Do this by entering the right hand side of the above definition and computing its derivative. Then, author the expression obtained by subtracting from your derivative computation a + b i times the right hand side above. Now simplify and if you have done everything correctly Derive should returns the answer zero. g. Use the above definition to show that the complex conjugate satisfies: eix = e−ix and eαx = eᾱx (Recall that in Derive the ᾱ is entered as CONJ(α).) 7.8. LABORATORY EXERCISES 129 *8. In this problem we use the Taylor polynomials for the arc tangent function tan−1 x to estimate π. Recall that tan−1 x is entered as atan x. a. Use Derive to verify the formula π = 4 tan−1 (1/5) − tan−1 (1/239) 4 b. Compute the eighth degree Taylor polynomial P8 (x) for tan−1 x. c. Use P8 (x) to approximate on the right side of the above formula and use your answer to estimate π. d. Let M be the maximum value of the 9th derivative of tan−1 (x) on the interval [0, 1/5]. Use the error estimate (11) on page 115 to give an upper bound for the error in your estimate of π in terms of M. For example, give an answer like M · 10−2 . e. Use graphical techniques to give an upper bound on M. f. Combine the last two parts to give an estimate on the number of decimal places your estimate to π valid for. How does this compare with Derive approximation to π? g. Use Derive to show that the absolute maximum value for |f (9) (x)|, where f (x) = tan−1 (x), is achieved at x = 0. 130 CHAPTER 7. TAYLOR POLYNOMIALS Chapter 8 Series 8.1 Introduction An infinite series is a sum with infinitely many terms: ∞ X We define P∞ i=0 ai = a0 + a1 + a2 + · · · i=0 ai = s to mean that lim n→∞ n X ai = s, i=0 if this limit exists. If the limit does exist we say the series converges; otherwise we say it diverges. There are two basic techniques for showing that a series is convergent. One method is to show directly that the above limit exists. There are not many examples when we can do this but a particularly important one is geometric series which will be discussed in the next section. The second method for showing convergence applies to series with nonnegative terms, i.e., the case that ai ≥ 0 for all i = 1, 2, . . . . In this case the partial sums, sn = a0 + a1 + · · · + an = n X ai , n = 0, 1, . . . i=0 form an increasing sequence, s0 ≤ s1 ≤ s2 ≤ . . . . Hence, by a fundamental property of real numbers, the limit limn→∞ sn exists if and only if the 131 CHAPTER 8. SERIES 132 sequence {sn } is bounded. This second technique is used extensively for proving convergence and obtaining estimates on the answer. Particular examples are the ratio test and the integral test which we will discuss in this chapter. 8.2 Geometric Series A geometric series is one P in iwhich the ratio of consecutive terms Pnis constant, i.e., series of the form ax . To evaluate this series let sn = i=0 xi = 1 + 2 n x + x + · · · + x . Then sn − xsn = (1 + x + x2 + · · · + xn ) − (x + x2 + · · · + xn + xn+1 ) = 1 − xn+1 Factoring out sn and solving, we get (1) sn = n X xi = 1 + x + x2 + · · · + xn = i=0 1 − xn+1 , 1−x if x 6= 1 It’s instructive to verify this formula in DfW. You start by clicking the sum button and enter x^k. Make sure the variable is k (not x) and set the Start value to 0 and the End value to n. Click OK and edit the resulting expression SUM( x^k, k, 0, n) by multiplying it by the factor (1 − x). Lastly, use Simplify/Expand to get the desired 1 − xn+1 . If |x| < 1, then limn→∞ xn+1 = 0. Thus, we get that limn→∞ sn exists and so the series is convergent. In addition, the following simple formula for evaluating geometric series holds: (2) ∞ X i=0 axi = a + ax + ax2 + · · · = a , 1−x if |x| < 1 If |x| ≥ 1 then the series diverges because limn→∞ sn does not exist. We can verify this formula in Derive by entering, as we did above or directly, the expression SUM( ax^k, k, 0, inf) which displays as the left hand side of (2). Now we must declare that −1 < x < 1. We do this using 8.3. APPLICATIONS 133 the Declare/Variable Domain menu for the variable x and the open interval (−1, 1). If you do this right the expression x :∈ Real (-1,1) will be the result. If not you should be able to edit the expression until it is right. Finally simplify the infinite series to get a/(1 − x) which is the desired result. 8.3 Applications Geometric series are useful in several areas, for example, business and finance. We will give some of the important examples. Interest. If you start with p dollars (p for principal ) in a bank account which earns 6% per year how much money will you have after n years? Assuming the interest is compounded yearly, you will be given an interest payment of 0.06 p after one year. You will still have the original p dollars so that the amount of money in the account after one year will be p(1.06). Notice that this is saying that each year the amount of money in the account gets multiplied by 1.06. Thus after n years the account will have p(1.06)n dollars. If we let r denote the interest rate, the amount after n years is p(1 + r)n . An interesting alternative to this formula is obtained by focusing on the year to year change in the savings account balance. Let s bal(k,p,r) denote the balance after k years, starting with an amount p which is compounded annually at a rate r. This function can be defined in DfW by s bal(k,p,r):=IF(k=0,p,(1+r)*s bal(k-1,p,r)). Notice how we use the function IF(test,true,false). To compute say s bal(2,p,r) the first thing that happens is the test k = 0 fails and hence we get (1+r)*s bal(1,p,r). But then s bal(1,p,r) is computed in a similar manner, i.e., the test k = 0 fails again so now s bal(2,p,r)=(1+r)*s bal(1,p,r)=(1+r)*((1+r)*s bal(0,p,r)). Finally, s bal(0,p,r) is evaluated but this time the test k = 0 succeeds and so the answer is p. Combining the answers we get the same result as before (1 + r)2 p. This type of computation has a fancy name; it’s called recursive programming and it is particularly useful in situations where you have a sequence of numbers which change one to the next by a fixed rule. CHAPTER 8. SERIES 134 Now suppose that the bank compounds your money quarterly instead of annually. This means that they give you 6/4 = 1.5% interest four times a year. So the amount of money in your account after n years is p(1.015)4n . For a general rate r compounded k times a year, the amount of money after n years is (3) p 1+ r kn k This can be also be expressed as s bal(kn,p,r/k). Now suppose that you deposit a dollars each year into a bank account paying a rate r in interest, compounded annually. Suppose that you opened the account with an amount p dollars. How much money will the account have after n years? This is easy to do using a small modification in the s bal function as follows: s bal(k,p,r,a):=IF(k=0,p,(1+r)*s bal(k-1,p,r,a)+a). In other words we need only account for the extra a dollars which are deposited each year. We can get a nice table of values by numerically approximating VECTOR([k,s bal(k,1000,.06,100)], k, 0, 10) to see how an initial balance of $1000 will grow over a ten year period, at 6% annual interest, if we add an extra $100 each year. Now if you make the same table as above using the symbolic values for p, r and a you get a sequence of expressions which don’t appear to follow any clear pattern. On the other hand, if we substitute r1 = 1 + r everything is much clearer. In DfW you would declare a variable r1 and use r1-1 as a replacement for r, then the table obtained by entering VECTOR([k,s bal(k,p,r1-1,a)], k, 0, 10) and pressing presents the following pattern for s bal(k,p,r,a): a(r1k−1 + r1k−2 + · · · + r1 + 1) + pr1k r1k − 1 + pr1k r1 − 1 (1 + r)k − 1 + p(1 + r)k =a r =a 8.3. APPLICATIONS 135 Here we used (1) with x = r1 = 1 + r. Thus, the geometric series arises naturally in compound interest problems and provides us with a useful formula. Loan repayment. Suppose we borrow p at an annual rate of R. We are to pay this loan back by paying a monthly amount of a dollars for n years. R . Thus, at the end of the first month we Now the monthly interest is r = 12 owe the p dollars plus the interest it would have earned, rp, for a total of (1 + r)p. We also make a payment of a dollars so the net amount we owe is (1 + r)p − A. The same computation is used month after month except that the p is replaced with the loan balance for the previous month. Hence, if let l bal(k,p,r,a) denote the loan balance after k months on a loan amount of p dollars at a monthly interest rate r and monthly payment a then l bal(k,p,r,a):=IF(k=0,p,(1+r)*l bal(k-1,p,r,a)-a). which is very similar to our definition for s bal. Now suppose we are interested in a loan of $20,000 at a monthly interest rate of r = 0.01. The problem is to compute the monthly payment a which will result in paying off the loan in four years. We can display a four year history of the loan in a table when the payments are a = $500 by first authoring the vector [k, l bal(k,20000,0.01,500)] and then using the Calculus/Vector menu to produce the expression VECTOR([k, l bal(k,20000,0.01,500)], k, 0, 48, 1). We see that after 4 year (so k = 48 payments) we still have an outstanding balance of $1633.21 (of course, we could also discover this by just simplifying l bal(48,20000,0.01,500)). This means that $500 per month is not enough to pay off the loan in 4 years. At this point we could try increasing the payment a and then computing bal(48,20000,0.01,a) until we get nearly zero. We might start by incrementing a by $10 until we get the answer within $10 and then increment by a dollar until we get the answer within a dollar. For repeated computations this would be a rather tedious approach. By comparing with the formula derived for s bal using the geometric CHAPTER 8. SERIES 136 series we get a similar formula for l bal(k,p,r,a), namely, (1 + r) p − a k k−1 X (1 + r)i = (1 + r)k p − a 1 − (1 + r)k 1 − (1 + r) = (1 + r)k p − a (1 + r)k − 1 r i=0 (4) Using this formula we can easily get the general formula for a by solving l bal(k,p,r,a) = 0 for a. Thus, the monthly payments a on a loan of p dollars at a monthly interest rate r (divide the annual rate by 12) for a period of n years (so k = 12n payments) is: (5) a= r(1 + r)k p (1 + r)k − 1 where k = 12n. Thus, in our $20,000 example you need a = $526.68, i.e., bal(48,20000,0.01,526.68) = 0. Repeating Decimals. What exactly is meant by the decimal representation of a number x = 0.d1 d2 d3 · · · , where each of the digits dk are integers 0 ≤ dk ≤ 9? One explanation is that there is no difficulty as long as it is a d2 d1 d1 + , etc. For the infinite case, finite decimal, i.e., 0.d1 = , 0.d1 d2 = 10 10 100 we can think of our decimal as the limit of an increasing sequence which is bounded from above: 0.d1 ≤ 0.d1 d2 ≤ 0.d1 d2 d3 ≤ · · · ≤ 1 . and hence this sequence has a limit, as mentioned above. Another approach is to view the decimal as an infinite series as follows: X dk d2 d1 d3 + 2 + 3 +··· = x = 0.d1 d2 · · · = 10 10 10 10k ∞ (6) k=1 Now clearly, the partial sums form an increasing sequence since the terms are nonnegative numbers. However, maybe it is not completely obvious that 8.4. APPROXIMATING INFINITE SERIES 137 they are bounded by 1! Here’s a proof: d2 9 dn 9 9 d1 + 2 +···+ n ≤ + 2 +···+ n 10 10 10 10 10 10 9 1 9 1 9 9 1 + = + ···+ 10 10 10 10 102 10 10n−1 9 9 1 9 1 9 10 + ≤ + + · · · = 1 = 1. 10 10 10 10 102 1 − 10 Note P∞ that thek key step above was recognizing that the geometric series k=0 a(1/10) , where a = 9/10, sums to 1 by (2) on page 132. Of course, we also notice that repeating decimals like 0.999 · · · = 1 and 0.333 · · · = 1/3 are all geometric series when represented as above. Try to figure out the a, x in (2) in each case. This turns out to be true of any repeating decimal and hence by the formula (2) these decimal numbers must be fractions a/b where a, b are integers. In fact, the converse is also true, namely, a decimal is a fraction if and only if it is eventually repeating. Example. Consider the eventually repeating decimal x = 0.5010101 · · · . We express this as k 1 1 1 X −3 5 + 3 + 5 +··· = + 10−2 10 x= 10 10 10 2 ∞ k=0 10−3 1 248 1 1 + = . = + = 2 1 − 10−2 2 990 495 We might notice that it is not possible to enter x in Derive as a decimal but we can define it by means of the infinite series above. Then, simplifying we get the above result. 8.4 Approximating Infinite Series We can determine the sum of a geometric series exactly but for mostPconvergent infinite series this is impossible. If the series converges to s = ∞ k=0 ak , then by P definition s can be approximated arbitrarily closely by the partial sums nk=0 ak for large enough n. In this section we investigate two methods for approximating infinite series, with a given precision. CHAPTER 8. SERIES 138 The Ratio Test. In a convergent geometric series, ak = axk , and hence ak+1 = ak x, i.e., the ratio of consecutive terms is x, where |x| < 1. In this section we consider positive series (ak > 0) where the the ratio of consecutive is approximately equal to some x with 0 < x < 1. It will turn out that all such series converge and that we can estimate their size by comparisons with appropriate geometric series. This technique is called the ratio test. Theorem 1. Let ai be positive. (a) If limi→∞ ai+1 /ai = λ < 1, then the series P ai converges. (b) Suppose that 0 < x < 1 and that for some n, ai+1 /ai ≤ x for all i > n. Then ∞ X 0≤ (7) ai − i=1 n X i=1 ai ≤ an+1 1−x Proof. If limi→∞ ai+1 /ai = λ < 1, then for any x satisfying λ < x < 1, we know that the ratios will be less than x for all large i. Thus, given x there is an n for which ai+1 ≤ xai whenever i > n. So an+2 ≤ xan+1 and an+3 ≤ xan+2 ≤ x2 an+1 . In general, an+1+k ≤ xk an+1 and hence for all m > n 0≤ m X i=1 ai − n X ai = an+1 + an+2 + · · · + am i=1 ≤ an+1 (1 + x + x2 + · · · ) = an+1 . 1−x Thus, the partial sums {sm } are bounded and the series is convergent. Moreover, the inequality (7) follows by taking limits as m → ∞. Example. Suppose we want to use Theorem 1 to prove that the series ∞ X 2k k=0 k! = 1 2 4 + + + ... 1 1 2 converges and estimate its value with an error of at most 10−6 . The first step is to show that limk→∞ ak+1 /ai < 1. We think of the terms as a 8.4. APPROXIMATING INFINITE SERIES 139 function of k by authoring term(k):=2^k/k!. Now simplifying the ratio term(k+1)/term(k) we see that 1 2 ak+1 ≤ = ak k+1 2 for all k > 2. Thus, limk→∞ ak+1 /ak = limk→∞ 2/(k + 1) = 0 < 1 so the series converges and furthermore we can take x = 1/2 and n = 2 in Theorem 1(b). Now we must determine n so that an+1 = 2an+1 < 10−6 . 1−x We do this by authoring VECTOR([n,2*term(n+1)],n,2,20) , approximating the result and then searching the entries (by scrolling) until we find one smaller than 10−6 . It P turns out n = 13 works. The last step is k to compute the partial sum s13 = 13 k=0 2 /k! giving 7.38905. We might observe how fortunate we were that k turned out to be so small. Recall some of our computations using the trapezoid method or Simpson’s rule where similar accuracy required thousands or even millions of computations (using the left endpoint method, for example). It is one of the fundamental properties of geometric series that they converge very rapidly. Think about it, 6–decimal place accuracy with just 15 computations! As it turns out this series is rather special since ∞ X 2k k=0 k! = e2 = 7.38905 · · · This important fact is explained in Chapter 7 equation 8. If this fact is new to you then just try authoring the above infinite series and have Derive simplify the result. What if the 2 is replaced with 3 or x? ∗ Example . Now consider the harder problem of approximating ∞ X k! kk k=1 140 CHAPTER 8. SERIES with error again of at most 10−6. Proceeding as before we author the formula term(k):=k!/k^k. Now by first simplifying and then taking limits we see that 1 1 ak+1 kk = lim = < lim k k→∞ ak k→∞ (k + 1) e 2 since e > 2. Thus, the limit is less than 1 so the series converges. Furthermore, we can take x = 1/2 in Theorem 1(b). But now we need to find an integer n so that ak+1 /ak = k k /(1 + k)k < 1/2 for all k > n. This step is harder than before. If we graph f (x) = (x/(x+1))x it appears to be decreasing for all x ≥ 0. See Figure 8.1. Figure 8.1: Ratio test example In order to prove that f (x) is a decreasing function we differentiate and show that f 0 (x) < 0. Using Derive we get xx [(x + 1) ln(x + 1) − (x + 1) ln x − 1] f 0 (x) = − (x + 1)x+1 1 xx ln(x + 1) − ln x − =− (x + 1)x x+1 8.4. APPROXIMATING INFINITE SERIES 141 after some rearrangement (see the file F-RATIO for the step-by-step procedure). Since xx /(x + 1)x is positive for x > 0, we need to show that ln(x + 1) − ln x − 1/(x + 1) is positive. At this point Derive can’t help so we need an idea from calculus. One quick way to solve this problem is to use the Mean Value Theorem for the function g(x) = ln x. The Mean Value Theorem says: g(b) − g(a) = g 0(c)(b − a) for some a < c < b. For a = x and b = x + 1 this gives ln(x + 1) − ln x = 1/c for some x < c < x + 1. Thus ln(x + 1) − ln x − 1 1 1 = − >0 x+1 c x+1 where we obtain the desired inequality since c < x + 1. Thus, f 0 (x) < 0 for all x > 0 and so f is decreasing. Now that we have established that the ratios decrease we need to know when they are less than 1/2. Since kk 1 ak+1 = = f (k) ≤ f (1) = . k ak (k + 1) 2 for all k ≥ 1, it follows that we may apply the theorem for any n. Finally, by (7), we must determine n so that an+1 −6 . 1 = 2an+1 < 10 1− 2 As before we author VECTOR([n,2*term(n+1)],n,2,20) , approximate the result and then search the entries until we find one smaller than 10−6 . It turns out in this case that k = 16. Computing the partial sum s15 gives 1.87985. P Now suppose that your series ak satisfies lim ak+1 /ak = λ but that λ ≥ 1. The case λ > 1 is pretty much like the case λ < 1 except that now the series diverges. The idea is to pick 1 < x < λ and observe that ∞ = an + an x + an x2 · · · ≤ an + an+1 + an+2 + . . . for some large n since now ak+1 /ak ≥ x for all k ≥ n. The case λ = 1 is much harder since, as we see in the next section, there are examples in which the series converges and examples where it diverges. CHAPTER 8. SERIES 142 The Integral Test Suppose that f (x) is a decreasing positive P valued func∞ tion, for x ≥ 1. Let an = f (n). We want to approximate i=1 ai and determine whether the series is convergent or divergent. In Section 6.4 we saw that, for a decreasing function like f (x), the left endpoint method of estimating a definite integral of f (x) always overestimates the integral while the right endpoint method underestimates it. This is quite obvious by looking at Figure 8.2 on the next page where we use f (x) = 1/x as our function and apply the box drawing function from Chapter 6; see the file F-SERINT for a demonstration. Now, we observe that since the interval size is one, the area of the box with height f (n) is just an . From this wePget that adding the area of boxes corresponds to partials sums of the series ak . Thus, for any 1 ≤ n ≤ m Z m+1 X (8) m ai ≤ f (x) dx ≤ n i=n+1 m X ai i=n The sum on the left is the right endpoint estimate and the sum on the right is the left endpoint estimate, when we use ∆x = 1 as the subinterval size. From this inequality, we obtain the following theorem: Theorem 2. Suppose that f (x) is a continuous, nonnegative, decreasing function for x ≥ 1. Put an = f (n). P∞ (a) The infinite series i=1 ai converges if and only if the improper integral R∞ f (x) dx does. 1 (b) Moreover, the inequality (9) n X i=1 ai ≤ n X Z ∞ ai + ∞ X f (x) dx ≤ n+1 i=1 i=1 ai ≤ n X Z ∞ ai + f (x) dx n i=1 holds for all n = 1, 2, . . . . (c) The value of the series can be estimated using the following: (10) 0≤ ∞ X i=1 ai − n X i=1 Z ∞ ai + ! f (x) dx n+1 ≤ an 8.4. APPROXIMATING INFINITE SERIES 143 Figure 8.2: The geometric estimate used in the integral test R∞ Proof. Suppose that the improper integral 1 f (x) dx is convergent so that the total area under the curve is finite. From (8) it follows that Z m Z ∞ m+1 X ai ≤ f (x) dx ≤ f (x) dx < ∞ n i=n+1 n and hence the partial sums {sm } are bounded (the first n terms are irrelevant). Thus, the series converges and the second inequality in (9) follows from Z ∞ ∞ n ∞ n X X X X ai = ai + ai ≤ ai + f (x) dx . i=1 i=1 i=n+1 i=1 n A similar argument shows that the integral is convergent if the series is and that the first inequality in (9) holds. The first inequality in (10) is an immediate consequence of R(9) and simin+1 larly it follows that the middle expression in (10) is bounded by n f (x) dx. But since f (x) is decreasing this integral is less than or equal to f (n) = an and the theorem is proved. CHAPTER 8. SERIES 144 We note that (9) actually gives P∞ us two methods for approximating the sum of a convergent series s = k=1 ak . The first technique looks more like the one used in the ratio test: Z ∞ ∞ n X X ai − ai ≤ f (x) dx 0 ≤ s − sn = i=1 i=1 n and the second one is the more refined estimate (10) which uses the quantity n X i=1 Z ∞ ai + f (x) dx n+1 to approximate s instead of the partial sum sn . As we shall see in the examples, this more refined method has a dramatic computational advantage. A curious formula. As our first application of the integral test let us prove that the series ∞ X 1 1 1 = 1 + 2 + 2 + ... 2 k 2 3 k=1 is convergent. First note that λ = 1 in the ratio test so we cannot use that approach. Next, we take f (x) = 1/x2 and observe (say using Derive) that Z n n 1 1 dx =− = 1 − → 1 as n → ∞ 2 x 1 n 1 x R∞ and hence the P improper integral 1 dx/x2 is convergent. Now, by the integral is the series is convergent. Actually, a similar test the series 1/i2 < P∞, that p argument shows that 1/i < ∞ whenever p > 1. Now it is a remarkable fact that (11) ∞ X π2 1 1 1 + + · · · = . = 1 + 2 i 4 9 6 i=1 You have to wonder how the π–term can possibly be involved in this computation. The proof of this fact is beyond the scope of this text but Derive can help us believe this result. One way to do this is to have Derive simplify the series and get π 2 /6 as the answer. It works, try it. A more independent 8.4. APPROXIMATING INFINITE SERIES 145 approach would be to compute the partial sums sn for several n and compare with a decimal approximation to π 2 /6. In Figure 8.3 on the following page we have Derive make these comparisons with n = 100, 1000, and 10,000. We also observe that Derive knows about (11) and simplifies the series accordingly. Problem: Compute this series to m decimal places. We solve this problem by using (10) which in this case says: ! ∞ n X X 1 1 1 1 ≤ 2. (12) − + 0≤ 2 2 i i n+1 n i=1 i=1 Thus, to solve our problem we need only find n so that right-hand side of (12) is less than 10−m , and then use n X 1 1 1 1 1 1 = 1+ + +···+ 2 + + 2 i n+1 4 9 n n+1 i=1 for our estimate. For example, with m = 6 we need to take n2 > 10m or n > 1000. Something rather amazing occurred in this problem. In Figure 8.3 on the next page we used the partial sums {sn } to approximate the sum s. This is the natural thing to do since s = lim sn . But the accuracy in Figure 8.3 is only 3 or 4 decimal places with n = 1000. This error is to expected since (8) yields Z ∞ ∞ X 1 1 dx ≤ = 0 ≤ s − sn = i2 x2 n n i=n+1 and the right-hand side is just less than 10−3 . On the other hand, adding the term 1/(n + 1) (which is the integral in (10)) increases the accuracy to 1/n2 = 10−6. This accuracy is 1000 times better than the other estimate. Put another way, suppose for example that both computations take about 3 seconds with n = 1000 on your PC, the amount of computation time needed to produce 6 decimal place accuracy using the less efficient method is almost an hour! See the file F-2-SER which contains a comparison of these methods. This problem illustrates the potential value of a innovative approach to a computation compared to the conventional solution. CHAPTER 8. SERIES 146 Figure 8.3: Summing the series P 1/i2 The Harmonic Series Let us apply the integral test to the harmonic series, namely, ∞ X 1 1 1 = 1 + + + ... i 2 3 i=1 We take f (x) = 1/x in the theorem and observe that Z x 1 dt = ln x → ∞ t as x→∞ and hence the integral is divergent. Thus, the series is divergent. Another P 1 = +∞ or in other words, the partials sums way to express this is that ∞ i=1 i are eventually larger than any given number. Consider this: How many terms of the harmonic series are necessary before the partial sums exceed 100? Is the answer 1000? 1,000,000? 1010 ? Amazingly, none of these answers are even close to the actual result. Suppose 8.5. LABORATORY EXERCISES 147 that 100 < ln n, then by (8) Z n 100 < ln n = 1 dt X 1 ≤ t i 1 n so that any n > e100 ≈ 2.6 × 1043 is certainly large enough. On the other hand, using (8) again we have 100 ≤ n X 1 1 i =1+ n X 1 2 i Z ≤1+ 1 n−1 dt < 1 + ln n t so that when combined with the above we see that the best n satisfies: e99 < n < e100 . 8.5 Laboratory Exercises For these problems it is a good idea to have more digits of precision: choose Declare/Algebraic State/Simplification and the Digits box to 10 or 12. 1. Formula (3) on page 134 shows the amount of money in an account after n years if the interest rate is r, the original amount is A, and the interest is compounded k times a year. In Problem 1 on page 191 you showed that if interest is compounded continuously, the amount of money would be Aern . a. Show that the limit as k → ∞ of compounding k times a year is the same as compounding continuously. b. If you put $1000.00 into an account earning 4.5% interest, how much money will be in the account after one year if the interest is compounded yearly? quarterly? daily? continuously? c. Do the previous part only assume that the bank is paying 9%. 2. Suppose you get a 30 year mortgage loan for $200, 000 which is to be repaid in 30 · 12 equal monthly payments, based on an annual interest rate of 7.5%. a. Find your monthly payment. CHAPTER 8. SERIES 148 b. How much do you still owe after your first payment? How much of your first year’s payment went to interest and how much went to paying off the principal? c. Formula (4) gives the amount you still owe after k months. Replace the k with 12k in Formula (4) so that k now represents years, approximate the resulting expression and then plot. (You’ll need to adjust the range in such a way that the visible x-axis contains the range 0 to 30 and the y–axis contains the range 0 to 200, 000.) Notice that at the beginning the amount you owe changes slowly but that near the end of the 30 years it changes quickly. 3. In some problems involving monthly payments or interest the monthly interest rate is computed by dividing the annual rate by 12. But sometimes the monthly rate m is not specified and instead the effective annual rate r is given. This means that compounding the monthly rate m 12 times gives the annual rate r, i.e. (1 + m)12 = 1 + r. Consider the previous problem but now suppose that the effective annual rate is 7.5%. a. Calculate the monthly rate for this problem. b. Find the monthly mortgage payments using this new rate. 4. The bank says that it will give you a car loan of $6,000 provided you make monthly payments of $135 for 5 years. What interest rate is the bank charging? (Hint: You may need to be a little careful how you compute this.) 5. Consider the fraction 1/7. a. Using Derive show that 1/7 appears to have a repeating decimal expansion. What is it? b. Express this repeating decimal from part a as an infinite series, see the example on page 137. c. Have Derive simplify this series. d. Identify the a and x terms from (2) and verify using that formula that your infinite series simplifies to 1/7. 8.5. LABORATORY EXERCISES 149 P 2 6. Have Derive evaluate the sum ∞ n=1 1/n . (Make sure you use Exact mode.) Evaluate the left and right sides of formula (9) in Theorem 2 for n = 1000. You should approximate the sum rather than Simplify, otherwise the computation time is fairly long. Use these to estimate π giving upper and lower bounds. P 7. For each of the following series ∞ k=0 ak find λ = limi→∞ ak+1 /ak and show that λ < 1/2. Now Pn use Theorem 1(b) with x = 1/2 to find n large enough so that k=0 ak approximates the series with error at −6 most 10 . a. ∞ X k3 k=0 b. 4k ∞ X (k!)2 (2k)! k=0 8. Use Theorem 2(c) to evaluate each of the following series with an error of at most 10−6 . (The finite sum of Theorem 2(c) should be Approximated but the improper integral should be evaluated exactly.) a. ∞ X k=2 c. ∞ X k=1 1 k(ln k)2 b. ∞ X 1 k3 k=1 1 1 + k2 9. Some of the following series converge and some diverge. Decide which do which and state the required Theorem needed to prove your conclusion. a. c. ∞ X 2k b. ∞ X 1 k ln k k=0 k=2 ∞ X 1 ek k=0 ∞ X 2 · 4 · · · 2k 10. Consider the series d. k=1 P∞ k=0 (2k)! 1/k!. a. Show that the series converges by the ratio test. CHAPTER 8. SERIES 150 b. Have Derive simplify this series. c. Use these results to approximate the Euler constant e with an accuracy of 10−6 *11. The following formula (13) 1+2 ∞ X −k 2 /t e = √ tπ 1+2 k=1 ∞ X ! −k 2 π 2 t e k=1 is known to hold for all t > 0. The formula is derived from an important technique in the theory of Fourier transforms called Poisson summation. We will not attempt to prove this formula but instead try to use it as a method of approximating π more efficiently than in an earlier problem. It has a number of other useful applications too. We will fix the value of t = 2 for the rest of this problem. a. Using the ratio test, show that both infinite series in (13) are convergent. P 2 −2k 2 π 2 that ∞ b. Use Theorem 1 with x = e−6π and n = 1 to show k=1 e √ is less than 10−8 . Thus, with an accuracy of 2 2π10−8 or roughly 7 decimal √ places we can take the right hand side of equation (13) to be 2π. c. Using Theorem 1 again, show that ! ∞ X 2 e−k /2 − 0< 1+2 1+2 k=1 =2 ∞ X e−k 2 /2 6 X ! e−k 2 /2 k=1 < 10−10 k=7 and hence 1 π≈ 2 1+2 6 X !2 −k 2 /2 e . k=1 d. Approximate the above expression using Simplify/Approximate with the number of precision digits set to 10. Compare the above approximation of π with Derive’s. What is the decimal place accuracy? 8.5. LABORATORY EXERCISES 151 e. To achieve more decimal places you should increase the value of t. Show that with t = 10, the analogous estimate in part b is ∞ X e−10k 2 π2 < 10−42 k=1 (This problem is essentially due to George Csordas.) 152 CHAPTER 8. SERIES Chapter 9 Approximating Integrals with Taylor Polynomials 9.1 Introduction In Chapter 6R we developed several techniques for approximating a definite b integral I = 0 f (x) dx by applying the trapezoid method or Simpson’s rule. In the last chapter we saw that many of the important functions in Calculus can be represented by a Taylor series and hence can be approximated by their Taylor polynomials. This suggest another approach to approximating I; namely, approximate the integrand f (x) by its Taylor polynomials and then use Z Z b b f (x) dx ≈ 0 Pn (x) dx = 0 Z bX n 0 k ak x dx = k=0 n X k=0 ak bk+1 k+1 where ak = f (k) (0)/k! to obtain the desired estimate. The advantage to this approach was strongly suggested by Problem 3 on page 159. In that problem it was shown that approximating ln 3 using Taylor series techniques gave 8–decimal place accuracy with approximately 8 computations. Whereas the standard approach using Simpson’s rule require approximately 100 computations. 153 CHAPTER 9. APPROXIMATING INTEGRALS 154 9.2 The Basic Error Estimate P Recall from (11) of Chapter 7 on page 115 that if nk=0 ak xk is the nth Taylor polynomial for f (x), then an upper bound for the error made in estimating f (x) with this Taylor polynomial is given by f (x) − (1) n X ak xk ≤ M k=0 |x|n+1 (n + 1)! where M is the maximum of |f (n+1) (t)| on the interval connecting 0 to x. This can be written as X |x|n+1 |x|n+1 −M ≤ f (x) − ak xk ≤ M (n + 1)! (n + 1)! k=0 n (2) If we integrate this from 0 to b, we get Z b n X |b|n+2 |b|n+2 ak k+1 (3) ≤ b −M f (x) dx − ≤M (n + 2)! k+1 (n + 2)! 0 k=0 Writing this with absolute values: Z b (4) 0 n X |b|n+2 ak k+1 ≤M b f (x) dx − k+1 (n + 2)! k=0 This technique works for integrals going from 0 to b. If you want to Rb approximate a f (x) dx, you can make the substitution u = x − a so the R b−a integral becomes 0 f (u) du. 9.3 The Logarithm Series 1 where we shift the variable 1−x so that x = 0 yields ln 1 = 0. First of all, we have the integral representation: Z x 1 dt = for −∞ < x < 1. ln 1−x 0 1−t Consider the logarithm function f (x) = ln which can be easily checked using Derive. 9.3. THE LOGARITHM SERIES 155 Now, the idea is to approximate the integrand by its Taylor series but in this case we recognize the connection with the geometric series; namely, ∞ X tk = k=0 1 1−t for −1 < x < 1. We’ll actually use the following more refined estimate from Section 8.2: (5) n ∞ X X tn+1 1 − tk = tk = tn+1 + tn+2 + · · · = 1 − t k=0 1−t k=n+1 whenever |t| < 1. Now we integrate this equation from 0 to x, where we assume that −1 ≤ x < 1, to get ! Z x n n X X 1 xk+1 1 − = − (6) tk dt ln 1 − x k=0 k + 1 1 − t 0 k=0 Z x n+1 t (7) dt . = 0 1−t Taking absolute values of the above we need to evaluate the integral in (7). Since this looks complicated, we instead try to obtain an upper bound. For 1 1 ≤ 1−x to obtain that positive x, we uses the inequality 0 < 1−t Z x k+1 Z x n+1 xn+2 t t (8) dt ≤ dt = . (1 − x)(n + 2) 0 1−t 0 1−x 1 On the other hand, for negative x, we instead use 0 < 1−t ≤ 1 to get a similar bound: Z 0 k+1 Z 0 |x|n+2 t (9) dt ≤ . |t|n+1 dt = (n + 2) x 1−t x Hence, we have the desired approximation result because xn+2 = 0 whenever n→∞ (1 − x)(n + 2) 0≤x<1 |x|n+2 = 0 whenever n→∞ (n + 2) −1 ≤ x ≤ 0 lim and lim CHAPTER 9. APPROXIMATING INTEGRALS 156 One small point, the polynomial approximations in (6) look a little different from the standard Taylor polynomials because the powers are expressed with the index k + 1. This is just an artificial difference since Pn+1 (x) = n+1 j X x j=1 X xk+1 x2 xn+1 =x+ +···+ = j 2 n + 1 k=0 k + 1 n and hence we ultimately obtain that xn+1 (1 − x)(n + 1) , 0 ≤ x < 1; 1 ln (10) − Pn (x) ≤ 1−x |x|n+1 , −1 ≤ x ≤ 0 (n + 1) which tends to zero as n → ∞. This leads to the Taylor series representation X xj 1 ln = 1−x j j=1 ∞ (11) 9.4 for − 1 ≤ x < 1. An Integral Approximation Suppose we wanted to estimate the definite integral Z 1 sin x dx. x 0 At first glance there appears to be a problem at x = 0 because we are dividing by zero. However, L’Hospital rule shows that limx→0 sin x/x = 1. An interesting alternative way of proving this fact is use the Taylor series representation for the sin x, i.e. X (−1)k x3 x5 + −··· = x2k+1 sin x = x − 3! 5! (2k + 1)! k=0 ∞ for all −∞ < x < +∞. Now for x 6= 0 we can divide both sides by x to get x2 x4 sin x =1− + − ... . x 3! 5! 9.4. AN INTEGRAL APPROXIMATION 157 Formally then, the right-hand side above approaches 1 as x → 0 because all the xn –terms tend to zero. Of course, there is always the problem of making estimates for infinite series, as opposed to finite sums, which can be difficult. One way around this difficulty is use the approach we adopted for approximating sin x in Section 7.4. There we used Taylor’s Theorem with remainder to show that (−1)n x2n+1 |x2n+3 | x3 x5 (12) + −... ≤ sin x − x − 3! 5! (2n + 1)! (2n + 3)! for all n = 0, 1, . . . . For example, even taking n = 0 in the above yields a sin x − 1| ≤ x2 /6 → 0 as nice result; namely, | sin x − x| ≤ |x|3 /6. Hence, | x sin x = 1. x → 0 and thus limx→0 x Similarly, if we take a larger value of n, say n = 3, we get x3 x5 x7 |x9 | sin x − x − (13) + − ≤ 3! 5! 7! 9! and so dividing by x and integrating from 0 to 1 yields Z Z 1 0 1 = Z 0 1 = 0 3 X sin x 1 dx − x (2n + 1)(2n + 1)! n=0 1 1 1 sin x dx − 1 − + − x 3 · 3! 5 · 5! 7 · 7! ! Z 1 8 3 1 |x| sin x X (−1)n x2n − dx ≤ dx = . x (2n + 1)! 9! 9 · 9! 0 n=0 Finally, since 1/(9 · 9!) ≈ 3.0619 × 10−7 we get 6 decimal place accuracy by approximating the integral using 4 terms from the series. In Figure 9.1 on the next page we have Derive approximate our integral using 20 digit precision. This computation, which uses Simpson’s rule, is actually quite slow, Load the file F-SININT and try this yourself. On the other hand, we enter the partial sums of the series solution and make a table comparing the first several sums with the answer from Derive. Notice that the theoretical error that we calculated above is practically the same as the actual error when n = 3. CHAPTER 9. APPROXIMATING INTEGRALS 158 Figure 9.1: Using Taylor series to approximate integrals 9.5 Laboratory Exercises 1. Use (17) on page 121 and (11) on page 156 to prove that ∞ X x2k+1 1+x ln (14) =2 for − 1 < x < 1 1−x 2k + 1 k=0 2. Let f (x) = ln 1+x for −1 < x < 1. In this exercise we will use the 1−x representation (14) above to compute ln 3. a. Determine the value of x in the standard representation of the logarithm function (17) on page 121 that makes the left hand side of that relation equal to ln 3. Explain why the infinite series on the right hand side can not be used to compute ln 3. and show that y = g(x) is a strictly increasing b. Plot g(x) = 1+x 1−x function on −1 < x < 1 with range 0 < y < ∞. c. Solve 1+x 1−x = 3 for x. Let x3 be your answer. 9.5. LABORATORY EXERCISES 159 d. Using (14) above, we get an infinite series for ln 3 by substituting x = x3 into (14). Show that this infinite series converges by the ratio test on page 138. e. Compare the numerical values of Pn (x3 ) for various n with the approximate value of ln 3. 3. If we take x = 1/3 in (14) above we get Z 2 ∞ X dt 2 = ln 2 = . 2k+1 t (2k + 1)3 1 k=0 In Chapter 6 we studied numerical integration techniques for approximating the above integral with the most efficient method being Simpson’s rule. One the other hand, using the ratio test on page 138 we approximated the infinite series similar to the above. a. Using the error in Simpson’s rule, formula (5) on page 99, determine approximately how many subdivisions (and hence how many computations) are needed to obtain 8 decimal place accuracy. b. For completeness, also do part (a) using the left endpoint method and the trapezoid method. c. Show that the ratio of terms in the above series is less than 1/9. d. Using formula (7) of Theorem 1 on page 138 with x = 1/9, determine how many terms are needed to approximate ln 2 to 8 decimal places. e. Now compare all four approximation techniques. Which method is the most efficient? Z 4. Use the formula x dt 2 0 1+t and the techniques of this chapter to prove that the Taylor representation ∞ X x3 x5 (−1)k 2k+1 −1 x + − . . . for − 1 ≤ x ≤ 1 =x− tan x = 2k + 1 3 5 k=0 −1 tan x= holds. Look back at Problem 6 on page 129 and also Problem 3b. What are the implications of this problem to the earlier ones? 160 CHAPTER 9. APPROXIMATING INTEGRALS 5. In this problem you are to estimate Z 2 √ e x dx 0 using the method outlined in the text. a. Define and simplify P(x):= the 8th –degree Taylor polynomial for ex . √ b. Author P ( x) and integrate the result from 0 to 2. Simplify this integral and then express the answer as a decimal. c. Compute the√maximum value of the ninth derivative of ex on the interval 0 to 2. Denote this maximum by M. (Note: This is the M value associated with the Taylor polynomial √ p(x) in (11) on page 115 0 ≤ x ≤ 2. The reason √ corresponding to the interval √ we use √ 2 and√not 2 is that if √ |ex − p(x)| ≤ c for 0 ≤ x ≤ 2, √ then |e x − p( x)| ≤ c for 0 ≤ x ≤ 2, i.e., for 0 ≤ x ≤ 2.) d. In a manner similar to what was done in Section 9.4, find the error in the approximation you obtained in part b. R2 √ e. Have Derive evaluate 0 e x dx and then approximate it and compare the answer with what you obtained in part b. 6. Do parts a. to e. but this time for Z 1 2 e−x dx. 0 Instead of starting with the Taylor polynomial for ex , start with the Taylor polynomial of e−x . Chapter 10 Polar and Parametric Graphs 10.1 Introduction Graphs of the form y = f (x) or x = g(y) can be used to represent a wide variety of curves in the plane, there are many important curves, such as circles or ellipses, that cannot be represented by a single graph of this type. More generally, imagine the curve traced out by an ant walking on a flat surface. In this chapter we will introduce two techniques for plotting general curves. One is the method of polar coordinates, which is a coordinate system based on angles and distance from the origin. The other is the method of parametric representation, which allows one to specify completely arbitrary curves like the motion of a particles (or the ant). 10.2 Polar Coordinates We can specify a point in the plane by how far it is from the origin and what angle the line from the point to the origin makes with the x–axis. If r is the distance from the origin and θ is the angle, we say that [r, θ] are the polar coordinates of the point; see Figure 10.1 on the next page. Thus, for example, the √ point with rectangular coordinates (1, 1) would have polar coordinates [ 2, π/4]. The way to envision plotting a polar point [r, θ] is to stand at the origin facing out towards the positive x–axis and then turn counterclockwise by the angle θ and then move r unit in the direction you are now facing. We usually think of r as being nonnegative, but if r is negative, we simply go backwards |r| units. Similarly, we plot negative angles by turning 161 162 CHAPTER 10. POLAR AND PARAMETRIC GRAPHS [r, θ] r θ Figure 10.1: Polar Coordinates clockwise instead of counter-clockwise. This leads to a surprising difference compared to rectangular coordinates; namely, two different polar coordinates can represent the same point. Thus, [−2, π/4] = [2, 5π/4] = [2, −3π/4]. Note that [0, θ] is the origin regardless of what θ is. Your calculus text has a more detailed description of polar coordinates. A basic problem in polar graphing is to plot a function such as r = ρ(θ), i.e., plot all points [r, θ] where r is given by the function ρ(θ). For example the circle of radius a, centered at the origin, is the graph of r = a. Thus, ρ(θ) = a is a constant functions. Note that to draw this circle in rectangular √ coordinates√you must think of this curve as two graphs, namely, y = a2 − x2 and y = − a2 − x2 . This simple example already shows that some curves are more easily represented with polar coordinates. Let us now try something harder such as r = 1 + cos θ. One then graphs the curve by computing r for lots of θ’s by thinking about the geometry of the angle θ and the value of r. This is usually done with angles such as θ = 0, π/4, π/2, 3π/4 and π which corresponds to 45◦ increments in the angle. By authoring vector([1+cos θ, θ], θ, 0, π, π/4) and simplifying this expression gives a table of polar points which can be plotted by hand or as a set of points in Derive. We’ll need to plot more θ’s but this is a start. A nice technique for viewing the data is to use the APPROX function to get decimals for the r–values. We then get r as a decimal and θ expressed in the usual radian notation for the angles. See Figure 10.2 on the facing page. Derive can plot these points in polar coordinates by selecting the Option menu and then selecting the Polar option on the Coordinates menu. Then, plot the points just as we did in rectangular coordinates by highlighting the matrix of points and clicking the plot button in the graphics window. After plotting these 5 points we try to imagine the rest of the graph by interpolating 10.2. POLAR COORDINATES 163 Figure 10.2: Plotting points in polar coordinates other values of θ. Of course, Derive will plot the curve for us. We enter either 1 + cos t or just highlight expression #1 in Figure 10.2, then click the Plot button in the graphics window. So far, this is just like rectangular plots except for the change in the coordinate mode. But now Derive will prompt you for the parameter interval (interval of θ’s to use) and suggest the default range of −π ≤ θ ≤ π. Since many of the standard examples of polar curves involve the θ-variable only in the form of either cos θ or sin θ, it usually suffices to only consider 0 ≤ θ ≤ 2π (or as Derive prefers −π ≤ θ ≤ π). Of course, you can change it to whatever interval you want. For example, in Figure 10.2 the range 0 ≤ θ ≤ π was used. You might want to plot the full graph at this point by using the default range. The resulting graph heart shaped curve is called a cardioid. Tracing. It is important to actually see the curve being plotted but the computer plots so quickly that it is nearly impossible to see it happen. Derive has an approach for “driving” around a curve called tracing. After plotting the polar curves above select the Trace Mode option on the Options 164 CHAPTER 10. POLAR AND PARAMETRIC GRAPHS menu (or just press F3 to toggle the Trace mode) and the cross will turn into a box and it will be moved onto the last curve plotted. Now press and hold down the right arrow key and watch the little car drive around the curve. You can see the value of θ, which we can also interpret as time, as it increases, as well as the r and θ coordinates, on the lower part of the screen. If you have more than one graph you can switch between curves by using the up or down arrow keys. When plotting the cardioid a = 1 pay particular attention to the way the plotting slows down as we approach the cusp. It turns out that the only way for cusps or corners to occur in the graph, when r(θ) is differentiable, is for the plotting to slow to a stop and then to start up again. This notion of speed will be discussed in Section 10.5. 10.3 Rotating Polar Curves A nice feature of polar coordinates is the ease with which we can rotate a figure. For example, if we plot r = ρ(θ) and we want to rotate the picture clockwise by an angle α we simply plot r = ρ(θ + α) instead. Try this out in for yourself using Derive. Here is an interesting application of this idea. Did you know that the curve y = 1/x, which is used to define the natural logarithm, is a hyperbola. The equation does not make this apparent since using the usual convention; namely, the axes should be chosen parallel and perpendicular to the axes of symmetry, we are supposed to have the equation of the form: x2 y 2 − 2 = ±1. a2 b We need to discuss converting polar graphs to rectangular graphs and vice versa. Figure 10.1 on page 162 makes it clear how to do this. The algebraic relationship between the polar coordinates [r, θ] and the rectangular coordinates (x, y) is given by the right triangle formed from the 3 points: (0, 0), (x, y) and (x, 0). The equations are: p (1) x = r cos θ, y = r sin θ and r = x2 + y 2, θ = tan−1 (y/x) In Figure 10.3 on the facing page we enter xy = 1, convert to polar coordinates by using the above equations and then rotate by α = π/4 in the 10.3. ROTATING POLAR CURVES 165 clockwise direction by substituting θ + π/4 for θ. We now what to apply the trigonometric formulas: sin(A + B) = sin A cos B + sin B cos A cos(A + B) = cos A cos B − sin A sin B but Derive does not simplify these by default. Instead we need to choose Declare/Algebra State/Simplification and on the Trigonometry box we select Expand. Simplifying these standard formulas will now yield the above. Simplifying our rotated curve now yields: r 2 cos2 t−r 2 /2 = 1. Converting back to rectangular coordinates we use (1) to replace r 2 cos2 t with x2 and r 2 with x2 + y 2 . This yields the desired result; namely, rotating the graph y = 1/x by 45◦ results in an equation x2 − y 2 = 2 which is a hyperbola. Figure 10.3: Showing that y = 1/x is a hyperbola Actually, the method used in Figure 10.3 to convert back to rectangular p 2 x + y 2 and θ = tan−1 (y/x) (Derive coordinates is to substitute r = denotes the inverse tangent function by ATAN). But there can √ be problems with this approach. For example, consider the polar point [ 2, 3π/4] which 166 CHAPTER 10. POLAR AND PARAMETRIC GRAPHS clearly corresponds to the point (−1, 1) in rectangular coordinates. But tan−1 (−1) = −π/4 instead of 3π/4 because the definition of the inverse tangent uses the principle angles −π/2 < θ < π/2. Thus, for points with x < 0 we should substitute θ = tan−1 (y/x) + π instead.1 Of course, in our example it doesn’t cause a problem thanks to the fact that cos2 (θ + π) = cos2 θ for all θ (check this using Derive). 10.4 Complex Numbers Recall that we can also think of the points in the plane as complex numbers. Thus, the point (a, b) in rectangular coordinates can also be considered to be the complex number a + b i. This raises the question of whether the polar coordinate representation of points in the plane might have an interesting application to visualizing complex numbers. The connection between these two ideas is provided by the Euler Formula that we discussed in an earlier problem (see Problem 6 on page 127). The formula, which essentially defines the complex exponential function, is given by eiθ = cos θ + i sin θ By looking at this formula we now realize that any complex number z = x + y i can be expressed as z = |z|eiθ where |z| = p x2 + y 2 and the angle θ comes from its polar coordinate representation. Note that the modulus |z| is simply the r in the polar coordinate representation. Thus, z = |z|eiθ = r cos θ + ir sin θ so that z has the polar coordinate representation [r, θ]. 1 Derive’s function ATAN has a two-variable form ATAN(y, x) which does the right thing. 10.5. PARAMETRIC CURVES 167 Rotations and Complex Multiplication Let’s look back at rotations from the previous section. Observe that the usual law of exponents when applied to complex exponentials, which can be verified using the addition formulas for sines and cosines, yields: eiα eiθ = ei(α+θ) . Hence, the geometric effect of multiplying an arbitrary complex number z by the complex exponential eiα is eiα z = eiα |z|eiθ = |z|ei(α+θ) and the point z is rotated in the counterclockwise direction through an angle α. Example The above formula now makes the computation of in for n = 2, 3, . . . completely transparent from a geometric point of view. Each power results in a counterclockwise 90◦ rotation. Thus, for example the famous formula i2 = −1 can be viewed as a rotation of the point (0, 1) in the plane to the point (−1, 0). 10.5 Parametric Curves As we saw in the last section we obtain many interesting curves by plotting r = ρ(θ) with α ≤ θ ≤ β in polar coordinates. However, there are still limitations on the shape of a polar curve (just as there are limitations on the shape of a rectangular graph) although these limitations are not as transparent since we have seen examples of looping in the limaçon curves. To study general curves we need the idea of parametric curves. To specify the motion of a particle in the plane; for example, the position of the ant crawling around on the plane, we return to rectangular coordinates and give the x–coordinate as a function, x = x(t), of a parameter t (which is usually thought of as time) and similarly for y = y(t). This means that at time t0 the particle is at the point (x(t0 ), y(t0 )). As an example, the equations (1) on page 164 show that the polar graph r = ρ(θ) for α ≤ θ ≤ β can be thought of as a parametric graph if we set x(t) = ρ(t) cos t, y(t) = ρ(t) sin t where α ≤ t ≤ β. 168 CHAPTER 10. POLAR AND PARAMETRIC GRAPHS Of course, this makes the plotting problem harder since we probably wouldn’t use the geometry of polar coordinates to plot points. The computer on the other hand doesn’t use geometric consideration since it just plots lots of points and connects them with line segments. Let us consider the non-polar example x(t) = 4 cos t, y(t) = sin t, where 0 ≤ t ≤ π. We can plot n points in order by taking ti = ti−1 + ∆t where ∆t = (β − α)/n and making a n × 2–matrix using the vector function. Enter [4*cos t,sin t] and then use Calculus/Vector with Start: 0, End: π and Step: .2 (this gives 16 points). Now we can plot this as usual in rectangular coordinates (you will need to switch back to rectangular coordinates). To draw a curve, select Options/Points again and set plotting mode to connected. Then, replot the points. See Figure 10.4 and Load the file F-PARAM1.MTH for a demonstration. Figure 10.4: Parametric plot of a semi-ellipse As with polar curves Derive has a simplified way to plot parametric curves. You simply plot the vector [4*cos t,sin t]. Derive will ask for 10.5. PARAMETRIC CURVES 169 the parameter interval and then plot the curve. You might have thought that Derive would plot the two functions 4 cos t and sin t since we know that this happens for 3 or more functions in a vector. But when a vector contains only two functions, it is treated as a parametric curve. Looking at the picture you might have guessed that the curve in Figure 10.4 was an ellipse (even if you didn’t read the caption) because of it’s oval shape. Of course, not all oval shaped curves are ellipses but indeed this example is one since one easily checks that x(t)2 y(t)2 + 2 = sin2 t + cos2 t = 1 for all t 42 1 and hence the particle travels along the ellipse x2 /4 + y 2 = 1 centered at the origin with semi-major axis 4 and semi-minor axis 1. Observe that this information does not tell you how the particle travels around on this ellipse. For instance, is it going clockwise or counterclockwise? Does it ever stop? See Figure 10.4 again and try the slow down technique to understand how the parametric curve can be thought of as a particle moving along a curve (like a car traveling over a roadway). By using this technique it is apparent that the motion is counterclockwise (as time t increases) and it never stops. This interpretation will be extremely important in later courses when Newton famous F = ma law is used to analyze the forces acting on a moving particle. Tracing parametric curves. Let us recall the tracing technique from Section 10.2, which we used for polar curves. We now want to “drive” around a parametric curve and observe its speed. After plotting the parametric curve above press F3. The cross will turn into a box on the curve and pressing and holding down the right arrow key will move the little car drive around the curve. You can see the time parameter as it increases, as well as the x and y coordinates, on the lower part of the screen. By watching the particle move while you press and hold down the right arrow key, you can see that the particle is traveling in the counterclockwise direction and a careful inspection will reveal that the speed (rate of change of distance with respect to time) is slower on the sides than the top and bottom parts of the curve. This is actually a consequence of one of Kepler’s laws of planetary motion. This law states that certain moving bodies revolving about a central point (such as the origin in this example) sweep out equal area in 170 CHAPTER 10. POLAR AND PARAMETRIC GRAPHS equal time. Assuming this fact, then the particle needs to be faster near the top and bottom since these points are closer to the origin and hence sweep out less area. Whereas the left and right portions of the curve are further from the origin and hence require less time to sweep out an equal amount of area. One can calculate the speed directly as follows: Over a small time interval ∆t the x-position changes by ∆x (= x(t + ∆t) − x(t)) and the y-position changes by ∆y.p Thus, the distance traveled during that time interval is approximately ∆x2 + ∆y 2 and hence the average speed is given by s p 2 2 2 2 p ∆x + ∆y ∆x ∆x = + ≈ x0 (t)2 + y 0 (t)2 ∆t ∆t ∆t Taking limits as ∆t → 0 leads to the formula: p Speed at time t = x0 (t)2 + y 0(t)2 . (2) Derive has an alternate approach for curves described by [x(t),y(t)]; namely, one uses Calculus/Differentiate on the vector and then √ applies ABS to the result. This works because ABS([a,b]) simplifies to a2 + b2 . Another use of Derive’s tracing feature is for curves that retrace themselves and hence make motion on the curve difficult to see. Try the example, x = sin t cos t and y = sin 2t for 0 ≤ t ≤ 2π. That is, plot the vector [sin t cos t, sin(2t)]. Surprisingly, the picture is simply a line segment with endpoints (−1/2, −1) and (1/2, 1). But how does the particle travel around this curve? By pressing F3 and tracing the curve we see a back and forth motion which reminds us of a swinging pendulum. In fact, by carefully observing the motion near the endpoints we see the particle slow down and stop. Then, it turns around and goes back in the opposite direction gaining speed as it approaches the center of the line segment and then slowing down as it approaches the other endpoint. A point where the speed is zero is actually the only way a smoothly parametrized curve, i.e., one for which x(t) and y(t) are continuously differentiable, can have cusps (like the cardioid) or corners (as in this example) or otherwise exhibit nonsmooth behavior. Check directly the speed at the endpoints. As a last example, enter x = 2 cos2 t and y = 2 sin t cos t for 0 ≤ t ≤ π. In this case we have another surprising picture of a circle, which we can verify by showing (x(t) − 1)2 + y(t)2 = 1 for all t. 10.5. PARAMETRIC CURVES 171 Figure 10.5: More parametric plots Two interesting features are that the complete circle is plotted with t in the [0, π] (instead of requiring 0 ≤ t ≤ 2π) and also that a particle travels around the curve with uniform speed. Observe this with the tracing technique and then verify it directly using (2). CHAPTER 10. POLAR AND PARAMETRIC GRAPHS 172 10.6 Laboratory Exercises 1. Consider the polar curve r = 2 cos θ. a. Plot the curve using polar coordinates. b. Describe how the curve is traced for 0 ≤ θ ≤ 2π. c. Use equations (1) on page 164 to convert the polar equation to rectangular coordinates. Use this to show that the curve is a circle of radius 1 with center at (1, 0). 2. Let r = 2 sin θ be a polar curve. a. Plot the curve using polar coordinates. b. Show that the graph is a rotation of the graph in Problem 1. 3. Let r = sec(θ − π/4) be a polar curve. a. Plot the curve using polar coordinates. b. Show that in rectangular coordinates the curve satisfies the equa√ tion: x + y = 2. (Hint: Use the Trigonometry Expand mode to simplify the equation.) 4. Plot several petal curves, r = 2 cos(nθ) for different integer choices of n. How many petals are there as a function of n? 5. Choose positive number d and e, then the family of polar curves r= ed 1 + e cos θ turns out to be conic sections (see your calculus text as a reference). We will examine this phenomenon with d = 2 and e set to 4 different positive values: e = .5, e = .75, e = 1 and e = 2. a. Plot the first two curves (e = .5 and e = .75) with −π < θ < π and identify the conics. b. Plot the curve with e = 1 with −3.10 < θ < 3.10. Can you identify this conic? 10.6. LABORATORY EXERCISES 173 c. Plot the curve with e = 2 with −2.09 < θ < 2.09. Can you identify this conic? d. In the last plot, what is the significance of the number θ = 2.09? What curves do you get when −π < θ < −2.10 or 2.10 < θ < π? (Warning: If you try plotting with the default range [−π, π] it will eventually graph the complete conic but it takes a very long time! Press Esc if you can’t wait.) 6. Let x = (cos t)3 and y = (sin t)3 for −π ≤ t ≤ π. a. Plot the parametric curve. b. Use Derive’s tracing method described on page 169 to find where the speed is 0 on the graph. c. Switch to the algebra window and verify your empirical observations by using (2) on page 170 to determine exactly where the speed is zero. 7. Let x = t sin t and y = t cos t for −3π/2 ≤ t ≤ 3π/2 a. Plot the parametric curve. b. Use tracing to determine how a particle (ant) traverses the curve over the given t interval. Sketch arrows on the graph to indicate the motion. c. What will happen if t is allowed to exceed 3π/2? Does it go around the curve again? *8. Start by authoring r(θ, a) := a(esin θ − 2 cos(4θ)) where we think of this function as a polar curve in θ with a paramenter a. Use Derive’s vector function to make a vector of the function r(θ, a) where the parameter a goes from 1 to 2 in increments of size 0.25. (So after you simplify it, the vector will contain 5 functions.) Plot this vector of 5 functions using polar coordinates. Does it look like a butterfly? (This curve is similar to one described by T. H. Fay, 174 CHAPTER 10. POLAR AND PARAMETRIC GRAPHS The butterfly curve, Amer. Math. Monthly, vol. 96, May 1989, p. 442.) It can be viewed on the Web as Figure 3 on our home page http://www.math.hawaii.edu/lab/ 9. Let x = t − sin t and y = 1 − cos t for t ≥ 0. a. Plot the parametric curve. b. Use tracing to verify that the motion stops briefly each time it touches the x–axis. c. Verify your observations in part b by using the formula for speed given in (2) on page 170. 10. Imagine a circle (or wheel) of radius one rolling along the x–axis at unit speed. Now try to picture the path followed by a fixed point on this circle as its rolls. This is the parametric curve in problem 9, it is called a cycloid curve. It may seem a little surprising that the speed of the point on the wheel is 0 once every time the wheel revolves even as the center of the wheel travels at a constant speed. a. Make a graph of the speed function (2) and determine how fast the point on the wheel going when it is at its highest point? (Hint: Plot the speed function and cycloid curve together on the same graph.) b. Load the file F-CYCL.MTH and plot expression #8 which contains the parametric curves for 5 positions of the rolling wheel along with a dot marking the particle’s position on the wheel. Then plot the cycloid expression #3, see Figure 10.6 on the facing page. 11. Plot the parametric curve x = sin(π sin t) and x = cos(π sin t) for −π ≤ t ≤ π. a. What geometric object does this look like? Prove that your answer is correct. b. Using the trace feature to see how a particle following these parametric equations moves along this geometric object. Describe this motion in words. 10.6. LABORATORY EXERCISES 175 Figure 10.6: The cycloid curve and the rolling wheel c. Are there places where the point seems to have speed 0? Find a formula for the speed of the particle at time t. At what times does the particle have speed 0 and what is the position of the particle at these times? 12. Two particles move in the plane. The motion of the first is described by the parametric equations x(t) = 16/3 − 8t/3, y(t) = 4t − 5, t≥0 and the second one by x(t) = 2 sin(πt/2), y(t) = −3 cos(πt/2), t≥0 Plot both of these curves. Find where the curves intersect. But just because the curves cross does not mean the particles collide; they might arrive at the intersection point at different times. Where do the particles collide? 176 CHAPTER 10. POLAR AND PARAMETRIC GRAPHS Chapter 11 Exponential Growth and Differential Equations 11.1 Introduction Suppose that y is a function of x. A first order differential equation is an equation which involves x, y and its derivative y 0 . An nth order differential equation involves x, y, y 0, . . . , y (n) . For example, y 00 + xy 0 = x2 + 1 is a second order differential equation. Differential equations occur frequently in every field of science and engineering, especially biology. Libraries have many volumes devoted to solving differential equations (even for first order differential equations). In this chapter we study first order differential equations and show some of the applications. One of the most important examples is population growth (of humans, cells, radioactive substances, savings account balances, etc.) We will show you how to get an exact solution to certain types of first order differential equations and we will introduce slope fields and Euler’s method for obtaining approximate solutions to more general first order differential equations. 11.2 Examples Population Growth. The standard model for population growth states that the rate of change y 0(x), of the population size y(x), with respect to time x is proportional to the population size at any given time. This means 177 178 CHAPTER 11. DIFFERENTIAL EQUATIONS that y 0 (x) = ky(x) for some fixed constant k and all x. Now it is easy to check that y(x) = y0 ekx satisfies the relations (1) dy = y 0 = ky dx y(0) = y0 where we simplify our notation by dropping the explicit reference to the variable x. Thus, the exponential function provides a model for population growth. Recall from Problem 7 on page 66 that we compared a linear model versus the exponential model above for the population of the US and found a significant difference in the long run behavior with the exponential model giving a much larger growth. This comparison was also made in Section 1.3 where it was shown that exponential growth eventually exceeds the growth of any polynomial. We now want to show that the above solution is the only solution to (1). Suppose that y = u(x) is a solution then Z x1 Z x1 0 u (x) dx = k dx = kx1 . u(x) 0 0 On the other hand, using the substitution y = u(x) in the integral above yields that Z u(x1 ) Z x1 0 u(x1 ) u (x) dy . dx = = ln u(x) y y0 y0 0 Now, if we set the right hand sides of the two equations above equal to each other we get u(x1 ) = kx1 . y0 Finally, we observe that since u(x1 ) > 0 and y0 > 0 we can remove the absolute values in the above equation. Exponentiate both sides of the resulting equation (remembering that eln a = a for a > 0) we get u(x1 ) = ekx1 y0 which is equivalent to our solution above. Less formally, this approach is quite simple. We rewrite dy = ky dx as dy =k y 11.2. EXAMPLES 179 and then integrate both sides to get Z Z dy = k dx = kx + c ln y = y and exponentiating yields y = ekx+c = ekx ec = c1 ekx . By using the initial conditions x = 0, y = y0 we see that the arbitrary constant c1 must be y0 . This method of solving differential equations is called separation of variables and the key feature is that the equation can be rewritten with all occurrences of y on the left side of the equation and all occurrences of x on the right side. Thus, to solve y 0 = f (y)g(x) you compute the integrals Z Z dy = g(x) dx + c f (y) explicitly and then solve for the constant c using the initial conditions. Example To solve the equation dy = xy 2 − 4x where y(1) = 4 dx we first separate the variables and integrate: Z Z dy = x dx . y2 − 4 Now, we use Derive to solve the integrals but add in a constant of integration c. This yields 1 y+2 x2 ln = +c 4 y−2 2 Now using Derive, substitute in the values x = 1, y = 4 and simplify. Next, have Derive solve for the value of c to get c= ln 3 − 1. 4 Finally, we substitute this value in the above equation and then have Derive solve for y to get the answer to the differential equation. 180 CHAPTER 11. DIFFERENTIAL EQUATIONS You should always check your answer to make sure it satisfies the differential equation and the initial conditions. In Derive you could differentiate the answer and set that equal to xy 2 − 4x where you use your answer in place of y. Now Simplify, you should get the value true which indicates that Derive was able to verify that the equation is an identity. You might also try this problem with pencil and paper ! The y-integral part involves some work since this is a partial fractions integration problem. Be CarefulR With Logarithms Since Derive gives the answer ln y, for the integral dy/y, instead of ln |y| this can cause some problems. From our definition of the logarithm it doesn’t make sense to take the log of a negative number. But Derive uses a more advanced definition which uses complex numbers and might cause some confusion for you. For example, Derive uses the formula ln(−1) = πi when it simplifies expressions. You have two choices: use Derive to solve the equations (potentially using complex numbers) or else change the answer to the integrals involving logarithms by inserting absolute values. In the previous example if we change the initial conditions to y(1) = 1 then we should change the equation resulting from the integrals above to the following: x2 1 y+2 ln = +c. 4 2−y 2 Now proceeding as before will give the solution. We’ll give several other examples of how to do this in the following sections. Newton’s Law of Cooling. Another important example of differential equations is Newton’s Law of Cooling. According to this law a hot pan of temperature yhot will have a temperature of y(t) at time t which decreases, i.e., will cool down, when placed in a vat of cool water of temperature ycool < yhot . The key point of the law is that the rate of change in the temperature, y 0 , is proportional to y(t)−ycool , which is the difference in the current temperature of the (hot) pan and the (cool) water. This says that (2) dy = −k(y − ycool ) dt where y(0) = yhot > ycool and k > 0 is a constant which depends on the physical properties of the pan, for example, copper cools faster than iron so the corresponding k-value 11.2. EXAMPLES 181 would be larger. Notice that the derivative dy/dt above is negative since the temperature is decreasing. We solve (2) by separating variables and integrating: Z Z dy = −k dt + c . y − ycool Simplifying this equation in Derive, we then solve for the unknown constant c by substituting in the initial conditions x = 0 and y = yhot . Note that we assume the quantity y − ycool to be positive; hence, we can take its logarithm. We now Substitute this value for c back into the relation above and solve for y. This gives the solution (3) y(t) = (yhot − ycool )e−kt + ycool . To do this computation in Derive we need to use multi-letter variables. Typically, one uses the variables yh and yc in place of yhot and ycool . So that these are treated as variables (and not as y · h) we first Author the vector [yh:=,yc:=] which simultaneously declares them both as variables. Notice that the term involving the exponential e−kt tends to zero very rapidly. Hence, y(t) tends to the water temperature ycool very rapidly. Radioactive Decay. In certain radioactive materials some particles change from one form to another. The number of particles decaying in this way in a small time period is proportional to the size of the material. So that, for example, if you have twice as much radioactive material the number of particles decaying is twice as great. If A(t) is the amount of radioactive material at time t, then A satisfies the differential equation A0 (t) = −kA. Here we have k > 0 and have written it in this way to emphasize that the derivative is negative since the amount of material decreases with time. Except for this minus sign this is the same as the population model above. It is easy to see the solution is (4) A(t) = A0 e−kt The half-life of a radioactive substance is the time it takes for half of it to decay. We can find this by solving A(t) = A0 /2 for t. By (4) this gives the equation A0 /2 = A0 e−kt . Cancelling the A0 , we get the equation 1/2 = e−kt , so that −kt = ln(1/2) = − ln 2 or t = ln 2/k. Notice that the half-life is independent of A0 . 182 11.3 CHAPTER 11. DIFFERENTIAL EQUATIONS Approximation of Solutions The general first order differential equation has the form y 0 = f (x, y) with initial conditions (x0 , y0 ), i.e., y = y0 when x = x0 . The separation of variables technique for solving differential equations that we discussed in the previous sections do not extend to all differential equations. In fact, many important differential equations cannot be solved explicitly by any technique what so ever. We encountered this situation earlier with integrals1 and this suggests trying to find numerical approximations to the solution. The critical observation to make is that the equation y 0 = f (x, y) tells us the slope of the tangent line to the solution y(x). Thus, by drawing many small line segments of slope f (x, y), through the point (x, y) in the plane, we obtain an approximate picture of the solution whose graph contains the point (x, y). By drawing several of these partial tangent lines we get an approximate picture of y(x) by drawing a curve which conforms to these slopes. These diagrams are called slope or direction fields. The file ADD-UTIL adds the function DF (for direction field) which will make a matrix. When this matrix is plotted it draws the ‘slope field.’ The form of DF is DF(r,x,x0,xm,m,y,y0,yn,n) where the first argument r is f (x, y) and x0, xm, m represent the initial and final x-values in a rectangular grid with m x-values plotted. Similarly, y0, yn, n represent the initial and final y-values in a rectangular grid with n y-values. Hence, the total number of line segments plotted will be m · n. In order that line segments are plotted, not just the endpoints, we put the plotting window into connected mode by choosing Options/Points and setting Connect to ‘Yes.’ As an example, we can take the cooling problem above, namely, y0 + y = 1 so that f (x, y) = −(y − 1) = 1 − y. We simplify the expression df(1-y,x,0,4,8,y,0,4,8) 1 Notice that the simple differential equation y 0 = f (x) has solution y = that the class of differential equations contains all integration problems. R f (x) dx so 11.3. APPROXIMATION OF SOLUTIONS 183 to get the slope field. In the plot window select Option/Plot Color and set it to ‘Off’ so that all slope lines will be in one color. Of course, if you like colorful diagrams then you can skip that last step. Also choose Option/Points to set the Connected Mode and to set Size to Small. Make sure to delete all existing graphs and then plot the slope field. Try to picture the solution though a given initial point (0, y0) by following the slope field. Finally, plot some actual solutions that we obtained above using the DE function and see how it conforms to the slope field. See Figure 11.1 where we have graphed the solution y = 3e−x +1, which corresponds to the initial condition y(0) = 4. Try several other initial conditions to see how the slope lines approximate the solution. Figure 11.1: Slope field for the Newton cooling problem ∗ Another Population Model. we had In the model we used for population growth dP = kP. dt 184 CHAPTER 11. DIFFERENTIAL EQUATIONS This works well for many populations. But the population cannot continue to grow forever. When a country no longer has room for expansion the rate of growth slows. For example, a bacteria culture in a petri dish will satisfy the above differential equation for awhile, but as the dish fills the above equation becomes invalid. Verhulst, a Belgian mathematician, proposed a model using the differential equation P dP = kP 1 − (5) . dt P1 Notice that when P is small compared to P1 , the derivative is approximately kP , as before. But as P approaches P1 , P 0 approaches 0. We study this equation by looking at the direction field. Let’s take a numerical example P dP =P 1− where P (0) = 1 , dt 5 so that the population starts out at a value of 1 and has a maximum value of 5. We’ll guess as to how long of a time interval to look at, say 0 ≤ t ≤ 12. Thus, we enter df(p(1-p/5),t,0,12,12,p,0,6,6) and Approximate to get a large direction field matrix. See Figure 11.2 on the facing page for a picture of the direction field. Looking at the picture of the direction field you should be able to see the solution approximately by starting at the point (0, 1) and “following along” in the direction of the tangent lines. The picture makes it appears that it takes only about 6-7 time units before the population reaches its maximum value of 5. To solve (5) exactly we separate variables and integrate Z Z dP = k dt + c . P (1 − PP1 ) In Derive we would first declare the variables P0 and P1 by entering [p0:=, p1:=] and then entering each of the integrals. Then, we Author the above equation. Notice that we added the integration constant c. After simplifying we get ln P − ln(P − P1 ) = c + kt 11.3. APPROXIMATION OF SOLUTIONS 185 Figure 11.2: A graph of a Verhulst population curve We solve for c by substituting in the initial conditions t = 0, P = P0 . After solving for c and substituting the value into our relation from above we now try to get the solution by solving for P . The equation we are trying to solve is ln P − ln(P − P1 ) = (ln(P0 ) − ln(P0 − P1 )) + kt . But, there are two problems with the above equation. We assume that 0 < P0 < P < P1 when t > 0 and so two of the logarithm have negative arguments. As a result we modify the above to the equation ln P − ln(P1 − P ) = (ln(P0 ) − ln(P1 − P0 )) + kt . and then try to solve for P . Curiously, this equation is too hard for Derive to solve and it returns no solutions. After carefully inspecting the equation it seems like a good idea to exponentiate both sides of the equation and use the fact that eln p = p whenever p > 0. In Derive this can be done by Authoring #e raised to CHAPTER 11. DIFFERENTIAL EQUATIONS 186 a power where the power is the above equation and then Simplifying. This yields the equation P0 ekt P = P1 − P P1 − P0 which Derive can solve for P . The result is (6) P = P0 P1 ekt P0 ekt + (P1 − P0 ) Notice that P (0) = P0 , as we would expect, and that limt→∞ P (t) = P1 . 11.4 Euler’s Approximation Method∗ The method of slope fields suggest an approximation technique known as Euler’s method . The idea is to approximate the solution to y 0 = f (x, y) where y(x0 ) = y0 by a piecewise linear function passing through a sequence of points (x0 , y0 ), (x1 , y1), . . . , (xn , yn ) obtained by using the slope at (xi−1 , yi−1), which is f (xi−1 , yi−1 ), to construct the next point (xi , yi ), where the increment in x is a fixed amount, say xi = xi−1 + h. The Derive function is deceptively simple: EULER(r,x,y,x0,y0,xn,n):= ITERATES(v+[1,LIM(r,[x,y],v)]*(xn-x0)/n,v,[x0,y0],n) where x varies between x0 ≤ x ≤ xn and we use n points in the approximation scheme. This function is also in the file ADD-UTIL. It is a slight variant of the EULER function in the utility file ODE APPR that comes with Derive. Try the Newton cooling problem EULER(1-y,x,y,0,4,4,16) to see how this works. Again, you must be sure that your graphics window is in single color, connected mode for this to plot properly. See the Figure 11.3 on the next page for a demonstration of this technique. You should try larger and larger n to see that the approximations converge, as n → ∞, to the solution for 0 ≤ x ≤ 4. 11.5. LINEAR FIRST ORDER DIFFERENTIAL EQUATIONS 187 Figure 11.3: Euler’s method for approximating solutions 11.5 Linear First Order Differential Equations Returning to the population growth equation (1) we now describe another method for proving that the exponential solution to equation is the only solution to that equation. To do this we suppose that u(x) is any solution to y 0 = ky that satisfies u(0) = y0 . We want to show that u(x)/ekx = e−kx u(x) is a constant, so we compute it’s derivative and observe that (7) 0 (e−kx u) = e−kx u0 − ke−kx u = e−kx (u0 − ku) = 0 holds for all x. Hence integrating gives e−kx u(x) = c. We solve for the constant c by substituting x = 0 in the above to get c = u(0) = y0 and then multiply both sides by ekx to obtain2 u(x) = y0 ekx 2 In Derive you can multiply both sides of an equation by an expression by right clicking the equation, inserting with parentheses into the author box and then multiplying. 188 CHAPTER 11. DIFFERENTIAL EQUATIONS as we claimed. Equation (1) is a special case of the general equation (8) y 0 + p(x)y = q(x), y(x0 ) = y0 since (1) can be written as y 0 −ky = 0. Thus, in (8) the functions p(x) = −k, q(x) = 0 and initial time x0 = 0. Any differential equation with the form of (8) is called a linear first order differential equation. We will prove that any such equation has a unique solution which is obtained in manner a similar to the above. See Theorem 1 below for the formula for the solution. The formula for the solution to (8) can be made into a Derive function quite easily. This has been done in Derive’s utility file ODE1 with the name LINEAR1. For convenience we have added this function to our utility file ADD-HEAD but we use the shorter name DE. It has the form DE(p, q, x, y, x0, y0) where p and q are expressions in the variable x. The initial conditions are y = y0 when x = x0. Example To solve the differential equation y 0 = 2y where y(0) = 5 simplify DE(-2,0,x,y,0,5). Note that the above equation can be rewritten as y 0 − 2y = 0 so p(x) = −2 and q(x) = 0. This will yield the expression y = 5e2x as the solution. Example To solve the Newton Cooling equation y 0 = −k(y − ycool ) where y(0) = yhot we rewrite the equation so that it has the form of the general first order linear differential equation in (8): (9) y 0 + ky = kycool y(0) = yhot and thus we can solve this equation with Derive by using the DE function. We will use the variables yh and yc in place of yhot and ycool . So that these 11.5. LINEAR FIRST ORDER DIFFERENTIAL EQUATIONS 189 are treated as single variables (and not as y · h) we first Author the vector [yh:=,yc:=]. Then we Author de(k,k*yc,t,y,0,yh) Simplifying the expression gives the solution y(t) = (yh − yc)e−kt + yc. (10) See Figure 11.4 for a demonstration of these functions and observe how rapidly the temperature y(t) tends to the water temperature yc. Use Derive to calculate limt→∞ y(t). Figure 11.4: Solving Newton’s cooling equation By looking back at (7) on page 187 and making a small modification of that argument we see how the above solution is derived; namely, by (9), (11) 0 (ekx y) = ekx y 0 + kekx y = ekx (y 0 + ky) = ycool kekx CHAPTER 11. DIFFERENTIAL EQUATIONS 190 and hence integrating gives Z kx ycool kekx dx = ycool ekx + c. e y(x) = Now solving for c by substituting x = 0 in the above yields c = yhot − ycool and then multiplying both sides by e−kx gives the desired result above. The argument above gives us a pretty good idea how to solve the general differential equation y 0 + p(x)y = q(x). One multiplies y by an appropriate exponential µ, differentiates and then replaces the quantity y 0 + p(x)y by q(x). Integrating the result essentially solves the problem. That critical multiplying exponential turns out to be R µ(x) = e p(x) dx µ0 (x) = p(x)µ(x). since See the proof of Theorem 1 below for the details. We now solve the general linear first order differential equation (8) by proving the following theorem: Theorem 1. Suppose that y(x) satisfies (8) where p(x) and q(x) are continuous functions of x. If y satisfies the initial condition y(x0 ) = y0 then Z x R Ru − xx p(u) du p(v) dv x (12) · q(u)e 0 du + y0 . y=e 0 x0 Rx p(u) du Proof. Let h(x) = e x0 . By hthe fundamental theorem of calculus, i Rx Rx p(u) du d d 0 x0 = p(x)h(x). Thus p(u) du = p(x). So h (x) = dx e dx x0 (h(x)y)0 = h(x)y 0 + h0 (x)y = h(x)y 0 + p(x)h(x)y If we multiply equation (8) by h(x) and use the above, we see that (h(x)y)0 = h(x)q(x). If we integrate both R x sides of this from x0 to x and use the fact that h(x0 ) = 0, we get h(x)y = x0 h(u)q(u) du + C, or − y=e Rx x0 Z p(u) du x · Ru q(u)e x0 p(v) dv du + C . x0 Since y(x0 ) = y0 , we see that C = y0 and thus (12) holds. 11.6. LABORATORY EXERCISES 191 As we said, the solution (12) to the differential equation can be made into a Derive function quite easily. You should look at the formula above and see if you can write a Derive function that will produce the solution. Then compare your answer with the following definition of the function DE.3 (13) de(p,q,x,y,x0,y0):= y = e^(-int(p,x,x0,x)) * (int(q*^ ^ e^int(p,x,x0,x),x,x0,x)+y0) 11.6 Laboratory Exercises The functions discussed in this chapter, DE, DF, and EULER, are all defined once you Load in the file ADD-HEAD. 1. If money earns interest compounded continuously and y(t) is the amount of money at time t, then y satisfies the differential equation y 0 = ry, where r is the interest rate. a. What is the solution to the differential equation y 0 = ry? b. Find how long it takes for your money to double for r = 3%, 5%, and 10%? (This means that r = 0.03, 0.05, and 0.1 in the above equation.) 2. Normal body temperature is 98.6◦ F. If someone dies, then the body cools according to Newton’s law of cooling. It is known that, if the surrounding temperature is a constant 64◦ , then the body will cool to 92◦ in 3 hours. 3 You might notice that the formula for the solution to the differential equation in Theorem 1 is careful about the “dummy R x variables” in the integrals. This is because in calculus we avoid integrals of the form a f (x) dx because the integration variable x might be mistaken for the upper limit x. Since the integration variable is completely arbitrary we usually take it to be t or u in such a situation. On the other hand, for the Derive function de above we used expressions like int(f(x),x,0,x) because the integration is done before the limits of integration are substituted. The computer does this correctly but it is usually foolhardy for students to try this since it is so easy to make mistakes such as Z x Z x x dx = x dx = x2 0 2 when then answer should be x /2. 0 192 CHAPTER 11. DIFFERENTIAL EQUATIONS a. Use this information to compute the constant k in (10) on page 189. b. Now suppose that a murder victim’s body is found at 12am with a temperature of 86◦ . Assuming an air temperature of 64◦ , determine when the murder was committed? 3. Consider the differential equation y 0 = 0.1x(y 2 − 4) with y(1) = 1. a. Use the DF function to draw a 16 × 16 grid of slope lines using 0 ≤ x ≤ 8 and −4 ≤ y ≤ 4. (You need to have the graphics window in the connected state; see the instructions for this on page 182.) b. Print out the slope field graph and with your pencil draw an approximate solution to the differential equation starting at the initial condition (1, 1). c. Use the separation of variables method to find the solution to the differential equation and plot the answer to see how it conforms to the slope lines. d. Verify that the solution never attains the value y = −2. Can you explain this fact by looking at the equation itself and not the solution? 4. Consider the differential equation y 0 = sin x − y with y(−1) = −1. a. Use the DF function to draw a 10 × 10 grid of slope lines using −1 ≤ x ≤ 3 and −1 ≤ y ≤ 1. (You need to have the graphics window in the connected state; see the instructions for this on page 182.) b. Rewrite the differential equation to have the form (8) on page 188. Use the DE function to find the solution to the differential equation and plot the answer to see how it conforms to the slope lines. c. Double check that the answer you get from the DE function is indeed the solution by verifying that it solves the differential equation and the initial conditions. 11.6. LABORATORY EXERCISES 193 5. Suppose a body of mass m is dropped from high in the atmosphere. Let v be its downward velocity as a function of time t. There are two forces acting on the body: gravity and wind resistance. The force due to gravity is mg, where g is a constant; the force due to wind resistance is −kv (the minus since it is upward). Newton’s law says F = ma, where a = v 0 is the body’s acceleration. This leads to the differential equation ma = mv 0 = mg − kv. Solve this equation for v with v(0) = 0. Find limt→∞ v(t) (don’t include the v= part from above). Derive returns an expression containing SIGN(km) because it does not know that k and m are positive. Use Declare/Variable Domain to declare that k is a positive real number, and do the same for m. Now reevaluate the limit. Note that v never exceeds this value, which is called the terminal velocity. No wind resistance corresponds to k = 0. Find v in this case both by solving the differential equation with k = 0, and by taking the limit of the general solution for v found above as k → 0. *6. Suppose the population growth of a small country satisfies (5) with P1 = 10 and k = 0.05 (with population in millions). Plot the direction field for this. (There are instructions for doing this in Section 11.3.) Suppose P (0) = 2. Find P (20), P (50), and P (100). Graph P (t). Adjust the scale of the graph so that you get a clear picture of the nature of the population growth. 7. Carbon-14, 14 C, is an unstable isotope of carbon that slowly decays to the more stable 12 C. While an organism is alive it has a constant amount of 14 C, but after it dies, the amount decreases according to (4). If 200 years after the organism dies, the amount of 14 C is 97.6% of the original amount, what is the half-life of 14 C? If the burnt wood from a prehistoric campsite contains 29% of the original amount of 14 C, how old is the campsite? 194 CHAPTER 11. DIFFERENTIAL EQUATIONS Chapter 12 Harmonic Motion and Differential Equations 12.1 Introduction In this chapter we consider second order differential equations of the form y 00 = f (t, y, y 0) where y(t0) = y0 and y 0(t0 ) = y00 . It is easy to see that two initial conditions are needed because in the simply case y 00 = f (t) one would simple integrate f (t) twice and that there would be two constants of integration. Our applications involve moving physical systems such as oscillating springs and swinging pendulums. These systems can be analyzed using Newton’s Law of Motion: F = ma. Since the a in this formula is acceleration which is the second derivative with respect to time we see that Newton’s formula is actually a second order differential equation. Free Fall The equation for the vertical height y of a free falling particle, in the time variable t, is given by y 00 = −g where y(0) = y0 and y 0 (0) = v0 where g is the force due to gravity (which we assume is constant). The initial conditions in this case are the initial height y0 and the initial velocity v0 . By integrating twice and solving for the initial conditions we get the solution y = y0 + v0 t − 12 gt2 . Here are the steps: 195 CHAPTER 12. HARMONIC MOTION 196 Z 0 y = Z y= −g dt = −gt + c1 = −gt + v0 1 1 −gt + v0 dt = − gt2 + v0 t + c2 = − gt2 + v0 t + y0 2 2 Notice that the constants are obtained by substituting t = 0, y = y0 and y 0 = v0 . In this chapter we will mainly be interested in second order linear differential equations of the form y 00 + by 0 + cy = 0 (1) These equations are linear differential equations because of they only involve y 00 , y 0 and y in a linear relation. It turns out that to solve these equations we need to use the complex exponential function eαx which was discussed earlier in Problem 6 on page 127 in Chapter 7. Here α = a + b i is in general a complex number (see Section 5.4 on page 78 for a brief tutorial on complex numbers). 12.2 Examples Springs and Hooke’s Law. Suppose we have a mass m attached to the end of a spring hanging from the ceiling. If we pull the mass down a little it will bounce (oscillate) up and down. We image it moving along the y–axis with y = 0 denoting the rest position. Newton’s law says F = ma where F is the force on the mass and a = y 00 is the acceleration. A reasonably good approximation of the force is given by Hooke’s Law which states F = Fspring = −ky where k is a positive constant. Since Fspring = F = ma = my 00 this gives y 00 = k y. After transposing the y term we get the following linear differential −m equation: (2) y 00 + k y=0 m As an example suppose we pull the particle down d units and let go. Then, the initial condition would be: y0 = −d and v0 = 0 12.2. EXAMPLES 197 Damped oscillation. Now suppose that we immerse our oscillating spring into a vat of oil. The oil would cause the oscillations to be damped out and eventually our system will come to a stop. This is basically the model for a car’s shock absorbers. When you hit a bump you want the oscillations to damp out at just the right rate so as to give a conformable ride. Not too quickly nor too slowly. The resistance force due to the oil is proportional to the velocity of the particle so we introduce a new force Foil = −by 0 where b is a positive constant. If we take this into account we get F = Fspring + Foil and our differential equation (2) becomes (3) y 00 + b 0 k y + y = 0. m m Pendulums. Suppose we have a mass m at the end of a pendulum of length l. It swings along a circular arc. When the pendulum is at rest it hangs straight down and has velocity 0. Let s(t) denote the arc length from this rest position as a function of time. Let θ(t) be the angle the pendulum makes from the vertical position. Then s = lθ and so the acceleration is d2 s/dt2 = ld2 θ/dt2 . The force on the mass due to gravity is downward and has magnitude mg, where g is the gravitational constant. This force can be broken into the part in the same direction as the pendulum rod and a part part tangent to the arc traced out by the mass; see Figure 12.1. θ s Figure 12.1: The pendulum CHAPTER 12. HARMONIC MOTION 198 The component of the force in the direction of the pendulum rod is cancelled out by the rod. The force along the arc is −gm sin θ. Newton’s law, F = ma says md2 s/dt2 = −gm sin θ. In terms of θ we get the differential equation: (4) g d2 θ = − sin θ 2 dt l This is not a linear equation because of the sin θ. But the Taylor series is sin θ = θ − θ3 /6 + · · · , so if θ is small we can approximate sin θ with θ. Using this (4) becomes (5) d2 θ g + θ=0 dt2 l If we start by pulling the pendulum back by an angle θ0 and letting go we get the initial conditions: θ = θ0 and 12.3 dθ = 0 when t = 0 . dt Solving Linear Differential Equations Our basic technique to solving (1) is to try an exponential solution y = ert for some choice of r. This is not such a surprising guess when one considers the simple example y 0 − ry = 0 from the previous chapter. We know that the solution would be y0 ert in that case. Substituting y = ert into (1) we get r 2 ert + brert + cert = (r 2 + br + c)ert = 0 . Since ert > 0 we want to solve the quadratic equation (6) r 2 + br + c = 0 This equation is called the characteristic equation. Its roots are √ √ −b + b2 − 4c −b − b2 − 4c r1 = (7) and r2 = 2 2 and so both y = er1 t and y = er2 t are solutions to (1). 12.3. SOLVING LINEAR DIFFERENTIAL EQUATIONS 199 Now, we take advantage of the fact that our differential equation is linear. We claim that if y1 , y2 are solutions to (1) then so is any function of the form y = C1 y1 + C2 y2 where C1 , C2 are arbitrary constants. This is easy to verify: y 00 + by 0 + cy = (C1 y1 + C2 y2 )00 + b(C1 y1 + C2 y2 )0 + c(C1 y1 + C2 y2 ) = (C1 y100 + C2 y200 ) + b(C1 y10 + C2 y20 ) + c(C1 y1 + C2 y2 ) = C1 (y100 + by10 + cy1 ) + C2 (y200 + by20 + cy2 ) = C1 0 + C2 0 = 0 . Finally, we take y1 = er1 t , y2 = er2 t above and then use the two arbitrary constants C1 , C2 to solve for the two initial conditions: y(t0) = y0 and y 0(t0 ) = y00 . Example Consider the equation, (8) y 00 − y 0 − 2y = 0 where y(0) = 3, y 0 (0) = 0 . The characteristic equation is r 2 − r − 2 = (r + 1)(r − 2) = 0 so r = −1, 2 . Our general solution is therefore y = C1 e−t + C2 e2t and we need to solve for the initial conditions. This leads to the pair of equations: C1 + C2 = y(0) = 1 −C1 + 2C2 = y 0(0) = 0 which has solutions: C1 = 2 and C2 = 1. Just to be sure, double check that the function y = 2e−t + e2t satisfies the differential equation in (8) and the initial conditions. To simplify the process above for the general second order equation (1) we use the utility function (we assume that you have loaded the file ADD-HEAD as usual): DE2(b, c, t, t0, y0, v0) . Thus, for our example we would Simplify DE2(-1, -2, t, 0, 3, 0). 200 CHAPTER 12. HARMONIC MOTION Example Now consider the equation, (9) y 00 + y = 0 where y(0) = 3, y 0 (0) = 0 . The characteristic equation in this case is r 2 + 1 = (r + i)(r − i) = 0 so r = ±i . Thus, we should try y = C1 eit + C2 e−it . We don’t usually encounter exponentials with complex numbers in the exponent so what does it mean? The answer is that we use the Euler Formula the has been discussed in an earlier exercise, see Problem 6 on page 127. Thus, eit = cos t + i sin t and e−it = cos t − i sin t and in general, e(α+β i)t = eαt (cos βt + i sin βt) . It’s important to note (again from Problem 6 on page 127) that the differentiation formula d (α+β i)t e = (α + β i)e(α+β i)t dt still holds, even for complex exponents, and hence y 0 = iC1 eit + (−i)C2 e−it . Thus, to solve for C1 , C2 we need to solve the equations: C1 + C2 = y(0) = 3 iC1 + (−i)C2 = y 0(0) = 0 Even though these equations have complex coefficients it is pretty easy to solve. In the second equation, just cancel the i terms. This yields the new equations: C1 + C 2 = 3 C 1 − C2 = 0 which has the solution C1 = C2 = 3/2. At this point it looks like our solution is going to involve complex numbers. But this runs counter to our intuition since (9) is model for an undamped 12.3. SOLVING LINEAR DIFFERENTIAL EQUATIONS 201 mass-spring system (see (2)) and this couldn’t possibly have complex numbers in the solution. Let look at the computation: 3 3 y = eit + e−it 2 2 3 3 = (cos t + i sin t) + (cos t − i sin t) 2 2 = 3 cos t and hence the i-term drops out of the solution. Although we were convinced of this fact from a physical point of view it was far from obvious from an algebraic point. To see why this is always the case we make an important observation about (1). Since we tacitly assume that the coefficients b, c are real numbers observe that if y is a solution to (1) then so are the real part 0). Note that r2 = α − iβ which is the complex conjugate of r1 . To find the real solutions corresponding to e(α+iβ)t we calculate eα+iβ = eαt eiβt = eαt cos(βt) + i sin(βt) Thus, as we showed above eαt cos(βt) and eαt sin(βt) are both solutions. Of course, we can easily check this fact directly by substituting eαt cos(βt) for y in (1) and show the left side simplifies to 0. Try this yourself. When b2 − 4ac = 0, r1 = r2 we have a problem because we know longer have two different solutions with which to solve for C1 , C2 . However, in this case both er1 t and ter1 t are solutions; see Exercise 3 on page 213. Summarizing, with r1 , r2 , α, and β as above, the general solution of (1) are (10) y = C1 er1 t + C2 er2 t if b2 − 4c > 0 (11) y = C1 er1 t + C2 ter1 t if b2 − 4c = 0 (12) y = C1 eαt cos(βt) + C2 eαt sin(βt) if b2 − 4c < 0 Using this form of the general solution we solve for the two arbitrary constants C1 , C2 using the initial conditions as above. Again, assuming you have loaded the ADD-HEAD file, you can solve (1) subject to these initial conditions by authoring DE2(b, c, t, t0, y0, v0) Springs and Hooke’s Law. Returning to our mass-spring example, suppose we have a mass m attached to the end of a spring hanging from the ceiling. If we pull the mass down a little it will bounce (oscillate) up and down. We image it moving along the y–axis with y = 0 denoting the rest position. Hooke’s Law for the spring force differential linear equation: (13) y 00 + k y = 0. m As an example suppose we pull the mass down d units and let go. Then y0 = −d and v0 = 0 so we can find the motion by authoring DE2(0, k/m, t, 0, -d, 0) but first we need to tell Derive that the two constants k, 12.3. SOLVING LINEAR DIFFERENTIAL EQUATIONS 203 m are both positive numbers. You use the Declare/Variable Domain to tell Derive that k is positive and do the same for m. Now simplifying the DE2 function gives the answer √ ! k −d cos √ t m Figure 12.2 shows the graph of this function when k = 2 and m = 1 and d varies between −2 and 2 in increments of 0.5. Notice all of the graphs cross the x–axis at the same place; that is, at the same time. So it doesn’t matter how far the spring is pulled down it will take q the same amount of k then time to return time to return to its original position. If we let ω = m to the original position is 2π/ω independent of d. This is called the period of oscillation. ω is called the angular frequency while the reciprocal of the period, ω/2π is the frequency. In Exercise 4 on page 213 you investigate what happens if we start with y0 = 0 but vary the velocity. Figure 12.2: Spring motion starting at different positions CHAPTER 12. HARMONIC MOTION 204 Damped oscillation. Recall that the frictional force due to the oil in the vat is proportional to the velocity of the mass. This extra force changed the differential equation (2) to (14) y 00 + b 0 k y + y=0 m m where b, k, m are all positive constants. Before we analyze the roots of the characteristic equation just imagine the effect of going from a very small value of b, close to zero, to a large value. Since the value of b represents how difficult it is to move in the oil (this is essentially the viscosity of the oil) a small value would mean the solution is similar the oscillating spring although it eventually slows down and stops. A larger value will mean less oscillations and eventually there will be no oscillations and the system will quickly come to a stop. Actually, the mathematical model never actually stops, it just goes into exponential decay! Going back to the characteristic equation for this equation we have r2 + k b r+ =0 m m Its roots are −b ± √ b2 − 4km 2m √ The solutions to (14) are given in (10)–(12). The sign of b2 − 4km determines which equation applies. If b2 > 4km we say the spring is over damped . In this case the solutions of (14) have the form of (10) with r1 and r2 the solutions to the characteristic equation given above. Notice that since b, k, and m are all positive √ b2 − 4km < b 0 < b2 − 4km < b2 so and thus, both r1 and r2 are negative. So the general solution is the sum of two decaying exponentials. If b2 = 4km the spring is critically damped. The solutions are given by (11). Again r1 is negative. If b2 ≤ 4km the spring is under damped. The solutions are given by (12). 12.3. SOLVING LINEAR DIFFERENTIAL EQUATIONS 205 As an illustration we take b/m = 1 and k/m = 4 in (2). To solve (2) with initial conditions t0 = 0, y0 = 2, and v0 = 0 we author DE2(1, 4, t, 0, 2, 0). Simplifying this gives ! !# " √ √ √ 2 15 15 15 t + sin t e−t/2 2 cos 2 15 2 We use the Declare/Algebra State/Simplification menu to set Trigonometry to Collect and simplify again we get √ ! √ √ 8 15 −t/2 15 15 e t + 2 arctan sin 15 2 5 ≈ 2.06559e−t/2 sin(1.93649 t + 1.31811) √ Figure 12.3 graphs this function as well as ± 8 1515 e−t/2 . Figure 12.3: Under Damped Oscillations 206 CHAPTER 12. HARMONIC MOTION Pendulums. Lastly, let’s return to the pendulum example. We have a mass m at the end of a pendulum of length l. It swings along a circular arc. When the pendulum is at rest it hangs straight down and has velocity 0. Let s(t) denote the arc length from this rest position as a function of time. Let θ(t) be the angle the pendulum makes from the vertical position; see Figure 12.1 on page 197. As noted earlier the component of the force in the direction of the pendulum rod is cancelled out by the rod and the force along the arc yields the differential equation: (15) d2 θ g + sin θ = 0 dt2 l Since this is not a linear equation we approximate sin θ with θ to get (5), i.e., (16) d2 θ g + θ=0 dt2 l In our illustration, we start by pulling the pendulum back by a small angle θ0 and letting go we can solve the equation by authoring DE2(0, g/L, t, 0, θ0 , 0). This gives the solution r g t θ0 cos l Notice that the period depends on l but not on θ0 . This is why old clocks often use pendulums. As the spring runs down the pendulum will continue to swing with the same frequency (until it stops completely of course). You can adjust the speed by making a small change in the length of the pendulum. Later in this chapter we will show how to find approximate solutions to exact pendulum equation (15). 12.4 Systems of Differential Equations Predator prey population growth. Suppose we have a population of rabbits. Let R(t) be the population at time t and let R0 = R(0) be the initial population. In Chapter 11 we had two models for R(t). The first was R0 = kR was the standard exponential growth model. The second was the Verhulst modification of this: R0 = kR/(1 − R/R1 ), where R1 is a constant 12.4. SYSTEMS OF DIFFERENTIAL EQUATIONS 207 representing the ideal population. But suppose we also have a population, F (t), of foxes which prey on the rabbits. This gives us a system of differential equations for R(t) and F (t). It is reasonable to assume that number of rabbits eaten by foxes is proportional to R · F . Then the population of rabbits and foxes can be modeled by the equations (17) R0 = kR(1 − R/R1 ) − cRF F 0 = dRF − eF where k, c, d, and e are positive constants. If R = 0 the second equation becomes F 0 = −eF . This means that if there are no rabbits the fox population will dwindle because there is nothing to eat. If F = 0 then the rabbit population will follow the Verhulst model. The Runge-Kutta method of approximation. first order differential equations has the form (18) A general system of two y 0 = r(t, y, z) z 0 = s(t, y, z) These can be solved exactly if r(t, y, z) has the form ay + bz and s(t, y, z) has a similar form. (When r and s have this form, the system of equations (18) is called linear.) Since the examples we are interested are not linear, we concentrate on finding approximate solution to (18). In Chapter 11 we described Euler’s method for finding an approximate solution of a single first order equation y 0 = f (t, y) subject to the initial conditions y(t0 ) = y0 . We start with the point (t0 , y0). Since we know the slope of y at this point is f (t0 , y0) we draw a short line segment from (t0 , y0 ) to (t1 , y1) = (t0 + h, y0 + hf (t0 , y0 )), where h is a small increment. The (n + 1)st point is obtained the nth by (tn+1 , yn+1 ) = (tn + h, yn + hf (tn , yn )) Figure 12.4 on the following page gives the direction field for the simple differential equation y 0 = −4(t − 1). Of course we can find the solutions by integration. If y(0) = 0 this gives y = 2t(2 − t), which we have also graphed. If we use Euler’s method with h = 1/2 the first three points are (0, 0), (1/2, 2), and (1, 3). As the graph indicates these points are not very close to the true solution. 208 CHAPTER 12. HARMONIC MOTION If instead of using the slope at (tn , yn ) we average this slope with the slope at the next point (tn+1 , yn+1) we obtain a much more accurate approximation of the solution. This is known as the second order Runge-Kutta method. The precise formulae for tn+1 and yn+1 are (19) tn+1 = tn + h = t0 + (n + 1)h h yn+1 = yn + f (tn , yn ) + f (tn + h, yn + hf (tn , yn )) 2 As we can see from Figure 12.4 this is much more accurate. If we also take into account the slope at the midpoint of the two points we obtain the fourth order Runge-Kutta method . This is usually just called the Runge-Kutta method . Figure 12.4: Euler and the 2nd Runge-Kutta methods If we have a system of equations like (18) we calculate triples of points (tn , yn , zn ) instead of pairs, but the formula is essentially the same. The Derive utility function RK, which is included in ADD-HEAD, will calculate approximate solutions to system of differential equations using the Runge- 12.4. SYSTEMS OF DIFFERENTIAL EQUATIONS 209 Kutta method.1 To approximately solve (18) with initial conditions y(t0 ) = y0 and z(t0 ) = z0 , we author RK([r(t,y,z), s(t,y,z)], [t, y, z], [t0, y0, z0], h, n) where h is the step size and n is the total number of steps you want. When we approXimate this we get a matrix of triples. To graph y(t) we use the function extract 2 columns(m,1,2) (where m is the matrix we got). This gives a matrix of pairs which we can plot. To plot z(t) we use extract 2 columns(m,1,3). Returning to the predator-prey problem let’s look at the rabbits and foxes problem with specific data for the constants in (17):2 k = .1 rabbit per month per rabbit R1 = 10000 rabbits c = .005 rabbit per month per rabbit-fox d = .0004 fox per month per rabbit-fox e = .04 fox per month per fox t0 = 0 months R0 = 2000 rabbits F0 = 10 foxes To use the Runge-Kutta method to find an approximation of the solution we author: RK([.1r(1 - r/10000) - .005rf, .00004rf - .04f], [t,r,f], [0,2000,10], 0.5, 600) We approximate this and then use extract 2 columns for columns 1 and 2 to see R(t). The result is graphed in the upper right window of Figure 12.5 on the following page. Extracting column 1 and 3 gives the fox population graphed in the lower right. Notice both populations oscillate with the fox population following the rabbit population. After the rabbits increase the foxes will then increase but when the fox population gets large the rabbit 1 RK is the same as the one in Derive’s utility file ODE-APPR so the description of it in Derive’s Help applies. 2 This example is taken from J. Callahan and K. Hoffman Calculus in Context, W. H. Freeman, 1995. 210 CHAPTER 12. HARMONIC MOTION population will decrease which in turn will cause the fox population to decrease and so on. The window in the lower left of Figure 12.5 shows the results of extracting columns 2 and 3. The point near the crosshair in that window is (2000, 10), the initial rabbit and fox populations. At the beginning both the rabbit and fox populations increase. When they reach the point furthest to the right the rabbit population starts to decrease while the fox population continues to increase. As we continue along the curve it spirals inward indicating that the oscillation in the populations get smaller. In Exercise 6 on page 213 your find the point to which the spiral approaches. Figure 12.5: Rabbits and Foxes The pendulum revisited. A second order differential equation such as (15) can be reduced to a system of two first order equations. To do this we intro- 12.5. LABORATORY EXERCISES 211 duce a new variable w(t) = dθ/dt. Then (15) becomes θ0 = w (20) g w 0 = − sin θ l As an example suppose g/l = 25. Then to get an approximate solution of (15) we author and then approximate the following. (21) EXTRACT 2 COLUMNS( RK([w,-25 SIN(θ)], [t,θ,w], [0,θ0 ,0], 0.05, 60), 1, 2) Figure 12.6 on the next page shows the resulting graphs for θ0 = π/8, π/4, π/2, and 15π/16. The graph of the solution of (15), namely θ0 cos(5t), is also shown on each graph. Looking at these graphs we can see several things. First for θ0 = π/8 = 22.5◦ the curves are almost identical showing that using (5) rather than (15) works well for small and even moderate angles. Even for θ0 = π/4 = 45◦ , shown in the lower left, is fairly close to the true graph. Since we are considering a pendulum without friction (undamped) we expect that when we release it with an initial angle of θ0 it will swing to the other side reaching the angle θ = −θ0 and then return back to the original position with θ = θ0 . Then of course it will just repeat this. This means that the solution of (15) will be periodic. The linear approximation (5) has a shorter period than the true equation (15). This makes sense since the magnitude of the force pushing the pendulum back towards its rest position (θ = 0) is proportional to sin θ for the true equation and to θ in the linear approximation and sin θ ≤ θ for θ > 0. The lower right frame of Figure 12.6 on the following page gives the graphs when θ0 = 15π/16. This corresponds to starting the pendulum almost at the top. Notice that not only is the true period much greater than the linear approximation but that the shape of curve is different. 12.5 Laboratory Exercises The functions discussed in this chapter, DE2 and RK are defined once you Load in the file ADD-HEAD. 1. For each of the differential equations below solve the characteristic equation and enter the general solution with constants C1 , C2 . Verify CHAPTER 12. HARMONIC MOTION 212 Figure 12.6: Pendulums that the general solution satisfies the differential equationby computing the first and second derivatives and substituting into the equation. Show that Derive simplifies the resulting expression to zero. Use only real solutions to the equations. Finally, use the DE2 function to solve the differential equation using the same initial conditions: y(0) = 1 and y 0(0) = 2. Plot the solution. a. y 00 − 2y 0 − 8y = 0 b. y 00 = −4y 0 − 4y c. y 00 = −16y d. y 00 − 4y 0 + 5y = 0 2. A mass, with m = 1, is attached to a vertical spring. The mass stretches the spring by 2 feet as a result. With the mass attached, stretch the spring another 3 feet and release it. The spring will then oscillate up and down periodically. (Use g = 32 feet/sec2 to calculate k.) a. Find the differential equation that describes this motion. 12.5. LABORATORY EXERCISES 213 b. Find the vertical displacement function y(t) by using DE2 to solve the differential equation. c. Determine the period of the motion. 3. Show that if the characteristic equation (6) has a double root, that is, if r1 = r2 , then both y = er1 t and y = ter1 t satisfy (1) on page 196. 4. Hooke’s Law is given by equation 2 on page 196. a. Solve this with the initial conditions y0 = 0 and v0 = v. (You should use Derive’s Declare/Variable Domain to tell Derive that m and k are positive.) b. Graph your solutions with with k = 2, m = 1, and v varying between −2 and 2 in increments of 0.5. 5. A third order differential equation of the form y 000 + by 00 + cy 0 + dy = 0 has the characteristic equation r3 + br 2 + cr + d = 0. The roots of the characteristic equation determine the solutions of the differential equation in the same way as for second order differential equations. The solutions of second order differential equations involve two arbitrary constants but for third order there are three. a. Find the solutions to y 000 − 2y 00 − y 0 + 2y = 0. b. Find the solutions to y 000 − 2y 00 + y 0 − 2y = 0. c. Find the solutions to y 000 − 4y 00 + 5y 0 − 2y = 0. 6. Suppose we want to find solutions to (17) such that both R(t) and F (t) are constant. One (trivial) solution is R(t) = 0 = F (t) but we would like something more interesting than this. If the populations are constant then R0 (t) = 0 and F 0 (t) = 0. a. Solve (17) for R and F when R0 (t) = F 0 (t) = 0. Hint: Use the second equation of (17) to find R, substitute this into the first equation and then solve for F . CHAPTER 12. HARMONIC MOTION 214 b. The curve in the lower left window of Figure 12.5 on page 210 spirals inward. Use your answer from the previous part with the constants on page 209 to guess where it is heading. 7. Suppose in our rabbits and foxes example instead of (17) we use the simpler equations R0 = kR − cRF F 0 = dRF − eF without the Verhulst modification. a. In Figure 12.5 on page 210 we used RK and EXTRACT 2 COLUMNS to make 3 graphs. Make the same 3 graphs but using these simpler equations. Describe the differences between your graphs and those of Figure 12.5. b. Find the solutions which are constant as in the previous problem. 8. We saw in the lower right frame of Figure 12.6 on page 212 on page 212 that for θ0 = 15π/16 the solution to (15) and to the linear approximation (5) were quite different. In this exercise we will compare the solution to (15) with a cos function of the same amplitude and period. a. Author the expression (21) with θ0 = 15π/16 and then approximate it. Then graph the result. b. Using this graph estimate the period P of this function c. Graph 15π 16 cos( 2π t) using the P you found in the previous part. P d. Notice the graph you found in the first part is pretty flat at the top and bottom compared to the cos curve. What is the solution of (15) if θ0 = π (and w0 = 0, of course)? You should be able to just guess the solution. 9. In this problem we explore what happens to a pendulum with initial position θ0 = 0 but with a nonzero value for w0 . If the initial velocity is not too large the pendulum will swing up to an angle α and then swing back. The motion will be the same as if we started with θ0 = α 12.5. LABORATORY EXERCISES 215 and w0 = 0 except that starting place for the graph will be different. That is, the curves will be the same except one will be shifted to the right. However if w0 is large enough, the pendulum will swing all the way over the top. a. Author EXTRACT 2 COLUMNS( RK([w,-25 SIN(θ)],[t,θ,w],[0,0,w0 ],.05,60),1,2) Substitute w0 = 9.5 and approximate and then graph the result. Do the same for w0 = 10 and w0 = 10.5. b. The behavior of the solutions of the previous part are quite different depending on whether w0 is large enough to send the pendulum over the top (so it keeps spinning around and around) or it doesn’t make it to the top and so falls back. In this problem we look for a value of w0 so that it never falls back but also never goes over the top. We will try to choose w0 so that it will have the exact amount of energy to just get to the top. Since we are assuming our pendulum is frictionless, there are two kinds of energy in our system, kinetic and potential energy. Kinetic energy is 12 mv 2 which in our case is 12 m(ds/dt)2 = 12 ml(dθ/dt)2 . Potential energy gained as the pendulum swings above its rest position is mgh where h is the height above the rest position. So the potential energy at the top is 2mgl. Use the law of conservation of energy to show that if the kinetic energy at the bottom equals the potential energy at the top then r g 0 w0 = θ (0) = 2 l which is 10 when g/l = 25. c. While the solution to (15) on page 206 cannot be expressed in terms of p elementary functions, the solution when θ(0) = 0 and 0 θ (0) = 2 gl can. Show that √g θ(t) = 4 arctan(e l t ) − π 216 CHAPTER 12. HARMONIC MOTION p is a solution of (15) and that θ0 (0) = 2 gl . You will need set the trigonometry mode to Expand under the Declare/Algebra StateSimplification menu. Also remember that Derive uses ATAN for the arctan function. d. When g/l = 25, θ(t) = 4 arctan(e5t ) − π. Graph this function and compare it with the graph you made in the first part with w0 = 10. Also graph EXTRACT 2 COLUMNS( RK([w,-25 SIN(θ)],[t,θ,w],[0,0,10],.01,500),1,2) e. Why do these graphs differ? Appendix A Utility Files This book defines 19 Derive functions. All of these functions are defined in the utility file ADD-UTIL which is quietly loaded; which means the formulas are not displayed, whenever you load the file ADD-HEAD. This file and its companion, ADD-HEAD, can be downloaded from our web page http://www.math.hawaii.edu/lab/ Listings of these files are given at the end of this appendix in the (hopefully unlikely) event you have trouble downloading them. Additional information on the use of the functions as well as examples are included on the web site above. How to use these files. When a student first starts to work on a lab assignment he should: 1. Enter (Author) his name and the lab number as a comment. (Comments are entered using the double quotes, ".) 2. Do File/Load/Math add-head. 3. Begin working on his assignment. The file ADD-HEAD has only four lines. Two of these are comments and one gives the variable syntax for the commands. The other line is LOAD("add-util"). This automatically silently loads ADD-UTIL.1 . For 1 This assumes that this file is in the default directory. A default directory should be established and all F-*.MTH files placed in that directory along with ADD-HEAD and ADD-UTIL 217 APPENDIX A. UTILITY FILES 218 this load command directory to work correctly, ADD-HEAD and ADD-UTIL should both be in the current directory. It is best to put them in the default directory. Home use of these files. If you have Derive for your own computer you can install ADD-HEAD and ADD-UTIL. When Derive starts it has a default directory it looks for MTH files. If you haven’t changed this it is ..\DfW\Math. That directory contains the utility files that come with the system. You should add a new subdirectory, such as ..\DfW\Lab, using the Windows file manager and then make that your default directory using the File/Change Directory command in DfW. Next, you put both ADD-UTIL and ADD-HEAD in this default directory and the above directions should work fine. You should also add all the F-*.MTH files that are used in the book’s figures to this directory. All of these files are available from our web site. A.1 The Functions Table A.1 on page 221 and A.2 on page 222 list the functions defined in ADD-UTIL. In each of the examples below it is assumed that the utility file ADD-UTIL has been loaded as described above. Here are some examples on their use. Example 1. If you want to compute a tangent line for say f (x) = x3 /3 at the point x = 1 you would Author and Simplify TANGENT(x^3/3, x, 1). The result will be y = x − 2/3. We describe the variables for this and the other functions typically as TANGENT( u, x, a) where the u refers to any expression in the variable x and a is a parameter in the function which in this case it is the point we are interested in. Example 2. Suppose that you want to find the quadratic polynomial ax2 + bx + c that passes through the three points (0, 0), (1, 2), and (2, 8). You Author CURVEFIT( x, [[0,1], [1,2], [2,8]]). After simplifying the result will be 2x2 . Probably the best way to do this is to start by defining the 3 × 2 matrix of points using the matrix button and then plotting the 3 points on a graph. Next you Author the CURVEFIT(x, part and then right click and insert the matrix of data points. Simplify and plot to make sure the answer function does indeed pass through the 3 data points. The A.1. THE FUNCTIONS 219 CURVEFIT function will find the appropriate degree polynomial through the data regardless of the number of points. Example 3. Suppose that now that you want to find the quadratic polynomial ax2 + bx + c that passes through the two points: (0,0) and (1,2). In addition, you want the derivative to be 1 when x = 0. You Author CURVEFIT( x, [[0,1], [1,2]], [[0,1]]). In other words, you enter one matrix for the points satisfied by the function and another matrix for the points satisfied by the derivative. The degree of the answer polynomial is always one less than the total number of equations for both the function and its derivative. Example 4. Let’s solve the equation x2 + x − 1 = 0 using Newton’s method of Chapter 5. We’ll use x0 = 5 as our initial guess. We obtain our first approximation by Authoring NEWT(x^2+x-1, x, 5) and then Simplifying to get 2.63263. We repeat this process using this new value as our starting point. After 4–5 iterations we obtain an approximation we good to 6 decimal places. Example 5. More generally, to approximate the solution to the equation u = 0, where u is an expression in x, using Newton’s method with initial guess a you author and approximate NEWT(u, x, a). Suppose instead that you want the first k approximates starting with x = a, then you approximate NEWT(u, x, a, k). The 4th argument is optional. You get a nice picture of the Newton method in action by approximating DRAW NEWT(u, x, a, k) and then plotting the result. Notice that the starting point can be a complex number in which case the approximates are also complex. The function DRAW COMPLEX(v) can be applied to the solution vector to get a matrix of [x, y] points which can then be plotted in a 2D-plot window. Example 6. Suppose that you want to approximate the integral which defines the natural logarithm of 2, i.e., Z 2 dx ln 2 = x 1 using say the trapezoid rule or Simpson’s rule for numerical integration. We do this for n = 100 subdivisions by Authoring either the expression TRAP(1/x, x, 100, 1, 2) or the expression SIMP(1/x, x, 100, 1, 2). Now since we are interested in a decimal approximation we use the button to simplify the expression. More generally, suppose you approximate 220 APPENDIX A. UTILITY FILES the integral of the expression u, in the variable x over the interval [a, b], using Simpson’s rule with n subdivisions. You Author SIMP(u,x,n,a,b) and press . Example 7. Suppose that you want to solve a Newton cooling type differential equation: y 0 = −(y − 2) with initial conditions y(0) = 4. You start by manipulating the equation to the form y 0 + py = q where p = 1 and q = 2. The function DE(p,q,x,y,x0,y0) solves this equation so we just substitute in the right values which in this case means that we Author DE(1,2,x,y,0,4) . and press Example 8. Suppose that you want to look at the direction field for the equation y 0 = r where r is an expression in x and y. You use the function DF(r,x,x0,xm,m,y,y0,yn,n)) where the grid of points is determined by x0 < x < xm with m subdivisions and y0 < y < yn with n subdivsions. Doing this for the previous example would mean Authoring say DF(-(y-2),x,0,6,12,y,-2,4,12) and then ap. You get a graph with a slope proximating the expression by pressing line at every half integer in an appropriate range of x and y’s by plotting the result. A.1. THE FUNCTIONS 221 Table A.1: Functions Defined in ADD-UTIL.MTH SUBST(u, x, a) Substitutes x = a in the expression u. SECANT(u, x, a, h) Secant line of u(x) through x = a and x = a + h. Tangent line of u(x) at x = a. TANGENT(u, x, a) CURVEFIT(x, data) CURVEFIT(x, data, ddata) NEWT(u, x, x0) NEWT(u, x, x0, k) DRAW NEWT(u, x, x0, k) DRAW COMPLEX(v) BISECT(u, x, v) BISECT(u, x, v, k) LEFT(u, x, n, a, b) MID(u, x, n, a, b) Fits a polynomial in the variable x, though the points data := [[x0, y0], [x1, y1], ...] provided ddata is either omitted or []. Otherwise, the graph of the derivative must pass through the ddata points. Newton algorithm for root of u(x) = 0 with initial guess x0. If the optional k argument is used then a vector of k iterates is returned. Draws a picture of Newton method applied to u(x) = 0 with initial guess x0 and k iterates. Simplify expression and plot the result. Converts the vector of complex numbers [x0 + iy0, x1 + iy1, ...] into a matrix of points [[x0, y0], [x1, y1], ...] which can then be plotted in a 2D-plot window. Bisection method for solving u(x) = 0 with interval v = [a, b]. The answer is either the left or right half of the interval depending on the root. If the optional k argument is used then a vector of k iterates is returned. Numerical approximation to the integral of u(x) over [a, b] using the left-endpoint method with n rectangles. Numerical approximation to the integral of u(x) over [a, b] using the midpoint method with n rectangles. APPENDIX A. UTILITY FILES 222 Table A.2: Functions Defined in ADD-UTIL.MTH (cont.) RIGHT(u, x, n, a, b) TRAP(u, x, n, a, b) SIMP(u, x, n, a, b) DRAW LEFT(u, x, n, a, b) DRAW RIGHT(u, x, n, a, b) DRAW TRAP(u, x, n, a, b) DE(p, q, x, y, x0, y0) DF(r, x, x0, xm, m, y, y0, yn, n) EULER(r, x, y, x0, y0, xn, n) Numerical approximation to the integral of u(x) over [a, b] using the right-endpoint method with n rectangles. Numerical approximation to the integral of u(x) over [a, b] using the trapezoid method with n trapezoids. Numerical approximation to the integral of u(x) over [a, b] using Simpson’s method with n subdivisions. Draws graphic demonstration of the leftendpoint method for numerically integrating u(x) over the interval [a, b] using n rectangles. Same as above except for the rightendpoint method. Draws graphic demonstration of the trapezoid method for numerically integrating u(x) over the interval [a, b] using n trapezoids. Solves the differential equation (DE) y 0 + p(x)y = q(x) with y(x0) = y0. The direction field (DF) for the differential equation: y 0 = r(x, y) with a grid determined by x0 < x < xm with m subdivisions and y0 < y < ym with n subdivisions. This gives an approximate solution to: y 0 = r(x, y) with y(x0) = y0. The answer is a vector of points [[x0, y0], [x1, y1], ...] from which one makes a piecewise linear approximating function, i.e., connect the points with straight line segments to get the approximating function’s graph. A.2. LISTINGS OF THE UTILITY FILES A.2 223 Listings of the Utility Files In the event you are unable to download these files, you can type them in. Probably the easiest way to do this is to start Derive and author each line. Then save the first as add-head and the second as add-util. A.2.1 The ADD-HEAD.MTH File "The vector below declares all the utility functions in add-util.mth." [SUBST(u,x,a):=,SECANT(u,x,a,h):=,TANGENT(u,x,a):=,CURVEFIT(x,data):=,SPLINE(~ x,data,m1):=,NEWT(u,x,x0,k):=,DRAW_NEWT(u,x,x0,k):=,DRAW_COMPLEX(v):=,BISECT(~ u,x,v0,k):=,LEFT(u,x,n,a,b):=,MID(u,x,n,a,b):=,RIGHT(u,x,n,a,b):=,TRAP(u,x,n,~ a,b):=,SIMP(u,x,n,a,b):=,DRAW_LEFT(u,x,n,a,b):=,DRAW_TRAP(u,x,n,a,b):=,DE(p,q~ ,x,y,x0,y0):=,DF(r,x,x0,xm,m,y,y0,yn,n):=,EULER(r,x,y,x0,y0,xn,n):=] LOAD("add-util") "Your file starts here:" A.2.2 The ADD-UTIL.MTH File "File add-util.mth, (c) 1997 Ralph Freese and David Stegenga." "See add-summary.mth for a summary of new functions defined below:" "Substitute x=a into the expression u." SUBST(u,x,a):=LIM(u,x,a) "The secant line of u(x) through x = a and x = a + h." SECANT(u,x,a,h):=y=(SUBST(u,x,a+h)-SUBST(u,x,a))/h*(x-a)+SUBST(u,x,a) "The tangent line of u(x) at x = a." TANGENT(u,x,a):=y=SUBST(u,x,a)+SUBST(DIF(u,x),x,a)*(x-a) "Helper functions for CURVEFIT." POLY(x,a,n):=SUM(a SUB (i+1)*x^i,i,0,n) DPOLY(x,a,n):=SUM(i*a SUB (i+1)*x^(i-1),i,1,n) EQNS(data,ddata,a,n):=APPEND(VECTOR(POLY(data SUB i SUB 1,a,n)=data SUB i SUB~ 2,i,1,DIMENSION(data),1),VECTOR(DPOLY(ddata SUB i SUB 1,a,n)=ddata SUB i SUB~ 2,i,1,DIMENSION(ddata),1)) UNK(n):=RHS(VECTOR(SOLVE(upsilon=upsilon,upsilon),i,1,n,1)‘ SUB 1) 224 APPENDIX A. UTILITY FILES ANS(x,data,ddata,a,n):=IF(DIMENSION(ans_:=SOLVE(EQNS(data,ddata,a,n),[a]))=0,~ [],POLY(x,(RHS(ans_)) SUB 1,n)) "Finds the polynomial of the right degree through the nx2-data matrix." CURVEFIT1(x,data):=ANS(x,data,[],UNK(DIMENSION(data)),DIMENSION(data)-1) CURVEFIT2(x,data,ddata):=ANS(x,data,ddata,UNK(DIMENSION(data)+DIMENSION(ddata~ )),DIMENSION(data)+DIMENSION(ddata)-1) CURVEFIT(x,data,ddata):=IF(DIMENSION(ddata)>0,CURVEFIT2(x,data,ddata),CURVEFI~ T1(x,data),CURVEFIT1(x,data)) "Quadratic spline function interpolating data points with initial slope m1." SPLINE_AUX(x,data,m):=SUM(CURVEFIT(x,[data SUB k,data SUB (k+1)],[[data SUB k~ SUB 1,m SUB k SUB 2]])*CHI(data SUB k SUB 1,x,data SUB (k+1) SUB 1),k,1,DIME~ NSION(data)-1) SLOPE(data,m1):=ITERATES([v SUB 1+1,2*(data SUB (v SUB 1+1) SUB 2-data SUB (v~ SUB 1) SUB 2)/(data SUB (v SUB 1+1) SUB 1-data SUB (v SUB 1) SUB 1)-v SUB 2]~ ,v,[1,m1],DIMENSION(data)-1) "Note that SLOPE returns the matrix [[1,m1], [2,m2], ...]." SPLINE(x,data,m1):=SPLINE_AUX(x,data,SLOPE(data,m1)) "Newton algorithm" NEWT_ITERATES(u,x,x0,k):=ITERATES(x-u/DIF(u,x),x,x0,k) NEWT(u,x,x0,k):=IF(k>0,NEWT_ITERATES(u,x,x0,k),?,SUBST(x-u/DIF(u,x),x,x0)) "This produces a vector which when plotted demonstrates Newton’s method." DRAW_NEWT(u,x,x0,k):=VECTOR([[v,0],[v,SUBST(u,x,v)],[NEWT(u,x,v),0]],v,ITERAT~ ES(NEWT(u,x,w),w,x0,k)) DRAW_COMPLEX(v):=VECTOR([RE(z),IM(z)],z,v) "Bisection method helper" BIS_AUX(u,x,a,b):=IF(SUBST(u,x,a)*SUBST(u,x,(a+b)/2)<0,[a,(a+b)/2],[(a+b)/2,b~ ]) "Bisection method" BISECT(u,x,v0,k):=IF(k>0,ITERATES(BIS_AUX(u,x,v SUB 1,v SUB 2),v,v0,k),?,BIS_~ AUX(u,x,v0 SUB 1,v0 SUB 2)) "Formula for the left-endpoint method for integrating u(x) over [a,b] with n ~ subdivisions." LEFT(u,x,n,a,b):=(b-a)/n*SUM(SUBST(u,x,a+k*(b-a)/n),k,0,n-1) "Formula for the midpoint method for integrating u(x) over [a,b] with n subdi~ A.2. LISTINGS OF THE UTILITY FILES 225 visions." MID(u,x,n,a,b):=(b-a)/n*SUM(SUBST(u,x,a+(k+0.5)*(b-a)/n),k,0,n-1) "Formula for the right-endpoint method for integrating u(x) over [a,b] with n~ subdivisions." RIGHT(u,x,n,a,b):=(b-a)/n*SUM(SUBST(u,x,a+k*(b-a)/n),k,1,n) "Formula for the trapezoid method for integrating u(x) over [a,b] with n subd~ ivisions." TRAP(u,x,n,a,b):=(b-a)/(2*n)*(SUBST(u,x,a)+SUBST(u,x,b)+2*SUM(SUBST(u,x,a+k*(~ b-a)/n),k,1,n-1)) "Formula for Simpson’s rule for integrating u(x) over [a,b] with n subdivisio~ ns." SIMP(u,x,n,a,b):=(b-a)/(6*n)*(SUBST(u,x,a)+SUBST(u,x,b)+2*SUM(SUBST(u,x,a+k*(~ b-a)/n),k,1,n-1)+4*SUM(SUBST(u,x,a+(k+1/2)*(b-a)/n),k,0,n-1)) "The box and trapezoid drawing functions used in the graphical demonstrations~ of numerical integration techniques." D_BOX(x1,y1,x2,y2):=[[x1,y1],[x2,y1],[x2,y2],[x1,y2],[x1,y1]] D_TRAP(x1,y1,x2,y2,x3,y3,x4,y4):=[[x1,y1],[x2,y2],[x3,y3],[x4,y4],[x1,y1]] DRAW_LEFT(u,x,n,a,b):=VECTOR(D_BOX(t,0,t+(b-a)/n,SUBST(u,x,t)),t,a,b-(b-a)/n,~ (b-a)/n) DRAW_RIGHT(u,x,n,a,b):=VECTOR(D_BOX(t,0,t+(b-a)/n,SUBST(u,x,t+(b-a)/n)),t,a,b~ -(b-a)/n,(b-a)/n) DRAW_TRAP(u,x,n,a,b):=VECTOR(D_TRAP(t,0,t+(b-a)/n,0,t+(b-a)/n,SUBST(u,x,t+(b-~ a)/n),t,SUBST(u,x,t)),t,a,b-(b-a)/n,(b-a)/n) "The solution to the differential equation (DE) y’+p(x)y=q(x) with y(x0)=y0." DE(p,q,x,y,x0,y0):=y=(y0+INT(q*#e^INT(p,x,x0,x),x,x0,x))/#e^INT(p,x,x0,x) "Direction field helper function." SEG(rc,x,y,x,y):=IF(ABS(rc)>1 AND y
Source Exif Data:File Type : PDF File Type Extension : pdf MIME Type : application/pdf PDF Version : 1.2 Linearized : No Page Count : 248 Create Date : 1910:10:50 71:20:82 Producer : Acrobat Distiller Command 3.0 for Solaris 2.3 and later (SPARC) Creator : dvips(k) 5.85 Copyright 1999 Radical Eye Software Title : main-rev.dviEXIF Metadata provided by EXIF.tools