




























































































Estude fácil! Tem muito documento disponível na Docsity
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
Esta página não é visível na pré-visualização
Não perca as partes importantes!





























































































Models, Methods, and Analysis
with MATLAB and MPI
A CRC Press Company Boca Raton London New York Washington, D.C.
COMPUTATIONAL
MATHEMATICS
Computational Mathematics:
Models, Methods and Analysis
with
MATLAB and MPI
List of Figures ix
List of Tables xi
Preface xiii
CONTENTS vii
9.6 GMRES(m) and MPI........................ 372
Bibliography 379
This book evolved from the need to migrate computational science into under- graduate education. It is intended for students who have had basic physics, programming, matrices and multivariable calculus.
The choice of topics in the book has been influenced by the Undergraduate Computational Engineering and Science Project (a United States Department of Energy funded eort), which was a series of meetings during the 1990s. These meetings focused on the nature and content for computational science undergraduate education. They were attended by a diverse group of science and engineering teachers and professionals, and the continuation of some of
University in fall semesters since 1992. The other four chapters were developed in 2002 and taught in the 2002-03 academic year.
The department of mathematics at North Carolina State University has given me the time to focus on the challenge of introducing computational science materials into the undergraduate curriculum. The North Carolina Supercom-
tutorials and computer time on supercomputers. Many students have made important suggestions, and Carol Cox Benzi contributed some course materials
with the initial use of MATLAB
. MATLAB is a registered trademark of The MathWorks, Inc. For product information, please contact:
The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098 USA Tel: 508-647- Fax: 508-647-
? A.
xiii
Variations of Chapters 1-4 and 6 have been taught at North Carolina State
these activities can be found at the Krell Institute, http://www.krellinst.org.
puting Center, http://www.ncsc.org, has provided the students with valuable
Web: www.mathworks.com http://www.mathworks.com/
E-mail: [email protected]
Computational science is a blend of applications, computations and mathemat- ics. It is a mode of scientific investigation that supplements the traditional laboratory and theoretical methods of acquiring knowledge. This is done by formulating mathematical models whose solutions are approximated by com- puter simulations. By making a sequence of adjustments to the model and subsequent computations one can gain some insights into the application area under consideration. This text attempts to illustrate this process as a method for scientific investigation. Each section of the first six chapters is motivated by a particular application, discrete or continuous model, numerical method, computer implementation and an assessment of what has been done.
Applications include heat diusion to cooling fins and solar energy storage, pollutant transfer in streams and lakes, models of vector and multiprocessing computers, ideal and porous fluid flows, deformed membranes, epidemic models with dispersion, image restoration and value of American put option contracts. The models are initially introduced as discrete in time and space, and this allows for an early introduction to partial dierential equations. The discrete models have the form of matrix products or linear and nonlinear systems. Methods in- clude sparse matrix iteration with stability constraints, sparse matrix solutions via variation on Gauss elimination, successive over-relaxation, conjugate gradi- ent, and minimum residual methods. Picard and Newton methods are used to approximate the solution to nonlinear systems.
Most sections in the first five chapters have MATLAB
the very aordable current student version of MATLAB. They are intended to be studied and not used as a "black box." The M ATLAB codes should be used as a first step towards more sophisticated numerical modeling. These codes do provide a learning by doing environment. The exercises at the end of each section have three categories: routine computations, variation of models, and mathematical analysis. The last four chapters focus on multiprocessing algorithms, which are implemented using message passing interface, MPI; see
Rocks" cluster software. These chapters have elementary Fortran 9x codes to illustrate the basic MPI subroutines, and the applications of the previous chapters are revisited from a parallel implementation perspective.
xv
codes; see [14] for
[17] for information about building your own multiprocessor via free "NPACI
xvi INTRODUCTION
lectures. Routine homework problems are assigned, and two projects are re-
work experiences. This forms a semester course on numerical modeling using partial dierential equations. be studied after Chapter 1 so as to enable the student, early in the semester, to become familiar with a high performance computing environment. Other course possibilities include: a semester course with an emphasis on mathemat-
parallel computation using Chapters 1 and 6-9 or a year course using Chapters 1-9. This text is not meant to replace traditional texts on numerical analysis, matrix algebra and partial dierential equations. It does develop topics in these areas as is needed and also includes modeling and computation, and so there is more breadth and less depth in these topics. One important component of computational science is parameter identification and model validation, and this requires a physical laboratory to take data from experiments. In this text model assessments have been restricted to the variation of model parameters, model evolution and mathematical analysis. More penetrating expertise in various aspects of computational science should be acquired in subsequent courses and work experiences. Related computational mathematics education material at the first and sec- ond year undergraduate level can be found at the Shodor Education Founda- tion, whose founder is Robert M. Pano, web site [22] and in Zachary’s book on programming [29]. Two general references for modeling are the undergradu- ate mathematics journal [25] and Beltrami’s book on modeling for society and biology [2]. Both of these have a variety of models, but often there are no computer implemenations. So they are a good source of potential computing projects. The book by Landau and Paez [13] has number of computational physics models, which are at about the same level as this book. Slightly more advanced numerical analysis references are by Fosdick, Jessup, Schauble and Domik [7] and Heath [10]. The computer codes and updates for this book can be found at the web site:
The computer codes are mostly in M ATLAB for Chapters 1-5, and in Fortran 9x for most of the MPI codes in Chapters 6-9. The choice of Fortran 9x is the author’s personal preference as the array operations are similar to those in MATLAB. However, the above web site and the web site associated with Pacheco’s book [21] do have C versions of these and related MPI codes. The web site for this book is expected to evolve and also has links to sequences of heat and pollution transfer images, book updates and new reference materials.
At North Carolina State University Chapters 1-4 are covered in 26 75-minute
quired, which can be chosen from topics in Chapters 1-5, related courses or
Chapter 6 on high performance computing can
ical analysis using Chapters 1-3, 8 and 9, a semester course with a focus on
http://www4.ncsu.edu/~white.
Computers use a finite subset of the rational numbers (a ratio of two in- tegers) to approximate any real number. This set of numbers may depend on the computer being used. However, they do have the same general form and are called floating point numbers. Any real number { can be represented by an infinite decimal expansion { = ±(={ 1 · · · {g · · · )10h, and by truncating this we can define the chopped floating point numbers. Let { be any real number and denote a floating point number by
i o({) = ±={ 1 · · · {g 10 h = ±({ 1 @10 + · · · + {g@ 10 g)10h=
This is a floating point number with base equal to 10 where { 1 is not equal to zero, {l are integers between 0 and 9, the exponent h is also a bounded integer and g is an integer called the precision of the floating point system. As- sociated with each real number, {, and its floating point approximate number, i o({), is the floating point error, i o({) {. In general, this error decreases as the precision, g, increases. Each computer calculation has some floating point or roundo error. Moreover, as additional calculations are done, there is an accumulation of these roundo errors.
Example. Let { = 1 = 5378 and i o({) = 0 =154 10^1 where g = 3. The roundo error is i o({) { = = 0022 =
The error will accumulate with any further operations containing i o({), for example, i o({)^2 = =237 10^1 and
i o({)^2 {^2 = 2= 37 2 =36482884 = = 00517116 =
Repeated calculations using floating point numbers can accumulate significant roundo errors.
Consider the cooling of a well stirred liquid so that the temperature does not depend on space. Here we want to predict the temperature of the liquid based on some initial observations. Newton’s law of cooling is based on the observation that for small changes of time, k, the change in the temperature is nearly equal to the product of the constant f, the k and the dierence in the room temperature and the present temperature of the coee. Consider the following quantities: xn equals the temperature of a well stirred cup of coee at time wn, xvxu equals the surrounding room temperature, and f measures the insulation ability of the cup and is a positive constant. The discrete form of Newton’s law of cooling is
xn+1 xn = fk(xvxu xn) xn+1 = (1 fk)xn + fk xvxu = dxn + e where d = 1 fk and e = fk xvxu =
The long run solution should be the room temperature, that is, xn should converge to xvxu as n increases. Moreover, when the room temperature is constant, then xn should converge monotonically to the room temperature. This does happen if we impose the constraint
0? d = 1 fk>
called a stability condition, on the time step k. Since both f and k are positive, d? 1.
The model in this case appears to be very simple. It consists of three constants x 0 > d> e and the formula xn+1 = dxn + e (1.1.1)
The formula must be used repeatedly, but with dierent xn being put into the right side. Often d and e are derived from formulating how xn changes as n increases (n reflects the time step). The change in the amount xn is often modeled by gxn + e xn+1 xn = gxn + e
where g = d 1 = The model given in (1.1.1) is called a first order finite dierence model for the sequence of numbers xn+1. Later we will generalize this to a sequence of column vectors where d will be replaced by a square matrix.
The "iterative" calculation of (1.1.1) is the most common approach to solving (1.1.1). For example, if d = 12 > e = 2 and x 0 = 10, then
x 1 =
x 2 =
x 3 =
x 4 =
If one needs to compute xn+1 for large n, this can get a little tiresome. On the other hand, if the calculations are being done with a computer, then the floating point errors may generate significant accumulation errors. An alternative method is to use the following "telescoping" calculation and the geometric summation. Recall the geometric summation
1 + u + u^2 + · · · + un^ and (1 + u + u^2 + · · · + un)(1 u) = 1 un+
w is the time array whose first entry is the initial time. The array | stores the approximate temperature values whose first entry is the initial temperature. The value of f is based on a second observed temperature, |_revhu, at time equal to k_revhu. The value of f is calculated in line 10. Once d and e have been computed, the algorithm is executed by the for loop in lines 16-19. Since the time step k = 1, q = 300 will give an approximation of the temperature over the time interval from 0 to 300. If the time step were to be changed from 1 to 5, then we could change q from 300 to 60 and still have an approximation of the temperature over the same time interval. Within the for loop we could look at the time and temperature arrays by omitting the semicolon at the end of the lines 17 and 18. It is easier to examine the graph of approximate temperature versus time, which is generated by the M ATLAB command plot(t,y).
70 = 350 65. Figure 1.1.1 indicates the expected monotonic decrease to
In Figure 1.1.2 notice that
Figure 1.1.1: Temperature versus Time
computed solution no longer is monotonic, but it does converge to the steady state solution.
The model continues to degrade as the magnitude of d increases. In the This is consistent with formula (1.1.2). Here we kept the same f, but let the step size increase to k = 15 and in this case d = 1 (2@13)15 = 17 @ 13 and e = fk70 = (2@13)1050 = 2100@ 13 = The vertical axis has units multiplied by 104.
Models of savings plans or loans are discrete in the sense that changes only occur at the end of each month. In the case of the heat transfer problem, the formula for the temperature at the next time step is only an approximation, which gets better as the time step k decreases. The cooling process is continuous because the temperature changes at every instant in time. We have used a discrete model of this, and it seems to give good predictions provided the time step is suitably small. Moreover there are other modes of transferring heat such as diusion and radiation.
There may be significant accumulation of roundo error. On a computer (1.1.1) is done with floating point numbers, and at each step there is some new roundo error Un+1. Let X 0 = i o(x 0 )> D = i o(d) and E = i o(e) so that
Xn+1 = DXn + E + Un+1= (1.1.3)
Figure 1.1.3 the computed solution oscillates and blows up!