Thompson - Computing for Scientists and Engineers (523188), страница 5
Текст из файла (страница 5)
In order to keep the programs easy to read, I have not included extensivechecking of the allowed range of input variables, such as choices that control program options. My rule of thumb has been to put in a range check if I made an input1.3 ONE PICTURE IS WORTH 1000 WORDS11error while testing a program, or if lack of a check is likely to produce confusing results.
There are checks for array bounds if they are simple to code and do not interrupt program flow. Errors of use or input that are diagnosed by our C programsalways begin with a double exclamation, ! !, followed by an explanation of the error.Program execution will often continue after some reasonable fix-up is attempted. Atypical fix-up is just to request another input for the troublesome variable.Because the programs are written to be translated easily to Fortran or Pascal, asdescribed in a previous subsection and shown in the appendix, I have tried to avoidnonstandard parts of C. The compiler that I use claims to follow ANSI standards.
Ialso checked for compatibility with the C language as described in the second editionof Kernighan and Ritchie’s book.In spite of all these precautions, I have two words of advice: caveat emptor — letthe buyer beware. The programs are supplied as is and are not guaranteed. Foreach program you use, I suggest that you make at least the checks I have indicated.If you can devise other tests of program correctness, I encourage you to do so.The index to computer programsBecause this book has many computer programs with associated functions, I haveincluded an annotated index to all the programs and functions.
They are listed, byorder of appearance, in the index that immediately precedes the regular index. Theprograms and functions also appear alphabetically by name in the regular index.1.3ONE PICTURE IS WORTH 1000 WORDSIn this book graphical output is usually suggested as a way to improve the presentation of results, especially in the projects.
Since graphics are so hardware dependent,my suggestions for graphics in the projects are necessarily vague. You should familiarize yourself as much as practicable with techniques of graphical presentation.If you have access to a powerful system that combines graphics and mathematics,such as Mathematica as described by Wolfram or by Wagon, you may wish to develop some of the projects by using such a system.Why and when you should use graphicsTufte, in his two books on displaying and envisioning quantitative information, hasgiven very interesting discussions and examples of effective (and ineffective) waysof displaying quantitative information from a variety of fields.
In numerical applications of mathematics, graphics are especially important because of the enormousnumber of numbers that come spewing out of the computer in a stream of numericalenvironmental pollution. If there are many values to be compared, or if you want toshow trends and comparisons (as we usually do), it is worth the effort to write agraphical interface for your program.
If there are just a few check values to output,12INTRODUCTIONit is not worth the extra coding and possible lack of clarity that graphics mayproduce.If you have access to Mathematica or some other system that combines mathematics, numerics, and graphics, your learning will be enhanced if you combine thethree elements when working the exercises and projects. Wagon’s book providesmany examples of graphics techniques that would be useful in conjunction with thisworkbook.Impressive graphics, or practical graphicsIn many books that relate to computing you will see elegant and impressive graphicsthat have been produced by long runs on powerful computers using special-purposeprograms. Although these illustrations may improve your comprehension, and perhaps inspire you to become a computer-graphics artist, their production is usuallynot practicable for most computer users. Therefore, I urge you to find a simplegraphics system that interfaces easily to your programming environment, that isreadily available to you, and that is inexpensive to use.
For example, there are abouta hundred line drawings in this book. They were all produced by using only twoapplications programs (one for graphics and one for drafting). The graphics program used input files that the C programs produced, so the numbers were seldomtouched by human hand, and the graphics output was produced on the same laserprinter that printed the text.Many of the programs in this book produce simple output files. I most oftenused these files for input to graphics, and sometimes for preparing tables. If youmake a similar interface and use it often to produce graphics (perhaps through theintermediary of a spreadsheet), I think it will improve your comprehension of thenumerical results, without burdening you with much coding effort.If you have convenient access to a state-of-the-art graphics system, it may beuseful for a few of the projects in this book.
Just as I believe that an approach to numerical computing that is completely recipe-based is unwise, I believe that usingcomputer-graphics systems without an understanding of their background is similarly unwise. A comprehensive treatment of many aspects of computer graphics isprovided in the treatise by Foley et al. Methods for preparing high-resolutiongraphics, and how to implement them in Pascal, are described in the book by Angelland Griffith.1.4 SUGGESTIONS FOR USING THIS BOOKThis book may be used for both self-study and for class use. I have some suggestions that should help you to make most effective use of it. First I indicate the conections between the remaining nine chapters, then there are remarks about the exercises and the projects.1.4 SUGGESTIONS FOR USING THIS BOOK13Links between the chaptersBecause we cover a large amount of territory and a variety of scientific and engineering landscapes in this book, it is useful to have an indication of the connections between its nine other chapters.
Table 1.1 summarizes the strength of the links between the chapters.TABLE 1.1 Cross-reference chart for use of this book.Key:chapter above is necessary preparationchapter above is desirable preparationchapter above is optional preparationComplex variablesPower seriesNumerical derivatives and integralsFitting curves through dataLeast-squares analysis of dataIntroduction to differential equationsSecond-order differential equationsDiscrete Fourier transforms and seriesFourier integral transformsFor example, if you plan to work through Chapter 7 (introduction to differentialequations), use of Chapters 2, 5, and 6 is optional, Chapter 3 (power series) is desirable, whereas Chapter 4 (numerical derivatives and integrals) is necessary preparation.
Within each chapter you should read not only the text, but also the exercises,which are embedded in the text. Exercises containing equations are especially important to be read, since these equations often form part of the development. Therefore, read over every exercise, even if you don’t work it through in detail.The exercises and projectsSince this book has an overwhelming number of exercises, many of them nontrivial,a guide to use of the exercises is appropriate. It will be clear to you that I always insert an exercise whenever I don’t want to show you all the steps of a development.This is not laziness on my part, because I assure you that I have worked through every step.
Rather, an exercise provides a checkpoint where you should pause, takestock of what you have been reading, then test your understanding by trying the exercise. If you have difficulty with this exercise, reread all of the subsectioncontaining the exercise, even past the troublesome exercise. Then work the exercise14INTRODUCTIONonce more.
I believe that by doing this you will have a realistic estimate of your progress in comprehension. If you are using this book for self-study, this procedureshould help you considerably.Some exercises are more than checkpoints, they are crossroads where conceptsand techniques developed previously are focused on relevant and interesting problems. This type of exercise, which often appears in a project toward the ends ofchapters, is always indicated.
Such exercises provide very good tests of your overall comprehension of the material in the current and previous chapters.The projects, of which there is at least one per chapter after this introductorychapter, are designed to bring together many of the aspects of analysis and numericsemphasized within the chapter.
They provide you with opportunities to explore thenumerics and the science by using the number-crunching and graphical powers ofcomputers. Programming aspects of the projects are discussed in Section 1.2.REFERENCES FOR THE INTRODUCTIONGeneral referencesAngell, I. O., and G. Griffith, High-Resolution Computer Graphics Using Pascal,Macmillan Education, Basingstoke, England, 1988.Dym, C. L., and E. S. Ivey, Principles of Mathematical Modeling, Academic Press,New York, 1980.Foley, J. D., A.
van Dam, S. K. Feiner, and J. F. Hughes, Computer Graphics,Addison-Wesley, Reading, Massachusetts, third edition, 1990.Gould, H. and J. Tobochnik, An Introduction to Computer Simulation Methods,Addison-Wesley, Reading, Massachusetts, 1988.Koonin, S. E., Computational Physics, Addison-Wesley, Redwood City,California, 1986.Koonin, S. E., and D. C. Meredith, Computational Physics: FORTRAN Version,Addison-Wesley, Redwood City, California, 1990.Mesterton-Gibbons, M., A Concrete Approach to Mathematical Modelling,Addison-Wesley, Reading, Massachusetts, 1989.Meyer, W. J., Concepts of Mathematical Modeling, McGraw-Hill, New York,1984.Modi, J.
J., Parallel Algorithms and Matrix Computation, Clarendon Press, Oxford,England, 1988.Nakamura, S., Computational Methods in Engineering and Science, WileyInterscience, New York, 1986.Taylor, A. E., and W. R. Mann, Advanced Calculus, Wiley, New York, third edition, 1983.Thompson, W. J., Computing in Applied Science, Wiley, New York, 1984.REFERENCES FOR THE INTRODUCTION15Tufte, E. R., The Visual Display of Quantitative Information, Graphics Press,Cheshire, Connecticut, 1983.Tufte, E. R., Envisioning Information, Graphics Press, Cheshire, Connecticut,1990.Wagon, S., Mathematica in Action, W. H.