Professional Documents
Culture Documents
Applied Numerical Methods with MATLAB for Engineers and Scientists 4th Edition Steven C. Chapra Dr. full chapter instant download
Applied Numerical Methods with MATLAB for Engineers and Scientists 4th Edition Steven C. Chapra Dr. full chapter instant download
Applied Numerical Methods with MATLAB for Engineers and Scientists 4th Edition Steven C. Chapra Dr. full chapter instant download
https://ebookmass.com/product/applied-numerical-methods-with-
matlab-for-engineers-and-scientists-5th-edition-steven-c-chapra/
https://ebookmass.com/product/applied-numerical-methods-with-
python-for-engineers-and-scientists-steven-c-chapra/
https://ebookmass.com/product/physics-for-scientists-and-
engineers-with-modern-physics-4th-edition-douglas-c-giancoli/
https://ebookmass.com/product/essential-matlab-for-engineers-and-
scientists-6th-edition-edition-hahn/
Essential MATLAB for engineers and scientists Sixth
Edition. Edition Hahn
https://ebookmass.com/product/essential-matlab-for-engineers-and-
scientists-sixth-edition-edition-hahn/
https://ebookmass.com/product/essential-matlab-for-engineers-and-
scientists-7th-edition-edition-hahn/
https://ebookmass.com/product/essential-matlab-for-engineers-and-
scientists-7th-edition-hahn-b-d/
https://ebookmass.com/product/applied-data-analysis-and-modeling-
for-energy-engineers-and-scientists/
https://ebookmass.com/product/etextbook-978-0131495081-physics-
for-scientists-engineers-with-modern-physics-4th-edition/
Applied Numerical Methods
with MATLAB® for Engineers and Scientists
Fourth Edition
Steven C. Chapra
Berger Chair in Computing and Engineering
Tufts University
APPLIED NUMERICAL METHODS WITH MATLAB® FOR ENGINEERS AND SCIENTISTS,
FOURTH EDITION
Published by McGraw-Hill Education, 2 Penn Plaza, New York, NY 10121. Copyright © 2018 by McGraw-Hill
Education. All rights reserved. Printed in the United States of America. Previous editions © 2012, 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 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.
1 2 3 4 5 6 7 8 9 LCR 21 20 19 18 17
ISBN 978-0-07-339796-2
MHID 0-07-339796-2
All credits appearing on page or at the end of the book are considered to be an extension of the copyright page.
mheducation.com/highered
To
My brothers,
John and Bob Chapra
and
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 Numerical Methods for Engineers and Surface Water-Quality Modeling.
Steve received engineering degrees from Manhattan College and the University of
Michigan. Before joining the faculty at Tufts, he worked for the Environmental Protection
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 environmental
engineering.
He has received a number of awards for his scholarly contributions, including the
Rudolph Hering Medal, the Meriam/Wiley Distinguished Author Award, and the Chandler-
Misener Award. He has also been recognized as the outstanding teacher at Texas A&M
University (1986 Tenneco Award), the University of Colorado (1992 Hutchinson Award),
and Tufts University (2011 Professor of the Year Award).
Steve was originally drawn to environmental engineering and science because of his
love of the outdoors. He is an avid fly fisherman and hiker. An unapologetic nerd, his love
affair with computing began when he was first introduced to Fortran programming as an
undergraduate in 1966. Today, he feels truly blessed to be able to meld his love of math-
ematics, science, and computing with his passion for the natural environment. In addition,
he gets the bonus of sharing it with others through his teaching and writing!
Beyond his professional interests, he enjoys art, music (especially classical music,
jazz, and bluegrass), and reading history. Despite unfounded rumors to the contrary, he
never has, and never will, voluntarily bungee jump or sky dive.
If you would like to contact Steve, or learn more about him, visit his home page at
http://engineering.tufts.edu/cee/people/chapra/ or e-mail him at steven.chapra@tufts.edu.
iv
CONTENTS
Preface xiv
CHAPTER 1
Mathematical Modeling, Numerical Methods,
and Problem Solving 4
1.1 A Simple Mathematical Model 5
1.2 Conservation Laws in Engineering and Science 12
1.3 Numerical Methods Covered in This Book 13
1.4 Case Study: It’s a Real Drag 17
Problems 20
CHAPTER 2
MATLAB Fundamentals 27
2.1 The MATLAB Environment 28
2.2 Assignment 29
2.3 Mathematical Operations 36
2.4 Use of Built-In Functions 39
2.5 Graphics 42
2.6 Other Resources 46
2.7 Case Study: Exploratory Data Analysis 46
Problems 49
CHAPTER 3
Programming with MATLAB 53
3.1 M-Files 54
3.2 Input-Output 61
v
vi CONTENTS
CHAPTER 4
Roundoff and Truncation Errors 99
4.1 Errors 100
4.2 Roundoff Errors 106
4.3 Truncation Errors 114
4.4 Total Numerical Error 125
4.5 Blunders, Model Errors, and Data Uncertainty 130
Problems 131
CHAPTER 5
Roots: Bracketing Methods 138
5.1 Roots in Engineering and Science 139
5.2 Graphical Methods 140
5.3 Bracketing Methods and Initial Guesses 141
5.4 Bisection 146
5.5 False Position 152
5.6 Case Study: Greenhouse Gases and Rainwater 156
Problems 159
CHAPTER 6
Roots: Open Methods 164
6.1 Simple Fixed-Point Iteration 165
6.2 Newton-Raphson 169
6.3 Secant Methods 174
6.4 Brent’s Method 176
6.5 MATLAB Function: fzero 181
6.6 Polynomials 183
6.7 Case Study: Pipe Friction 186
Problems 191
CONTENTS vii
CHAPTER 7
Optimization 198
7.1 Introduction and Background 199
7.2 One-Dimensional Optimization 202
7.3 Multidimensional Optimization 211
7.4 Case Study: Equilibrium and Minimum Potential Energy 213
Problems 215
CHAPTER 8
Linear Algebraic Equations and Matrices 227
8.1 Matrix Algebra Overview 229
8.2 Solving Linear Algebraic Equations with MATLAB 238
8.3 Case Study: Currents and Voltages in Circuits 240
Problems 244
CHAPTER 9
Gauss Elimination 248
9.1 Solving Small Numbers of Equations 249
9.2 Naive Gauss Elimination 254
9.3 Pivoting 261
9.4 Tridiagonal Systems 264
9.5 Case Study: Model of a Heated Rod 266
Problems 270
CHAPTER 10
LU Factorization 274
10.1 Overview of LU Factorization 275
10.2 Gauss Elimination as LU Factorization 276
10.3 Cholesky Factorization 283
10.4 MATLAB Left Division 286
Problems 287
viii CONTENTS
CHAPTER 11
Matrix Inverse and Condition 288
11.1 The Matrix Inverse 288
11.2 Error Analysis and System Condition 292
11.3 Case Study: Indoor Air Pollution 297
Problems 300
CHAPTER 12
Iterative Methods 305
12.1 Linear Systems: Gauss-Seidel 305
12.2 Nonlinear Systems 312
12.3 Case Study: Chemical Reactions 320
Problems 323
CHAPTER 13
Eigenvalues 326
13.1 Mathematical Background 328
13.2 Physical Background 331
13.3 The Power Method 333
13.4 MATLAB Function: eig 336
13.5 Case Study: Eigenvalues and Earthquakes 337
Problems 340
CHAPTER 14
Linear Regression 346
14.1 Statistics Review 348
14.2 Random Numbers and Simulation 353
14.3 Linear Least-Squares Regression 358
14.4 Linearization of Nonlinear Relationships 366
14.5 Computer Applications 370
14.6 Case Study: Enzyme Kinetics 373
Problems 378
CONTENTS ix
CHAPTER 15
General Linear Least-Squares and Nonlinear Regression 385
15.1 Polynomial Regression 385
15.2 Multiple Linear Regression 389
15.3 General Linear Least Squares 391
15.4 QR Factorization and the Backslash Operator 394
15.5 Nonlinear Regression 395
15.6 Case Study: Fitting Experimental Data 397
Problems 399
CHAPTER 16
Fourier Analysis 404
16.1 Curve Fitting with Sinusoidal Functions 405
16.2 Continuous Fourier Series 411
16.3 Frequency and Time Domains 414
16.4 Fourier Integral and Transform 415
16.5 Discrete Fourier Transform (DFT) 418
16.6 The Power Spectrum 423
16.7 Case Study: Sunspots 425
Problems 426
CHAPTER 17
Polynomial Interpolation 429
17.1 Introduction to Interpolation 430
17.2 Newton Interpolating Polynomial 433
17.3 Lagrange Interpolating Polynomial 441
17.4 Inverse Interpolation 444
17.5 Extrapolation and Oscillations 445
Problems 449
CHAPTER 18
Splines and Piecewise Interpolation 453
18.1 Introduction to Splines 453
18.2 Linear Splines 455
18.3 Quadratic Splines 459
18.4 Cubic Splines 462
18.5 Piecewise Interpolation in MATLAB 468
18.6 Multidimensional Interpolation 473
18.7 Case Study: Heat Transfer 476
Problems 480
x CONTENTS
CHAPTER 19
Numerical Integration Formulas 488
19.1 Introduction and Background 489
19.2 Newton-Cotes Formulas 492
19.3 The Trapezoidal Rule 494
19.4 Simpson’s Rules 501
19.5 Higher-Order Newton-Cotes Formulas 507
19.6 Integration with Unequal Segments 508
19.7 Open Methods 512
19.8 Multiple Integrals 512
19.9 Case Study: Computing Work with Numerical Integration 515
Problems 518
CHAPTER 20
Numerical Integration of Functions 524
20.1 Introduction 524
20.2 Romberg Integration 525
20.3 Gauss Quadrature 530
20.4 Adaptive Quadrature 537
20.5 Case Study: Root-Mean-Square Current 540
Problems 544
CHAPTER 21
Numerical Differentiation 548
21.1 Introduction and Background 549
21.2 High-Accuracy Differentiation Formulas 552
21.3 Richardson Extrapolation 555
21.4 Derivatives of Unequally Spaced Data 557
21.5 Derivatives and Integrals for Data with Errors 558
21.6 Partial Derivatives 559
21.7 Numerical Differentiation with MATLAB 560
21.8 Case Study: Visualizing Fields 565
Problems 567
CONTENTS xi
CHAPTER 22
Initial-Value Problems 579
22.1 Overview 581
22.2 Euler’s Method 581
22.3 Improvements of Euler’s Method 587
22.4 Runge-Kutta Methods 593
22.5 Systems of Equations 598
22.6 Case Study: Predator-Prey Models and Chaos 604
Problems 609
CHAPTER 23
Adaptive Methods and Stiff Systems 615
23.1 Adaptive Runge-Kutta Methods 615
23.2 Multistep Methods 624
23.3 Stiffness 628
23.4 MATLAB Application: Bungee Jumper with Cord 634
23.5 Case Study: Pliny’s Intermittent Fountain 635
Problems 640
CHAPTER 24
Boundary-Value Problems 646
24.1 Introduction and Background 647
24.2 The Shooting Method 651
24.3 Finite-Difference Methods 658
24.4 MATLAB Function: bvp4c 665
Problems 668
McGraw-Hill Connect®
Learn Without Limits
Connect is a teaching and learning platform that is proven
to deliver better results for students and instructors.
Mobile
Connect’s new, intuitive mobile interface gives students
and instructors flexible and convenient, anytime–anywhere
access to all components of the Connect platform.
Adaptive
THE ADAPTIVE
READING EXPERIENCE
DESIGNED TO TRANSFORM
THE WAY STUDENTS READ
SmartBook®
Proven to help students improve grades and study more
efficiently, SmartBook contains the same content within
the print book, but actively tailors that content to the
needs of the individual. SmartBook’s adaptive technology
provides precise, personalized instruction on what the
student should do next, guiding the student to master
and remember key concepts, targeting gaps in knowledge
and offering customized feedback, and driving the student
toward comprehension and retention of the subject matter.
Available on tablets, SmartBook puts learning at the student’s
fingertips—anywhere, anytime.
www.mheducation.com
PREFACE
This book is designed to support a one-semester course in numerical methods. It has been
written for students who want to learn and apply numerical methods in order to solve prob-
lems in engineering and science. As such, the methods are motivated by problems rather
than by mathematics. That said, sufficient theory is provided so that students come away
with insight into the techniques and their shortcomings.
MATLAB® provides a great environment for such a course. Although other en-
vironments (e.g., Excel/VBA, Mathcad) or languages (e.g., Fortran 90, C++) could
have been chosen, MATLAB presently offers a nice combination of handy program-
ming features with powerful built-in numerical capabilities. On the one hand, its
M-file programming environment allows students to implement moderately compli-
cated algorithms in a structured and coherent fashion. On the other hand, its built-in,
numerical capabilities empower students to solve more difficult problems without try-
ing to “reinvent the wheel.”
The basic content, organization, and pedagogy of the third edition are essentially pre-
served in the fourth edition. In particular, the conversational writing style is intentionally
maintained in order to make the book easier to read. This book tries to speak directly to the
reader and is designed in part to be a tool for self-teaching.
That said, this edition differs from the past edition in three major ways: (1) new
material, (2) new and revised homework problems, and (3) an appendix introducing
Simulink.
1. New Content. I have included new and enhanced sections on a number of topics. The
primary additions include material on some MATLAB functions not included in previ-
ous editions (e.g., fsolve, integrate, bvp4c), some new applications of Monte Carlo
for problems such as integration and optimization, and MATLAB’s new way to pass
parameters to function functions.
2. New Homework Problems. Most of the end-of-chapter problems have been modified,
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 dif-
ficult than the problems in the previous edition.
3. I have developed a short primer on Simulink which I have my students read prior to
covering that topic. Although I recognize that some professors may not choose to
cover Simulink, I included it as a teaching aid for those that do.
xiv
PREFACE xv
Aside from the new material and problems, the fourth edition is very similar to the
third. In particular, I have endeavored to maintain most of the features contributing to its
pedagogical effectiveness including extensive use of worked examples and engineering and
scientific 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 straight-
forward 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.
Finally, I want to thank my family, and in particular my wife, Cynthia, for the love,
patience, and support they have provided through the time I’ve spent on this project.
Steven C. Chapra
Tufts University
Medford, Massachusetts
steven.chapra@tufts.edu
PEDAGOGICAL TOOLS
Theory Presented as It Informs Key Concepts. The text is intended for Numerical
Methods users, not developers. Therefore, theory is not included for “theory’s sake,” for ex-
ample no proofs. Theory is included as it informs key concepts such as the Taylor series, con-
vergence, 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 en-
gineering 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.
1.1 MOTIVATION
What are numerical methods and why should you study them?
Numerical methods are techniques by which mathematical problems are formulated
so that they can be solved with arithmetic and logical operations. Because digital comput-
ers excel at performing such operations, numerical methods are sometimes referred to as
computer mathematics.
In the pre–computer era, the time and drudgery of implementing such calculations
seriously limited their practical use. However, with the advent of fast, inexpensive digital
computers, the role of numerical methods in engineering and scientific problem solving
has exploded. Because they figure so prominently in much of our work, I believe that
numerical methods should be a part of every engineer’s and scientist’s basic education.
Just as we all must have solid foundations in the other areas of mathematics and science,
we should also have a fundamental understanding of numerical methods. In particular, we
should have a solid appreciation of both
their capabilities and their limitations.
Beyond contributing to your overall
education, there are several additional
reasons why you should study numerical
methods:
1. Numerical methods greatly expand the
types of problems you can address.
They are capable of handling large sys-
tems of equations, nonlinearities, and
complicated geometries that are not
uncommon in engineering and science
and that are often impossible to solve
analytically with standard calculus. As
such, they greatly enhance your prob-
lem-solving skills.
2. Numerical methods allow you to use
“canned” software with insight. During
1
2 PART 1 MODELING, COMPUTERS, AND ERROR ANALySIS
your career, you will invariably have occasion to use commercially available prepack-
aged computer programs that involve numerical methods. The intelligent use of these
programs is greatly enhanced by an understanding of the basic theory underlying the
methods. In the absence of such understanding, you will be left to treat such packages
as “black boxes” with little critical insight into their inner workings or the validity of
the results they produce.
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 efficient vehicle for learning to use computers. Because nu-
merical methods are expressly designed for computer implementation, they are ideal for
illustrating the computer’s powers and limitations. 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 acknowl-
edge 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 math-
ematics. 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.
With these reasons as motivation, we can now set out to understand how numerical
methods and digital computers work in tandem to generate reliable solutions to mathemati-
cal problems. The remainder of this book is devoted to this task.
This book is divided into six parts. The latter five parts focus on the major areas of nu-
merical methods. Although it might be tempting to jump right into this material, Part One
consists of four chapters dealing with essential background material.
Chapter 1 provides a concrete example of how a numerical method can be employed
to solve a real problem. To do this, we develop a mathematical model of a free-falling
bungee jumper. The model, which is based on Newton’s second law, results in an ordinary
differential equation. After first using calculus to develop a closed-form solution, we then
show how a comparable solution can be generated with a simple numerical method. We
end the chapter with an overview of the major areas of numerical methods that we cover in
Parts Two through Six.
Chapters 2 and 3 provide an introduction to the MATLAB® software environment.
Chapter 2 deals with the standard way of operating MATLAB by entering commands one
at a time in the so-called calculator, or command, mode. This interactive mode provides
a straightforward means to orient you to the environment and illustrates how it is used for
common operations such as performing calculations and creating plots.
1.2 PART ORGANIZATION 3
Chapter 3 shows how MATLAB’s programming mode provides a vehicle for assem-
bling individual commands into algorithms. Thus, our intent is to illustrate how MATLAB
serves as a convenient programming environment to develop your own software.
Chapter 4 deals with the important topic of error analysis, which must be understood
for the effective use of numerical methods. The first part of the chapter focuses on the
roundoff errors that result because digital computers cannot represent some quantities
exactly. The latter part addresses truncation errors that arise from using an approximation
in place of an exact mathematical procedure.
Another random document with
no related content on Scribd:
The success in blending courage with courtesy, bravery with
politeness, which this way of disciplining the youth of the country
may attain, and actually has attained in Japan, is a complete
refutation of the silly notion—so common, alas! in Anglo-Saxon and
Christian lands, that haughtiness in “superiors” and insolence in
“inferiors,” together with the readiness to fight one’s fellows with fists,
swords, or pistols, is a necessary part of a soldier’s preparation for
the most successful resistance to the enemies of one’s country. It is
difficult to conceive of more impressive lessons regarding the effects
produced by different systems of education upon different racial
characteristics than that afforded by the following two incidents. For
some weeks in the Autumn of 1899 I occupied a house in Tokyo,
from the rooms of which nearly everything going on in one of the
large public schools of the city could be either overheard or
overlooked. But not once did a harsh word or a loud cry reach our
ears, or a rude and impolite action our eyes. But during a residence
of a fortnight in similar proximity to one of the best Christian colleges
of India, there was scarcely an hour of the school day when some
seemingly serious uproar was not in evidence in the room beneath
our window. And it was not an uncommon thing to observe both pupil
and teacher standing on their feet and vociferously “sassing” each
other,—with one or more of the other pupils occasionally chiming in.
More suggestive of vital differences, however, is another experience
of mine. Toward the close of the Russo-Japanese war a Japanese
pupil, a Buddhist priest, who had fought in the Chino-Japanese war
and had been decorated for his bravery, had been called out into the
“reserves.” A letter received from him while his regiment was still
waiting to be ordered to the front, after telling how he had left the
school for “temple-boys,” which he had founded on his return from
his studies in this country, and of which he was the Dean, added
these pregnant words: “Pray for us, that we may have success and
victory.” Now it so happened that almost the same mail which
brought this letter, carried to another member of my family a letter
from a Christian Hindū, who had come to this country for theological
study. In this letter, too, there was an appeal to our pious sympathy;
but it took the following form: “Pray for me, that I may be able to bear
the cold.” Surely, Great Britain need not fear an uprising of the
“intellectuals” in India, so long as its babus are educated in such
manner as to foster so unenduring character, however gifted in
philosophical speculation and eloquence of speech.
The system of education now established in Japan, both in its
Universities and in its public schools, has still many weaknesses and
deficiencies, and some glaring faults. Nor are Japanese boys,
especially when they have grown older and become more wise in
their own eyes, always agreeable to their teachers, or easy to
manage and to instruct. But of all this we may perhaps conclude to
speak at another time. This at any rate is certain: There are few
memories in the life-time of at least one American teacher, which he
more gladly recalls, and more delights to cherish, than those which
signalise his many meetings with the school children of Japan: and
among them all, not the least pleasant is that of the three hundred
boys of Kameoka, standing in a row upon the banks of the Katsura-
gawa and shouting their “banzais” to the departing boat.
And, indeed, having already described with sufficient fulness how
one runs the rapids, admires the banks, perhaps visits a shrine or a
tea-house on the way, and arrives in safety to find refreshment and
rest at Arashi-yama, there is nothing more worth saying to be said on
the subject.
CHAPTER III
CLIMBING ASAMA-YAMA