Numerical Methods for Engineers
SEVENTH EDITION
Steven C. Chapra Berger Chair in Computing and Engineering
Tufts University
Raymond P. Canale Professor Emeritus of Civil Engineering
University of Michigan
cha9792x_fm_i_xvi.indd Page i 22/11/13 6:42 PM F-468 cha9792x_fm_i_xvi.indd Page i 22/11/13 6:42 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
NUMERICAL METHODS FOR ENGINEERS, SEVENTH EDITION
Published by McGraw-Hill Education, 2 Penn Plaza, New York, NY 10121. Copyright © 2015 by McGraw-Hill Education. All rights reserved. Printed in the United States of America. Previous editions © 2010, 2006, and 2002. No part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written consent of McGraw-Hill Education, including, but not limited to, in any network or other electronic storage or transmission, or broadcast for distance learning.
Some ancillaries, including electronic and print components, may not be available to customers outside the United States.
This book is printed on acid-free paper.
1 2 3 4 5 6 7 8 9 0 DOC/DOC 1 0 9 8 7 6 5 4
ISBN 978–0–07–339792–4 MHID 0–07–339792–x
Senior Vice President, Products & Markets: Kurt L. Strand Vice President, General Manager, Products & Markets: Marty Lange Vice President, Content Production & Technology Services: Kimberly Meriwether David Executive Brand Manager: Bill Stenquist Managing Director: Thomas Timp Global Publisher: Raghothaman Srinivasan Developmental Editor: Lorraine Buczek Marketing Manager: Heather Wagner Director, Content Production: Terri Schiesl Senior Content Project Manager: Melissa M. Leick Buyer: Jennifer Pickel Cover Designer: Studio Montage, St. Louis, MO Cover Image: Peak towering above clouds: Royalty-Free/CORBIS; Skysurfers: Getty Images/Digital Vision/RF Media Project Manager: Sandra M. Schnee Compositor: Aptara®, Inc. Typeface: 10/12 Time Roman Printer: R. R. Donnelley
All credits appearing on page or at the end of the book are considered to be an extension of the copyright page.
Library of Congress Cataloging-in-Publication Data
Chapra, Steven C. Numerical methods for engineers / Steven C. Chapra, Berger chair in computing and engineering, Tufts University, Raymond P. Canale, professor emeritus of civil engineering, University of Michigan. — Seventh edition. pages cm Includes bibliographical references and index. ISBN 978-0-07-339792-4 (alk. paper) — ISBN 0-07-339792-X (alk. paper) 1. Engineering mathematics—Data processing. 2. Numerical calculations—Data processing 3. Microcomputers—Programming. I. Canale, Raymond P. II. Title. TA345.C47 2015 518.024’62—dc23 2013041704
cha9792x_fm_i_xvi.indd Page ii 22/11/13 6:42 PM F-468 cha9792x_fm_i_xvi.indd Page ii 22/11/13 6:42 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
To
Margaret and Gabriel Chapra
Helen and Chester Canale
cha9792x_fm_i_xvi.indd Page iii 22/11/13 6:42 PM F-468 cha9792x_fm_i_xvi.indd Page iii 22/11/13 6:42 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
iv
CONTENTS
PREFACE xiv
ABOUT THE AUTHORS xvi
PART ONE
MODELING, PT1.1 Motivation 3 COMPUTERS, AND PT1.2 Mathematical Background 5 ERROR ANALYSIS 3 PT1.3 Orientation 8
CHAPTER 1 Mathematical Modeling and Engineering Problem Solving 11
1.1 A Simple Mathematical Model 11 1.2 Conservation Laws and Engineering 18 Problems 21
CHAPTER 2 Programming and Software 27
2.1 Packages and Programming 27 2.2 Structured Programming 28 2.3 Modular Programming 37 2.4 Excel 39 2.5 MATLAB 43 2.6 Mathcad 47 2.7 Other Languages and Libraries 48 Problems 49
CHAPTER 3 Approximations and Round-Off Errors 55
3.1 Signifi cant Figures 56 3.2 Accuracy and Precision 58 3.3 Error Defi nitions 59 3.4 Round-Off Errors 65 Problems 79
cha9792x_fm_i_xvi.indd Page iv 22/11/13 6:42 PM F-468 cha9792x_fm_i_xvi.indd Page iv 22/11/13 6:42 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
CONTENTS v
CHAPTER 4 Truncation Errors and the Taylor Series 81
4.1 The Taylor Series 81 4.2 Error Propagation 97 4.3 Total Numerical Error 101 4.4 Blunders, Formulation Errors, and Data Uncertainty 106 Problems 108
EPILOGUE: PART ONE 110 PT1.4 Trade-Offs 110 PT1.5 Important Relationships and Formulas 113 PT1.6 Advanced Methods and Additional References 113
PART TWO
ROOTS OF PT2.1 Motivation 117 EQUATIONS 117 PT2.2 Mathematical Background 119
PT2.3 Orientation 120
CHAPTER 5 Bracketing Methods 123
5.1 Graphical Methods 123 5.2 The Bisection Method 127 5.3 The False-Position Method 135 5.4 Incremental Searches and Determining Initial Guesses 141 Problems 142
CHAPTER 6 Open Methods 145
6.1 Simple Fixed-Point Iteration 146 6.2 The Newton-Raphson Method 151 6.3 The Secant Method 157 6.4 Brent’s Method 162 6.5 Multiple Roots 166 6.6 Systems of Nonlinear Equations 169 Problems 173
CHAPTER 7 Roots of Polynomials 176
7.1 Polynomials in Engineering and Science 176 7.2 Computing with Polynomials 179 7.3 Conventional Methods 182
cha9792x_fm_i_xvi.indd Page v 22/11/13 6:42 PM F-468 cha9792x_fm_i_xvi.indd Page v 22/11/13 6:42 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
vi CONTENTS
7.4 Müller’s Method 183 7.5 Bairstow’s Method 187 7.6 Other Methods 192 7.7 Root Location with Software Packages 192 Problems 202
CHAPTER 8 Case Studies: Roots of Equations 204
8.1 Ideal and Nonideal Gas Laws (Chemical/Bio Engineering) 204 8.2 Greenhouse Gases and Rainwater (Civil/Environmental Engineering) 207 8.3 Design of an Electric Circuit (Electrical Engineering) 209 8.4 Pipe Friction (Mechanical/Aerospace Engineering) 212 Problems 215
EPILOGUE: PART TWO 226 PT2.4 Trade-Offs 226 PT2.5 Important Relationships and Formulas 227 PT2.6 Advanced Methods and Additional References 227
PART THREE
LINEAR ALGEBRAIC PT3.1 Motivation 231 EQUATIONS 231 PT3.2 Mathematical Background 233
PT3.3 Orientation 241
CHAPTER 9 Gauss Elimination 245
9.1 Solving Small Numbers of Equations 245 9.2 Naive Gauss Elimination 252 9.3 Pitfalls of Elimination Methods 258 9.4 Techniques for Improving Solutions 264 9.5 Complex Systems 271 9.6 Nonlinear Systems of Equations 271 9.7 Gauss-Jordan 273 9.8 Summary 275 Problems 275
CHAPTER 10 LU Decomposition and Matrix Inversion 278 10.1 LU Decomposition 278 10.2 The Matrix Inverse 287 10.3 Error Analysis and System Condition 291 Problems 297
cha9792x_fm_i_xvi.indd Page vi 22/11/13 6:42 PM F-468 cha9792x_fm_i_xvi.indd Page vi 22/11/13 6:42 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
CONTENTS vii
CHAPTER 11 Special Matrices and Gauss-Seidel 300
11.1 Special Matrices 300 11.2 Gauss-Seidel 304 11.3 Linear Algebraic Equations with Software Packages 311 Problems 316
CHAPTER 12 Case Studies: Linear Algebraic Equations 319
12.1 Steady-State Analysis of a System of Reactors (Chemical/Bio Engineering) 319 12.2 Analysis of a Statically Determinate Truss (Civil/Environmental Engineering) 322 12.3 Currents and Voltages in Resistor Circuits (Electrical Engineering) 326 12.4 Spring-Mass Systems (Mechanical/Aerospace Engineering) 328 Problems 331
EPILOGUE: PART THREE 341 PT3.4 Trade-Offs 341 PT3.5 Important Relationships and Formulas 342 PT3.6 Advanced Methods and Additional References 342
PART FOUR
OPTIMIZATION 345 PT4.1 Motivation 345 PT4.2 Mathematical Background 350 PT4.3 Orientation 351
CHAPTER 13 One-Dimensional Unconstrained Optimization 355
13.1 Golden-Section Search 356 13.2 Parabolic Interpolation 363 13.3 Newton’s Method 365 13.4 Brent’s Method 366 Problems 368
CHAPTER 14 Multidimensional Unconstrained Optimization 370
14.1 Direct Methods 371 14.2 Gradient Methods 375 Problems 388
cha9792x_fm_i_xvi.indd Page vii 22/11/13 6:42 PM F-468 cha9792x_fm_i_xvi.indd Page vii 22/11/13 6:42 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
viii CONTENTS
CHAPTER 15 Constrained Optimization 390
15.1 Linear Programming 390 15.2 Nonlinear Constrained Optimization 401 15.3 Optimization with Software Packages 402 Problems 413
CHAPTER 16 Case Studies: Optimization 416
16.1 Least-Cost Design of a Tank (Chemical/Bio Engineering) 416 16.2 Least-Cost Treatment of Wastewater (Civil/Environmental Engineering) 421 16.3 Maximum Power Transfer for a Circuit (Electrical Engineering) 425 16.4 Equilibrium and Minimum Potential Energy (Mechanical/Aerospace Engineering) 429 Problems 431
EPILOGUE: PART FOUR 438 PT4.4 Trade-Offs 438 PT4.5 Additional References 439
PART FIVE
CURVE FITTING 441 PT5.1 Motivation 441 PT5.2 Mathematical Background 443 PT5.3 Orientation 452
CHAPTER 17 Least-Squares Regression 456
17.1 Linear Regression 456 17.2 Polynomial Regression 472 17.3 Multiple Linear Regression 476 17.4 General Linear Least Squares 479 17.5 Nonlinear Regression 483 Problems 487
CHAPTER 18 Interpolation 490
18.1 Newton’s Divided-Difference Interpolating Polynomials 491 18.2 Lagrange Interpolating Polynomials 502 18.3 Coeffi cients of an Interpolating Polynomial 507 18.4 Inverse Interpolation 507 18.5 Additional Comments 508 18.6 Spline Interpolation 511 18.7 Multidimensional Interpolation 521 Problems 524
cha9792x_fm_i_xvi.indd Page viii 22/11/13 6:42 PM F-468 cha9792x_fm_i_xvi.indd Page viii 22/11/13 6:42 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
CONTENTS ix
CHAPTER 19 Fourier Approximation 526
19.1 Curve Fitting with Sinusoidal Functions 527 19.2 Continuous Fourier Series 533 19.3 Frequency and Time Domains 536 19.4 Fourier Integral and Transform 540 19.5 Discrete Fourier Transform (DFT) 542 19.6 Fast Fourier Transform (FFT) 544 19.7 The Power Spectrum 551 19.8 Curve Fitting with Software Packages 552 Problems 561
CHAPTER 20 Case Studies: Curve Fitting 563
20.1 Linear Regression and Population Models (Chemical/Bio Engineering) 563 20.2 Use of Splines to Estimate Heat Transfer (Civil/Environmental Engineering) 567 20.3 Fourier Analysis (Electrical Engineering) 569 20.4 Analysis of Experimental Data (Mechanical/Aerospace Engineering) 570 Problems 572
EPILOGUE: PART FIVE 582 PT5.4 Trade-Offs 582 PT5.5 Important Relationships and Formulas 583 PT5.6 Advanced Methods and Additional References 584
PART SIX
NUMERICAL PT6.1 Motivation 587 DIFFERENTIATION PT6.2 Mathematical Background 597 AND PT6.3 Orientation 599 INTEGRATION 587
CHAPTER 21 Newton-Cotes Integration Formulas 603
21.1 The Trapezoidal Rule 605 21.2 Simpson’s Rules 615 21.3 Integration with Unequal Segments 624 21.4 Open Integration Formulas 627 21.5 Multiple Integrals 627 Problems 629
cha9792x_fm_i_xvi.indd Page ix 22/11/13 6:42 PM F-468 cha9792x_fm_i_xvi.indd Page ix 22/11/13 6:42 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
x CONTENTS
CHAPTER 22 Integration of Equations 633
22.1 Newton-Cotes Algorithms for Equations 633 22.2 Romberg Integration 634 22.3 Adaptive Quadrature 640 22.4 Gauss Quadrature 642 22.5 Improper Integrals 650 Problems 653
CHAPTER 23 Numerical Differentiation 655
23.1 High-Accuracy Differentiation Formulas 655 23.2 Richardson Extrapolation 658 23.3 Derivatives of Unequally Spaced Data 660 23.4 Derivatives and Integrals for Data with Errors 661 23.5 Partial Derivatives 662 23.6 Numerical Integration/Differentiation with Software Packages 663 Problems 670
CHAPTER 24 Case Studies: Numerical Integration and Differentiation 673
24.1 Integration to Determine the Total Quantity of Heat (Chemical/Bio Engineering) 673
24.2 Effective Force on the Mast of a Racing Sailboat (Civil/Environmental Engineering) 675
24.3 Root-Mean-Square Current by Numerical Integration (Electrical Engineering) 677
24.4 Numerical Integration to Compute Work (Mechanical/Aerospace Engineering) 680
Problems 684
EPILOGUE: PART SIX 694 PT6.4 Trade-Offs 694 PT6.5 Important Relationships and Formulas 695 PT6.6 Advanced Methods and Additional References 695
PART SEVEN
ORDINARY PT7.1 Motivation 699 DIFFERENTIAL PT7.2 Mathematical Background 703 EQUATIONS 699 PT7.3 Orientation 705
cha9792x_fm_i_xvi.indd Page x 22/11/13 6:42 PM F-468 cha9792x_fm_i_xvi.indd Page x 22/11/13 6:42 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
CONTENTS xi
CHAPTER 25 Runge-Kutta Methods 709
25.1 Euler’s Method 710 25.2 Improvements of Euler’s Method 721 25.3 Runge-Kutta Methods 729 25.4 Systems of Equations 739 25.5 Adaptive Runge-Kutta Methods 744 Problems 752
CHAPTER 26 Stiffness and Multistep Methods 755
26.1 Stiffness 755 26.2 Multistep Methods 759 Problems 779
CHAPTER 27 Boundary-Value and Eigenvalue Problems 781
27.1 General Methods for Boundary-Value Problems 782 27.2 Eigenvalue Problems 789 27.3 Odes and Eigenvalues with Software Packages 801 Problems 808
CHAPTER 28 Case Studies: Ordinary Differential Equations 811
28.1 Using ODEs to Analyze the Transient Response of a Reactor (Chemical/Bio Engineering) 811
28.2 Predator-Prey Models and Chaos (Civil/Environmental Engineering) 818 28.3 Simulating Transient Current for an Electric Circuit (Electrical Engineering) 822 28.4 The Swinging Pendulum (Mechanical/Aerospace Engineering) 827 Problems 831
EPILOGUE: PART SEVEN 841 PT7.4 Trade-Offs 841 PT7.5 Important Relationships and Formulas 842 PT7.6 Advanced Methods and Additional References 842
PART EIGHT
PARTIAL PT8.1 Motivation 845 DIFFERENTIAL PT8.2 Orientation 848 EQUATIONS 845
cha9792x_fm_i_xvi.indd Page xi 22/11/13 6:42 PM F-468 cha9792x_fm_i_xvi.indd Page xi 22/11/13 6:42 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
xii CONTENTS
CHAPTER 29 Finite Difference: Elliptic Equations 852
29.1 The Laplace Equation 852 29.2 Solution Technique 854 29.3 Boundary Conditions 860 29.4 The Control-Volume Approach 866 29.5 Software to Solve Elliptic Equations 869 Problems 870
CHAPTER 30 Finite Difference: Parabolic Equations 873
30.1 The Heat-Conduction Equation 873 30.2 Explicit Methods 874 30.3 A Simple Implicit Method 878 30.4 The Crank-Nicolson Method 882 30.5 Parabolic Equations in Two Spatial Dimensions 885 Problems 888
CHAPTER 31 Finite-Element Method 890
31.1 The General Approach 891 31.2 Finite-Element Application in One Dimension 895 31.3 Two-Dimensional Problems 904 31.4 Solving PDEs with Software Packages 908 Problems 912
CHAPTER 32 Case Studies: Partial Differential Equations 915
32.1 One-Dimensional Mass Balance of a Reactor (Chemical/Bio Engineering) 915
32.2 Defl ections of a Plate (Civil/Environmental Engineering) 919 32.3 Two-Dimensional Electrostatic Field Problems (Electrical
Engineering) 921 32.4 Finite-Element Solution of a Series of Springs
(Mechanical/Aerospace Engineering) 924 Problems 928
EPILOGUE: PART EIGHT 931 PT8.3 Trade-Offs 931 PT8.4 Important Relationships and Formulas 931 PT8.5 Advanced Methods and Additional References 932
cha9792x_fm_i_xvi.indd Page xii 22/11/13 6:42 PM F-468 cha9792x_fm_i_xvi.indd Page xii 22/11/13 6:42 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
CONTENTS xiii
APPENDIX A: THE FOURIER SERIES 933
APPENDIX B: GETTING STARTED WITH MATLAB 935
APPENDIX C: GETTING STARTED WITH MATHCAD 943
BIBLIOGRAPHY 954
INDEX 957
cha9792x_fm_i_xvi.indd Page xiii 22/11/13 6:42 PM F-468 cha9792x_fm_i_xvi.indd Page xiii 22/11/13 6:42 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
xiv
PREFACE
It has been over twenty years since we published the fi rst edition of this book. Over that period, our original contention that numerical methods and computers would fi gure more prominently in the engineering curriculum—particularly in the early parts—has been dra- matically borne out. Many universities now offer freshman, sophomore, and junior courses in both introductory computing and numerical methods. In addition, many of our colleagues are integrating computer-oriented problems into other courses at all levels of the curriculum. Thus, this new edition is still founded on the basic premise that student engineers should be provided with a strong and early introduction to numerical methods. Consequently, although we have expanded our coverage in the new edition, we have tried to maintain many of the features that made the fi rst edition accessible to both lower- and upper-level undergraduates. These include:
• Problem Orientation. Engineering students learn best when they are motivated by problems. This is particularly true for mathematics and computing. Consequently, we have approached numerical methods from a problem-solving perspective.
• Student-Oriented Pedagogy. We have developed a number of features to make this book as student-friendly as possible. These include the overall organization, the use of introductions and epilogues to consolidate major topics and the extensive use of worked examples and case studies from all areas of engineering. We have also en- deavored to keep our explanations straightforward and oriented practically.
• Computational Tools. We empower our students by helping them utilize the standard “point-and-shoot” numerical problem-solving capabilities of packages like Excel, MATLAB, and Mathcad software. However, students are also shown how to develop simple, well-structured programs to extend the base capabilities of those environ- ments. This knowledge carries over to standard programming languages such as Visual Basic, Fortran 90, and C/C11. We believe that the current fl ight from computer programming represents something of a “dumbing down” of the engineering curricu- lum. The bottom line is that as long as engineers are not content to be tool limited, they will have to write code. Only now they may be called “macros” or “M-fi les.” This book is designed to empower them to do that.
Beyond these fi ve original principles, the seventh edition has new and expanded problem sets. Most of the problems have been modifi ed so that they yield different numerical solu- tions from previous editions. In addition, a variety of new problems have been included. The seventh edition also includes McGraw-Hill’s Connect® Engineering. This online homework management tool allows assignment of algorithmic problems for homework, quizzes, and tests. It connects students with the tools and resources they’ll need to achieve success. To learn more, visit www.mcgrawhillconnect.com. McGraw-Hill LearnSmart™ is also available as an integrated feature of McGraw-Hill Connect® Engineering. It is an adaptive learning system designed to help students learn faster, study more effi ciently, and retain more knowledge for greater success. LearnSmart assesses
cha9792x_fm_i_xvi.indd Page xiv 22/11/13 6:42 PM F-468 cha9792x_fm_i_xvi.indd Page xiv 22/11/13 6:42 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
PREFACE xv
a student’s knowledge of course content through a series of adaptive questions. It pinpoints concepts the student does not understand and maps out a personalized study plan for success. Visit the following site for a demonstration. www.mhlearnsmart.com As always, our primary intent in writing this book is to provide students with a sound introduction to numerical methods. We believe that motivated students who enjoy numeri- cal methods, computers, and mathematics will, in the end, make better engineers. If our book fosters an enthusiasm for these subjects, we will consider our efforts a success.
Acknowledgments. We would like to thank our friends at McGraw-Hill. In particular, Lorraine Buczek and Bill Stenquist, who provided a positive and supportive atmosphere for creating this edition. As usual, Beatrice Sussman did a masterful job of copyediting the man- uscript and Arpana Kumari of Aptara also did an outstanding job in the book’s fi nal production phase. As in past editions, David Clough (University of Colorado), Mike Gustafson (Duke), and Jerry Stedinger (Cornell University) generously shared their insights and suggestions. Use- ful suggestions were also made by Bill Philpot (Cornell University), Jim Guilkey (University of Utah), Dong-Il Seo (Chungnam National University, Korea), Niall Broekhuizen (NIWA, New Zealand), and Raymundo Cordero and Karim Muci (ITESM, Mexico). The present edition has also benefi ted from the reviews and suggestions by the following colleagues:
Betty Barr, University of Houston Jalal Behzadi, Shahid Chamran University Jordan Berg, Texas Tech University Jacob Bishop, Utah State University Estelle M. Eke, California State University, Sacramento Yazan A. Hussain, Jordan University of Science & Technology Yogesh Jaluria, Rutgers University S. Graham Kelly, The University of Akron Subha Kumpaty, Milwaukee School of Engineering Eckart Meiburg, University of California-Santa Barbara Prashant Mhaskar, McMaster University Luke Olson, University of Illinois at Urbana-Champaign Richard Pates Jr., Old Dominion University Joseph H. Pierluissi, University of Texas at El Paso Juan Perán, Universidad Nacional de Educación a Distancia (UNED) Scott A. Socolofsky, Texas A&M University
It should be stressed that although we received useful advice from the aforementioned individuals, we are responsible for any inaccuracies or mistakes you may detect in this edi- tion. Please contact Steve Chapra via e-mail if you should detect any errors in this edition. Finally, we would like to thank our family, friends, and students for their enduring patience and support. In particular, Cynthia Chapra, Danielle Husley, and Claire Canale are always there providing understanding, perspective, and love.
Steven C. Chapra Medford, Massachusetts steven.chapra@tufts.edu
Raymond P. Canale Lake Leelanau, Michigan
cha9792x_fm_i_xvi.indd Page xv 22/11/13 6:42 PM F-468 cha9792x_fm_i_xvi.indd Page xv 22/11/13 6:42 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
xvi
ABOUT THE AUTHORS
Steve Chapra teaches in the Civil and Environmental Engineering Department at Tufts University where he holds the Louis Berger Chair in Computing and Engineering. His other books include Surface Water-Quality Modeling and Applied Numerical Methods with MATLAB. Dr. Chapra received engineering degrees from Manhattan College and the University of Michigan. Before joining the faculty at Tufts, he worked for the Environmental Pro- tection Agency and the National Oceanic and Atmospheric Administration, and taught at Texas A&M University and the University of Colorado. His general research interests focus on surface water-quality modeling and advanced computer applications in environ- mental engineering. He is a Fellow of the ASCE, and has received a number of awards for his scholarly contributions, including the Rudolph Hering Medal (ASCE), and the Meriam-Wiley Distinguished Author Award (American Society for Engineering Education). He has also been recognized as the outstanding teacher among the engineering faculties at Texas A&M University, the University of Colorado, and Tufts University. Raymond P. Canale is an emeritus professor at the University of Michigan. During his over 20-year career at the university, he taught numerous courses in the area of comput- ers, numerical methods, and environmental engineering. He also directed extensive research programs in the area of mathematical and computer modeling of aquatic ecosystems. He has authored or coauthored several books and has published over 100 scientifi c papers and reports. He has also designed and developed personal computer software to facilitate en- gineering education and the solution of engineering problems. He has been given the Meriam-Wiley Distinguished Author Award by the American Society for Engineering Education for his books and software and several awards for his technical publications. Professor Canale is now devoting his energies to applied problems, where he works with engineering fi rms and industry and governmental agencies as a consultant and expert witness.
cha9792x_fm_i_xvi.indd Page xvi 22/11/13 6:42 PM F-468 cha9792x_fm_i_xvi.indd Page xvi 22/11/13 6:42 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
Numerical Methods for Engineers
cha9792x_p01_001-010.indd Page 1 09/10/13 9:56 PM F-468 cha9792x_p01_001-010.indd Page 1 09/10/13 9:56 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
PART ONE
cha9792x_p01_001-010.indd Page 2 09/10/13 9:56 PM F-468 cha9792x_p01_001-010.indd Page 2 09/10/13 9:56 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
3
PT1.1 MOTIVATION
Numerical methods are techniques by which mathematical problems are formulated so that they can be solved with arithmetic operations. Although there are many kinds of numerical methods, they have one common characteristic: they invariably involve large numbers of tedious arithmetic calculations. It is little wonder that with the development of fast, effi cient digital computers, the role of numerical methods in engineering problem solving has increased dramatically in recent years.
PT1.1.1 Noncomputer Methods
Beyond providing increased computational fi repower, the widespread availability of com- puters (especially personal computers) and their partnership with numerical methods has had a signifi cant infl uence on the actual engineering problem-solving process. In the precomputer era there were generally three different ways in which engineers approached problem solving:
1. Solutions were derived for some problems using analytical, or exact, methods. These solutions were often useful and provided excellent insight into the behavior of some systems. However, analytical solutions can be derived for only a limited class of problems. These include those that can be approximated with linear models and those that have simple geometry and low dimensionality. Consequently, analytical solutions are of limited practical value because most real problems are nonlinear and involve complex shapes and processes.
2. Graphical solutions were used to characterize the behavior of systems. These graphical solutions usually took the form of plots or nomographs. Although graphical techniques can often be used to solve complex problems, the results are not very precise. Furthermore, graphical solutions (without the aid of computers) are extremely tedious and awkward to implement. Finally, graphical techniques are often limited to problems that can be described using three or fewer dimensions.
3. Calculators and slide rules were used to implement numerical methods manually. Although in theory such approaches should be perfectly adequate for solving complex problems, in actuality several diffi culties are encountered. Manual calculations are slow and tedious. Furthermore, consistent results are elusive because of simple blunders that arise when numerous manual tasks are performed.
During the precomputer era, signifi cant amounts of energy were expended on the solution technique itself, rather than on problem defi nition and interpretation (Fig. PT1.1a). This unfortunate situation existed because so much time and drudgery were required to obtain numerical answers using precomputer techniques.
MODELING, COMPUTERS, AND ERROR ANALYSIS
cha9792x_p01_001-010.indd Page 3 09/10/13 9:56 PM F-468 cha9792x_p01_001-010.indd Page 3 09/10/13 9:56 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
4 MODELING, COMPUTERS, AND ERROR ANALYSIS
Today, computers and numerical methods provide an alternative for such compli- cated calculations. Using computer power to obtain solutions directly, you can approach these calculations without recourse to simplifying assumptions or time-intensive tech- niques. Although analytical solutions are still extremely valuable both for problem solving and for providing insight, numerical methods represent alternatives that greatly enlarge your capabilities to confront and solve problems. As a result, more time is available for the use of your creative skills. Thus, more emphasis can be placed on problem formulation and solution interpretation and the incorporation of total system, or “holistic,” awareness (Fig. PT1.1b).
PT1.1.2 Numerical Methods and Engineering Practice
Since the late 1940s the widespread availability of digital computers has led to a veri- table explosion in the use and development of numerical methods. At fi rst, this growth was somewhat limited by the cost of access to large mainframe computers, and, conse- quently, many engineers continued to use simple analytical approaches in a signifi cant portion of their work. Needless to say, the recent evolution of inexpensive personal
FIGURE PT1.1 The three phases of engineering problem solving in (a) the precomputer and (b) the computer era. The sizes of the boxes indicate the level of emphasis directed toward each phase. Computers facilitate the implementation of solution techniques and thus allow more emphasis to be placed on the creative aspects of problem formulation and interpretation of results.
INTERPRETATION
Ease of calculation allows holistic thoughts and intuition to develop;
system sensitivity and behavior can be studied
FORMULATION
In-depth exposition of relationship of
problem to fundamental laws
SOLUTION
Easy-to-use computer method
(b)
INTERPRETATION
In-depth analysis limited by time-
consuming solution
FORMULATION
Fundamental laws explained
briefly
SOLUTION
Elaborate and often complicated method to make problem tractable
(a)
cha9792x_p01_001-010.indd Page 4 09/10/13 9:56 PM F-468 cha9792x_p01_001-010.indd Page 4 09/10/13 9:56 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
PT1.2 MATHEMATICAL BACKGROUND 5
computers has given us ready access to powerful computational capabilities. There are several additional reasons why you should study numerical methods:
1. Numerical methods are extremely powerful problem-solving tools. They are capable of handling large systems of equations, nonlinearities, and complicated geometries that are not uncommon in engineering practice and that are often impossible to solve analytically. As such, they greatly enhance your problem-solving skills.
2. During your careers, you may often have occasion to use commercially available prepackaged, or “canned,” computer programs that involve numerical methods. The intelligent use of these programs is often predicated on knowledge of the basic theory underlying the methods.
3. Many problems cannot be approached using canned programs. If you are conversant with numerical methods and are adept at computer programming, you can design your own programs to solve problems without having to buy or commission expensive software.
4. Numerical methods are an effi cient vehicle for learning to use computers. It is well known that an effective way to learn programming is to actually write computer programs. Because numerical methods are for the most part designed for implementation on computers, they are ideal for this purpose. Further, they are especially well-suited to illustrate the power and the limitations of computers. When you successfully implement numerical methods on a computer and then apply them to solve otherwise intractable problems, you will be provided with a dramatic demonstration of how computers can serve your professional development. At the same time, you will also learn to acknowledge and control the errors of approximation that are part and parcel of large-scale numerical calculations.
5. Numerical methods provide a vehicle for you to reinforce your understanding of mathematics. Because one function of numerical methods is to reduce higher mathematics to basic arithmetic operations, they get at the “nuts and bolts” of some otherwise obscure topics. Enhanced understanding and insight can result from this alternative perspective.
PT1.2 MATHEMATICAL BACKGROUND
Every part in this book requires some mathematical background. Consequently, the in- troductory material for each part includes a section, such as the one you are reading, on mathematical background. Because Part One itself is devoted to background material on mathematics and computers, this section does not involve a review of a specifi c math- ematical topic. Rather, we take this opportunity to introduce you to the types of math- ematical subject areas covered in this book. As summarized in Fig. PT1.2, these are
1. Roots of Equations (Fig. PT1.2a). These problems are concerned with the value of a variable or a parameter that satisfi es a single nonlinear equation. These problems are especially valuable in engineering design contexts where it is often impossible to explicitly solve design equations for parameters.
2. Systems of Linear Algebraic Equations (Fig. PT1.2b). These problems are similar in spirit to roots of equations in the sense that they are concerned with values that
cha9792x_p01_001-010.indd Page 5 09/10/13 9:56 PM F-468 cha9792x_p01_001-010.indd Page 5 09/10/13 9:56 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
6 MODELING, COMPUTERS, AND ERROR ANALYSIS
f(x)
x
Root
x2
x1
Solution
Minimum
f(x)
x
Interpolation
f(x)
x
f(x)
x
Regression
f(x)
I
(a) Part 2: Roots of equations Solve f(x) = 0 for x.
(c) Part 4: Optimization
(b) Part 3: Linear algebraic equations Given the a’s and the c’s, solve a11x1 + a12x2 = c1 a21x1 + a22x2 = c2 for the x’s.
Determine x that gives optimum f(x).
(e) Part 6: Integration I = �ab f (x) dx Find the area under the curve.
(d) Part 5: Curve fitting
x
FIGURE PT1.2 Summary of the numerical methods covered in this book.
cha9792x_p01_001-010.indd Page 6 09/10/13 9:56 PM F-468 cha9792x_p01_001-010.indd Page 6 09/10/13 9:56 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
PT1.2 MATHEMATICAL BACKGROUND 7
satisfy equations. However, in contrast to satisfying a single equation, a set of values is sought that simultaneously satisfi es a set of linear algebraic equations. Such equations arise in a variety of problem contexts and in all disciplines of engineering. In particular, they originate in the mathematical modeling of large systems of interconnected elements such as structures, electric circuits, and fl uid networks. However, they are also encountered in other areas of numerical methods such as curve fi tting and differential equations.
3. Optimization (Fig. PT1.2c). These problems involve determining a value or values of an independent variable that correspond to a “best” or optimal value of a function. Thus, as in Fig. PT1.2c, optimization involves identifying maxima and minima. Such problems occur routinely in engineering design contexts. They also arise in a number of other numerical methods. We address both single- and multi-variable unconstrained optimization. We also describe constrained optimization with particular emphasis on linear programming.
4. Curve Fitting (Fig. PT1.2d). You will often have occasion to fi t curves to data points. The techniques developed for this purpose can be divided into two general categories: regression and interpolation. Regression is employed where there is a signifi cant degree of error associated with the data. Experimental results are often of this kind. For these situations, the strategy is to derive a single curve that represents the general trend of the data without necessarily matching any individual points. In contrast, interpolation is used where the objective is to determine intermediate values between relatively error-free data points. Such is usually the case for tabulated information. For these situations, the strategy is to fi t a curve directly through the data points and use the curve to predict the intermediate values.
5. Integration (Fig. PT1.2e). As depicted, a physical interpretation of numerical integration is the determination of the area under a curve. Integration has many
y
x
(g) Part 8: Partial differential equations Given
solve for u as a function of x and y
= f (x, y)� 2u
�x2 �2u �y2
+
t
Slope = f(ti, yi)
y
�t
ti ti + 1
( f ) Part 7: Ordinary differential equations Given
solve for y as a function of t.
yi + 1 = yi + f (ti , yi ) �t
� = f (t, y) dy dt
�y �t
FIGURE PT1.2 (concluded)
cha9792x_p01_001-010.indd Page 7 09/10/13 9:56 PM F-468 cha9792x_p01_001-010.indd Page 7 09/10/13 9:56 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
8 MODELING, COMPUTERS, AND ERROR ANALYSIS
applications in engineering practice, ranging from the determination of the centroids of oddly shaped objects to the calculation of total quantities based on sets of discrete measurements. In addition, numerical integration formulas play an important role in the solution of differential equations.
6. Ordinary Differential Equations (Fig. PT1.2f ). Ordinary differential equations are of great signifi cance in engineering practice. This is because many physical laws are couched in terms of the rate of change of a quantity rather than the magnitude of the quantity itself. Examples range from population-forecasting models (rate of change of population) to the acceleration of a falling body (rate of change of velocity). Two types of problems are addressed: initial-value and boundary-value problems. In addition, the computation of eigenvalues is covered.
7. Partial Differential Equations (Fig. PT1.2g). Partial differential equations are used to characterize engineering systems where the behavior of a physical quantity is couched in terms of its rate of change with respect to two or more independent variables. Examples include the steady-state distribution of temperature on a heated plate (two spatial dimensions) or the time-variable temperature of a heated rod (time and one spatial dimension). Two fundamentally different approaches are employed to solve partial differential equations numerically. In the present text, we will emphasize fi nite-difference methods that approximate the solution in a pointwise fashion (Fig. PT1.2g). However, we will also present an introduction to fi nite-element methods, which use a piecewise approach.
PT1.3 ORIENTATION
Some orientation might be helpful before proceeding with our introduction to nu- merical methods. The following is intended as an overview of the material in Part One. In addition, some objectives have been included to focus your efforts when studying the material.
PT1.3.1 Scope and Preview
Figure PT1.3 is a schematic representation of the material in Part One. We have designed this diagram to provide you with a global overview of this part of the book. We believe that a sense of the “big picture” is critical to developing insight into numerical methods. When reading a text, it is often possible to become lost in technical details. Whenever you feel that you are losing the big picture, refer back to Fig. PT1.3 to reorient yourself. Every part of this book includes a similar fi gure. Figure PT1.3 also serves as a brief preview of the material covered in Part One. Chapter 1 is designed to orient you to numerical methods and to provide motivation by demonstrating how these techniques can be used in the engineering modeling process. Chapter 2 is an introduction and review of computer-related aspects of numerical meth- ods and suggests the level of computer skills you should acquire to effi ciently apply succeeding information. Chapters 3 and 4 deal with the important topic of error analysis, which must be understood for the effective use of numerical methods. In addition, an epilogue is included that introduces the trade-offs that have such great signifi cance for the effective implementation of numerical methods.
cha9792x_p01_001-010.indd Page 8 09/10/13 9:56 PM F-468 cha9792x_p01_001-010.indd Page 8 09/10/13 9:56 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
PT1.3 ORIENTATION 9
FIGURE PT1.3 Schematic of the organization of the material in Part One: Modeling, Computers, and Error Analysis.
CHAPTER 1 Mathematical Modeling and Engineering
Problem Solving
PART 1 Modeling,
Computers, and
Error Analysis
CHAPTER 2 Programming and Software
CHAPTER 3 Approximations and Round-Off
Errors
CHAPTER 4 Truncation
Errors and the Taylor Series
EPILOGUE
2.7 Languages and
libraries
2.6 Mathcad
2.5 MATLAB
2.4 Excel
2.3 Modular
programming
2.2 Structured
programming
2.1 Packages and programming
PT 1.2 Mathematical background
PT 1.6 Advanced methods
PT 1.5 Important formulas
4.4 Miscellaneous
errors
4.3 Total numerical
error
4.2 Error
propagation
4.1 Taylor series
3.4 Round-off
errors
3.1 Significant
figures
3.3 Error
definitions
3.2 Accuracy and
precision
PT 1.4 Trade-offs
PT 1.3 Orientation
PT 1.1 Motivation
1.2 Conservation
laws
1.1 A simple
model
cha9792x_p01_001-010.indd Page 9 09/10/13 9:56 PM F-468 cha9792x_p01_001-010.indd Page 9 09/10/13 9:56 PM F-468 /207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles/207/MH02101/cha9792x_disk1of1/007339792x/cha9792x_pagefiles
10 MODELING, COMPUTERS, AND ERROR ANALYSIS
TABLE PT1.1 Specifi c study objectives for Part One.
1. Recognize the difference between analytical and numerical solutions. 2. Understand how conservation laws are employed to develop mathematical models of physical
systems. 3. Defi ne top-down and modular design. 4. Delineate the rules that underlie structured programming. 5. Be capable of composing structured and modular programs in a high-level computer language. 6. Know how to translate structured fl owcharts and pseudocode into code in a high-level language. 7. Start to familiarize yourself with any software packages that you will be using in conjunction with
this text. 8. Recognize the distinction between truncation and round-off errors. 9. Understand the concepts of signifi cant fi gures, accuracy, and precision. 10. Recognize the difference between true relative error et, approximate relative error ea, and
acceptable error es, and understand how ea and es are used to terminate an iterative computation. 11. Understand how numbers are represented in digital computers and how this representation induces
round-off error. In particular, know the difference between single and extended precision. 12. Recognize how computer arithmetic can introduce and amplify round-off errors in calculations. In
particular, appreciate the problem of subtractive cancellation. 13. Understand how the Taylor series and its remainder are employed to represent continuous functions. 14. Know the relationship between fi nite divided differences and derivatives. 15. Be able to analyze how errors are propagated through functional relationships. 16. Be familiar with the concepts of stability and condition. 17. Familiarize yourself with the trade-offs outlined in the Epilogue of Part One.
PT1.3.2 Goals and Objectives
Study Objectives. Upon completing Part One, you should be adequately prepared to embark on your studies of numerical methods. In general, you should have gained a fundamental understanding of the importance of computers and the role of approxima- tions and errors in the implementation and development of numerical methods. In addi- tion to these general goals, you should have mastered each of the specifi c study objectives listed in Table PT1.1.
Computer Objectives. Upon completing Part One, you should have mastered suffi cient computer skills to develop your own software for the numerical methods in this text. You should be able to develop well-structured and reliable computer programs on the basis of pseudocode, fl owcharts, or other forms of algorithms. You should have developed the capability to document your programs so that they may be effectively employed by users. Finally, in addition to your own programs, you may be using software packages along with this book. Packages like Excel, Mathcad, or The MathWorks, Inc. MATLAB® pro- gram are examples of such software. You should become familiar with these packages, so that you will be comfortable using them to solve numerical problems later in the text.
cha9792x_p01_001-010.indd Page 10 09/10/13 9:56 PM F-468 cha9792x_p01_001-010.indd