Download Applied Numerical Methods With MATLAB by Steven Chapra and more Study notes Numerical Methods in Engineering in PDF only on Docsity!
This page intentionally left blank
APPLIED NUMERICAL METHODS WITH MATLAB FOR ENGINEERS AND SCIENTISTS, THIRD EDITION
Published by McGraw-Hill, a business unit of The McGraw-Hill Companies, Inc., 1221 Avenue of the Americas, New York, NY 10020. Copyright © 2012 by The McGraw-Hill Companies, Inc. All rights reserved. Previous editions © 2008 and 2005. 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 The McGraw-Hill Companies, Inc., 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 3 2 1
ISBN 978-0-07-340110- MHID 0-07-340110-
TM
Vice President & Editor-in-Chief: Marty Lange Vice President EDP/Central Publishing Services: Kimberly Meriwether David Publisher: Raghothaman Srinivasan Sponsoring Editor: Peter E. Massar Marketing Manager: Curt Reynolds Development Editor: Lorraine Buczek Project Manager: Melissa M. Leick
Design Coordinator: Brenda A. Rolwes Cover Design: Studio Montage, St. Louis, Missouri Cover Credit: © Brand X/Jupiter Images RF Buyer: Kara Kudronowicz Media Project Manager: Balaji Sundararaman Compositor: MPS Limited, a Macmillan Company Typeface: 10/12 Times 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.
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. The MathWorks Publisher Logo identifies books that contain “MATLAB ®” content. Used with permission. The MathWorks does not warrant the accuracy of the text or exercises in this book. This book’s use or discussion “MATLAB ®” software or related products does not constitute endorsement or sponsorship by The MathWorks of a particular use of the “MATLAB ®” software or related products.
For MATLAB®^ and Simulink product information, or information on other related products, please contact: The MathWorks, Inc. 3 Apple Hill Drive Natick, MA, 01760-2098 USA Tel: 508-647- Fax: 508-647- E-mail: info@mathworks.com Web: www.mathworks.com
Library of Congress Cataloging-in-Publication Data
Chapra, Steven C. Applied numerical methods with MATLAB for engineers and scientists / Steven C. Chapra. — 3rd ed. p. cm. ISBN 978-0-07-340110-2 (alk. paper)
- Numerical analysis—Data processing—Textbooks. 2. MATLAB—Textbooks. I. Title.
QA297.C4185 2012 518–dc22 2010044481
www.mhhe.com
To
My brothers,
John and Bob Chapra
v
CONTENTS
About the Author iv
- PART ONE Modeling, Computers, and Error Analysis Preface xiii
- 1.1 Motivation
- 1.2 Part Organization
- CHAPTER - and Problem Solving Mathematical Modeling, Numerical Methods, - 1.1 A Simple Mathematical Model - 1.2 Conservation Laws in Engineering and Science - 1.3 Numerical Methods Covered in This Book - 1.4 Case Study: It’s a Real Drag - Problems
- CHAPTER - MATLAB Fundamentals - 2.1 The MATLAB Environment - 2.2 Assignment - 2.3 Mathematical Operations - 2.4 Use of Built-In Functions - 2.5 Graphics - 2.6 Other Resources - 2.7 Case Study: Exploratory Data Analysis - Problems
- CHAPTER - Programming with MATLAB - 3.1 M-Files - 3.2 Input-Output - 3.3 Structured Programming - 3.4 Nesting and Indentation - 3.5 Passing Functions to M-Files - 3.6 Case Study: Bungee Jumper Velocity - Problems
- CHAPTER - Roundoff and Truncation Errors - 4.1 Errors - 4.2 Roundoff Errors - 4.3 Truncation Errors - 4.4 Total Numerical Error - 4.5 Blunders, Model Errors, and Data Uncertainty - Problems
- PART TWO Roots and Optimization
- 2.1 Overview
- 2.2 Part Organization
- CHAPTER - Roots: Bracketing Methods - 5.1 Roots in Engineering and Science - 5.2 Graphical Methods - 5.3 Bracketing Methods and Initial Guesses - 5.4 Bisection - 5.5 False Position - 5.6 Case Study: Greenhouse Gases and Rainwater - Problems
- CHAPTER - Roots: Open Methods - 6.1 Simple Fixed-Point Iteration - 6.2 Newton-Raphson - 6.3 Secant Methods - 6.4 Brent’s Method - 6.5 MATLAB Function: fzero - 6.6 Polynomials - 6.7 Case Study: Pipe Friction - Problems - CHAPTER - Optimization - 7.1 Introduction and Background - 7.2 One-Dimensional Optimization - 7.3 Multidimensional Optimization - 7.4 Case Study: Equilibrium and Minimum Potential Energy - Problems
- PART THREE Linear Systems - 3.1 Overview - 3.2 Part Organization
- CHAPTER
- Linear Algebraic Equations and Matrices
- 8.1 Matrix Algebra Overview
- 8.2 Solving Linear Algebraic Equations with MATLAB
- 8.3 Case Study: Currents and Voltages in Circuits
- Problems
- CHAPTER
- Gauss Elimination
- 9.1 Solving Small Numbers of Equations
- 9.2 Naive Gauss Elimination
- 9.3 Pivoting
- 9.4 Tridiagonal Systems
- 9.5 Case Study: Model of a Heated Rod
- Problems
- CHAPTER - LU Factorization - 10.1 Overview of LU Factorization - 10.2 Gauss Elimination as LU Factorization - 10.3 Cholesky Factorization - 10.4 MATLAB Left Division - Problems
- CHAPTER - Matrix Inverse and Condition - 11.1 The Matrix Inverse - 11.2 Error Analysis and System Condition - 11.3 Case Study: Indoor Air Pollution - Problems
- CHAPTER - Iterative Methods - 12.1 Linear Systems: Gauss-Seidel - 12.2 Nonlinear Systems - 12.3 Case Study: Chemical Reactions - Problems
- CHAPTER - Eigenvalues - 13.1 Mathematical Background - 13.2 Physical Background - 13.3 The Power Method - 13.4 MATLAB Function: eig - 13.5 Case Study: Eigenvalues and Earthquakes - Problems
- PART FOUR Curve Fitting
- 4.1 Overview
- 4.2 Part Organization
- CHAPTER - Linear Regression - 14.1 Statistics Review - 14.2 Random Numbers and Simulation - 14.3 Linear Least-Squares Regression - 14.4 Linearization of Nonlinear Relationships - 14.5 Computer Applications - 14.6 Case Study: Enzyme Kinetics - Problems
- CHAPTER
- General Linear Least-Squares and Nonlinear Regression
- 15.1 Polynomial Regression
- 15.2 Multiple Linear Regression
- 15.3 General Linear Least Squares
- 15.4 QR Factorization and the Backslash Operator
- 15.5 Nonlinear Regression
- 15.6 Case Study: Fitting Experimental Data
- Problems
- CHAPTER
- Fourier Analysis
- 16.1 Curve Fitting with Sinusoidal Functions
- 16.2 Continuous Fourier Series
- 16.3 Frequency and Time Domains
- 16.4 Fourier Integral and Transform
- 16.5 Discrete Fourier Transform (DFT)
- 16.6 The Power Spectrum
- 16.7 Case Study: Sunspots
- Problems
- CHAPTER
- Polynomial Interpolation
- 17.1 Introduction to Interpolation
- 17.2 Newton Interpolating Polynomial
- 17.3 Lagrange Interpolating Polynomial
- 17.4 Inverse Interpolation
- 17.5 Extrapolation and Oscillations
- Problems
- CHAPTER
- Splines and Piecewise Interpolation
- 18.1 Introduction to Splines
- 18.2 Linear Splines
- 18.3 Quadratic Splines
- 18.4 Cubic Splines
- 18.5 Piecewise Interpolation in MATLAB
- 18.6 Multidimensional Interpolation
- 18.7 Case Study: Heat Transfer
- Problems
- PART FIVE Integration and Differentiation
- 5.1 Overview
- 5.2 Part Organization
- CHAPTER - Numerical Integration Formulas - 19.1 Introduction and Background - 19.2 Newton-Cotes Formulas - 19.3 The Trapezoidal Rule - 19.4 Simpson’s Rules - 19.5 Higher-Order Newton-Cotes Formulas - 19.6 Integration with Unequal Segments - 19.7 Open Methods - 19.8 Multiple Integrals - 19.9 Case Study: Computing Work with Numerical Integration - Problems
- CHAPTER - Numerical Integration of Functions - 20.1 Introduction - 20.2 Romberg Integration - 20.3 Gauss Quadrature - 20.4 Adaptive Quadrature - 20.5 Case Study: Root-Mean-Square Current - Problems
- CHAPTER - Numerical Differentiation - 21.1 Introduction and Background - 21.2 High-Accuracy Differentiation Formulas - 21.3 Richardson Extrapolation - 21.4 Derivatives of Unequally Spaced Data - 21.5 Derivatives and Integrals for Data with Errors - 21.6 Partial Derivatives - 21.7 Numerical Differentiation with MATLAB - 21.8 Case Study: Visualizing Fields - Problems
- PART SIX Ordinary Differential Equations
- 6.1 Overview
- 6.2 Part Organization
- CHAPTER - Initial-Value Problems - 22.1 Overview - 22.2 Euler’s Method - 22.3 Improvements of Euler’s Method - 22.4 Runge-Kutta Methods - 22.5 Systems of Equations - 22.6 Case Study: Predator-Prey Models and Chaos - Problems
- CHAPTER - Adaptive Methods and Stiff Systems - 23.1 Adaptive Runge-Kutta Methods - 23.2 Multistep Methods - 23.3 Stiffness - 23.4 MATLAB Application: Bungee Jumper with Cord - 23.5 Case Study: Pliny’s Intermittent Fountain - Problems
- CHAPTER - Boundary-Value Problems - 24.1 Introduction and Background - 24.2 The Shooting Method - 24.3 Finite-Difference Methods - Problems - APPENDIX A: MATLAB BUILT-IN FUNCTIONS - APPENDIX B: MATLAB M-FILE FUNCTIONS - BIBLIOGRAPHY - INDEX
McGraw-Hill Digital Offerings Include:
McGraw-Hill Create™
Craft your teaching resources to match the way you teach! With McGraw-Hill Create™,
www.mcgrawhillcreate.com, you can easily rearrange chapters, combine material from
other content sources, and quickly upload content you have written like your course
syllabus or teaching notes. Find the content you need in Create by searching through thou-
sands of leading McGraw-Hill textbooks. Arrange your book to fit your teaching style.
Create even allows you to personalize your book’s appearance by selecting the cover and
adding your name, school, and course information. Order a Create book and you’ll receive
a complimentary print review copy in 3–5 business days or a complimentary electronic
review copy (eComp) via email in minutes. Go to www.mcgrawhillcreate.com today and
register to experience how McGraw-Hill Create™ empowers you to teach your students
your way.
McGraw-Hill Higher Education and Blackboard Have Teamed Up
Blackboard, the Web-based course-management system, has partnered with McGraw-Hill
to better allow students and faculty to use online materials and activities to complement
face-to-face teaching. Blackboard features exciting social learning and teaching tools that
foster more logical, visually impactful and active learning opportunities for students.
You’ll transform your closed-door classrooms into communities where students remain
connected to their educational experience 24 hours a day.
This partnership allows you and your students access to McGraw-Hill’s Create™ right
from within your Blackboard course—all with one single sign-on. McGraw-Hill and
Blackboard can now offer you easy access to industry leading technology and content,
whether your campus hosts it, or we do. Be sure to ask your local McGraw-Hill represen-
tative for details.
Electronic Textbook Options
This text is offered through CourseSmart for both instructors and students. CourseSmart is
an online resource where students can purchase the complete text online at almost half the
cost of a traditional text. Purchasing the eTextbook allows students to take advantage of
CourseSmart’s web tools for learning, which include full text search, notes and highlight-
ing, and email tools for sharing notes between classmates. To learn more about CourseSmart
options, contact your sales representative or visit www.CourseSmart.com.
FIGURE P.1 An outline of this edition. The shaded areas represent new material. In addition, several of the original chapters have been supplemented withnew topics. xiv
PART ONE
PART TWO
PART THREE
PART FOUR
PART FIVE
PART SIX
Modeling, Computers,
Roots and
Linear Systems
Curve Fitting
Integration and
Ordinary Differential
and Error Analysis
Optimization
Differentiation
Equations
CHAPTER 1
CHAPTER 5
CHAPTER 8
CHAPTER 14
CHAPTER 19
CHAPTER 22
Mathematical
Roots: Bracketing
Linear Algebraic
Linear Regression
Numerical Integration
Initial-Value
Modeling, Numerical
Methods
Equations
Formulas
Problems
Methods, and Problem
and Matrices
SolvingCHAPTER 2
CHAPTER 6
CHAPTER 9
CHAPTER 15
CHAPTER 20
CHAPTER 23
MATLAB
Roots: Open
Gauss Elimination
General Linear
Numerical lntegration
Adaptive Methods
Fundamentals
Methods
Least-Squares and
of Functions
and Stiff Systems
Nonlinear Regression
CHAPTER 3
CHAPTER 7
CHAPTER 10
CHAPTER 16
CHAPTER 21
CHAPTER 24
Programming
Optimization
LU
Factorization
Fourier Analysis
Numerical
Boundary-Value
with MATLAB
Differentiation
Problems
CHAPTER 4
CHAPTER 11
CHAPTER 17
Roundoff and
Matrix Inverse
Polynomial
Truncation Errors
and Condition
Interpolation
CHAPTER 12
CHAPTER 18
Iterative Methods
Splines and PiecewiseInterpolation
CHAPTER 13Eigenvalues
PREFACE xv
to move this material up to what I consider to be its more natural mathematical po-
sition at the end of the section on linear algebraic equations. By stressing applica-
tions (in particular, the use of eigenvalues to study vibrations), I have found that
students respond very positively to the subject in this position. In addition, it allows
me to return to the topic in subsequent chapters which serves to enhance the
students’ appreciation of the topic.
- Fourier Analysis. In past years, if time permitted, I also usually presented a lecture
at the end of the semester on Fourier analysis. Over the past two years, I have begun
presenting this material at its more natural position just after the topic of linear least
squares. I motivate the subject matter by using the linear least-squares approach to
fit sinusoids to data. Then, by stressing applications (again vibrations), I have found
that the students readily absorb the topic and appreciate its value in engineering and
science.
It should be noted that both chapters are written in a modular fashion and could
be skipped without detriment to the course’s pedagogical arc. Therefore, if you
choose, you can either omit them from your course or perhaps move them to the
end of the semester. In any event, I would not have included them in the current
edition if they did not represent an enhancement within my current experience in
the classroom. In particular, based on my teaching evaluations, I find that the
stronger, more motivated students actually see these topics as highlights. This is
particularly true because MATLAB greatly facilitates their application and inter-
pretation.
2. New Content. Beyond the new chapters, I have included new and enhanced sections on a
number of topics. The primary additions include sections on animation (Chap. 3), Brent’s
method for root location (Chap. 6), LU factorization with pivoting (Chap. 8), ran-
dom numbers and Monte Carlo simulation (Chap. 14), adaptive quadrature (Chap. 20),
and event termination of ODEs (Chap. 23).
3. New Homework Problems. Most of the end-of-chapter problems have been modi-
fied, and a variety of new problems have been added. In particular, an effort has been
made to include several new problems for each chapter that are more challenging and
difficult than the problems in the previous edition.
Aside from the new material and problems, the third edition is very similar to the second.
In particular, I have endeavored to maintain most of the features contributing to its pedagog-
ical effectiveness including extensive use of worked examples and engineering and scien-
tific applications. As with the previous edition, I have made a concerted effort to make this
book as “student-friendly” as possible. Thus, I’ve tried to keep my explanations straightfor-
ward and practical.
Although my primary intent is to empower students by providing them with a sound
introduction to numerical problem solving, I have the ancillary objective of making this
introduction exciting and pleasurable. I believe that motivated students who enjoy engi-
neering and science, problem solving, mathematics—and yes—programming, will ulti-
mately make better professionals. If my book fosters enthusiasm and appreciation for these
subjects, I will consider the effort a success.
PEDAGOGICAL TOOLS
Theory Presented as It Informs Key Concepts. The text is intended for Numerical Meth-
ods users, not developers. Therefore, theory is not included for “theory’s sake,” for example no
proofs. Theory is included as it informs key concepts such as the Taylor series, convergence,
condition, etc. Hence, the student is shown how the theory connects with practical issues in
problem solving.
Introductory MATLAB Material. The text includes two introductory chapters on how to
use MATLAB. Chapter 2 shows students how to perform computations and create graphs
in MATLAB’s standard command mode. Chapter 3 provides a primer on developing
numerical programs via MATLAB M-file functions. Thus, the text provides students with
the means to develop their own numerical algorithms as well as to tap into MATLAB’s
powerful built-in routines.
Algorithms Presented Using MATLAB M-files. Instead of using pseudocode, this book
presents algorithms as well-structured MATLAB M-files. Aside from being useful com-
puter programs, these provide students with models for their own M-files that they will
develop as homework exercises.
Worked Examples and Case Studies. Extensive worked examples are laid out in detail
so that students can clearly follow the steps in each numerical computation. The case stud-
ies consist of engineering and science applications which are more complex and richer than
the worked examples. They are placed at the ends of selected chapters with the intention of
(1) illustrating the nuances of the methods, and (2) showing more realistically how the
methods along with MATLAB are applied for problem solving.
Problem Sets. The text includes a wide variety of problems. Many are drawn from engi-
neering and scientific disciplines. Others are used to illustrate numerical techniques and
theoretical concepts. Problems include those that can be solved with a pocket calculator as
well as others that require computer solution with MATLAB.
Useful Appendices and Indexes. Appendix A contains MATLAB commands, and
Appendix B contains M-file functions.
Textbook Website. A text-specific website is available at www.mhhe.com/chapra. Re-
sources include the text images in PowerPoint, M-files, and additional MATLAB resources.
PREFACE xvii
This page intentionally left blank