A First Course In Scientific Computing

2y ago
1.72 MB
239 Pages
Last View : 1m ago
Last Download : 1y ago
Upload by : Mollie Blount

A First Course inScientific ComputingSymbolic, Graphic, and NumericModeling Using Maple, Java,Mathematica, and Fortran90Fortran VersionRUBIN H. LANDAUFortran Coauthors:KYLE AUGUSTSONSALLY D. HAERERPRINCETON UNIVERSITY PRESSPRINCETON AND OXFORD

iic 2005 by Princeton University PressCopyright 41 William Street, Princeton, New Jersey 085403 Market Place, Woodstock, Oxfordshire OX20 1SYAll Rights Reserved

ContentsPrefacexiiiChapter 1. Introduction1.1Nature of Scientific Computing1.2Talking to Computers1.3Instructional Guide1.4Exercises to Come Back To1246PART 1. MAPLE OR MATHEMATICA BY DOING(SEE TEXT OR CD)9PART 2.FORTRAN BY DOINGChapter 9. Getting Started with Fortran9.1Another Way to Talk to a Computer9.2Fortran Program Pieces9.3Entering and Running Your First Program9.4Looking Inside Area.f909.5Key Words9.6Supplementary ExercisesChapter 10. Data Types, Limits, Procedures; Rocket Golf10.1 Problem and Theory (same as Chapter 3)10.2 Fortran’s Primitive Data Types10.3 Integers10.4 Floating-Point Numbers10.5 Machine Precision10.6 Under- and OverflowsNumerical Constants10.7 Experiment: Determine Your Machine’s Precision10.8 Naming 0211211212212214

ivCONTENTS10.9 Mathematical (Intrinsic) Functions10.10 User-Defined Procedures: Functions and SubroutinesFunctionsSubroutines10.11 Solution: Viewing Rocket GolfAssessment10.12 Your Problem: Modify Golf.f9010.13 Key Words10.14 Further ExercisesChapter 11. Visualization with Fortran11.1 An Overview of Dislin2-D Graphs within Fortran using DislinRunning the Sample ProgramDislin Matrix PlotsDislin Surface Plots11.2 Setting up Dislin *11.3 Gnuplot BasicsPrinting PlotsGnuplot Surface (3-D) PlotsChapter 12. Flow Control via Logic; Projectiles12.1 Problem: Frictionless Projectile Motion12.2 Theory: Kinematics12.3 Computer Science: Designing Structured ProgramsFlow Charts and Pseudocode12.4 Flow Control via LogicConditional and Relational OperatorsControl StructuresSelect Case12.5 Implementation: projectile.f9012.6 Solution: Projectile Trajectories12.7 Key Words12.8 Supplementary ExercisesChapter 13. Fortran Input and Output13.1 Basic I/O13.2 Formatted Output13.3 File I/OChapter 14. Numerical Integration; Power and Energy Usage14.1 Problem (Same as Chapter 6): Power and Energy14.2 Algorithms: Trapezoid and Simpson’s RulesTrapezoid 257258259260262262263264

CONTENTS14.3 Implementation: Trap.f90Implementation with Nested LoopsImproved Method: Simpson’s Rule14.4 Assessment: Which Rule Is Better?14.5 Key Words and Concepts14.6 Supplementary ExercisesChapter 15. Differential Equations with Maple and Fortran*15.1 Problem: Projectile Motion with Drag15.2 Model: Velocity-Dependent Drag15.3 Algorithm: Numerical Differentiation15.4 Math: Solving Differential EquationsImplementation: ProjectileAir.f9015.5 Assessment: Balls Falling Out of the Sky?Improved Algorithm: Verlet*15.6 Maple: Differential-Equation ToolsExtract Right-Hand Side: rhsSecond-Order ODE with PlotSystem of ODEs15.7 Maple Solution: Drag Velocity15.8 Extract OperandsSolution for R and T15.9 Drag v 2 (Exercise)15.10 Drag v 3/2Defining Functions from Procedures15.11 Exploration: Planetary Motion*Implementation: Planet.java*15.12 Key Words15.13 Supplementary ExercisesChapter 16. Object-Oriented Programming; Complex Currents16.1 Problem: Resonance in RLC Circuit16.2 Math: Complex NumbersComplex Arithmetic Review16.3 Theory: Resistance Becomes ImpedanceSolution for Complex Current16.4 CS: Abstract Data Types, Objects16.5 Objects in FortranData by ReferenceSample Data TypeObject ConstructorsDeclaring and Creating ObjectsInstances16.6 Fortran Solution: Complex 93296297298299301301301305305306306

viCONTENTS16.7 Maple Solution: Complex CurrentsMaple’s Surface Plots of Complex Impedance16.8 Key Words16.9 Fortran and Maple ExercisesChapter 17. Arrays: Vectors, Matrices; Rigid-Body Rotations17.1 Problem: Rigid-Body Rotations17.2 Theory: Angular-Momentum Dynamics17.3 Computer Science and Math: Arrays vs. Vectors andMatrices17.4 Array Declaration and InstantiationArray SizesFixed-Sized ArraysAssumed-Shape Arrays*Allocatable Arrays*17.5 Arrays as Arguments to Procedures*Computation: Changing Array Arguments in Functions17.6 Application to Rotations17.7 Key Words17.8 Supplementary ExercisesChapter 18. Advanced Function Methods, Objects18.1 Procedure Modules and Interfaces18.2 Changing the Arguments of a Function18.3 Functions Calling Functions18.4 Function OverloadingChapter 19. Discrete Math, Arrays as Bins; Bug Dynamics*19.1 Problem: Variability of Bug Populations19.2 Theory: Self-Limiting Growth, Discrete Maps19.3 Assessment: Properties of Nonlinear Maps19.4 Exploration: Bifurcation Diagram, Bugs.f90*Implementation; Bifurcation DiagramBinning19.5 Exploration: Other Discrete Maps*Chapter 20. 2-D Arrays: File I/O, PDE’s; Realistic Capacitor20.1 Problem: Field of Realistic Capacitor20.2 Theory and Model: Electrostatics and PDEsLaplace’s Partial Differential Equation*20.3 Algorithm: Finite Differences20.4 Implementation: LaplaceFile.f90LaplaceFile.f90 Orientation and Visualization20.5 2343344344344346346348349350

viiCONTENTS20.620.7Exploration: 3-D Capacitor*Key WordsChapter 21. Web Computing (see Java Version)352352353LATEX SURVIVAL GUIDE355Chapter 22. LATEX for Text22.1 Why LATEX?22.2 Structure of a LATEX Document22.3 Sample Input File (Sample.tex)22.4 Sample LATEX OutputBrief Look at Input FileSpecial CharactersParagraphs, Spaces, and BreaksQuotation Marks and Dashes22.5 Fonts for TextType SizesFancy Text AccentsMath Symbols in Text22.6 Environments22.7 ListsText TablesFloating Tables22.8 SectionsSubsectionsQuotations and Footnotes357PART 3.Chapter 23. LATEX for Mathematics23.1 Entering Mathematics: Math Mode23.2 Mathematical Symbols and GreekGreek LettersRelationsNegative RelationsBinary (and Other) OperatorsArrowsMath ParenthesesMiscellaneous Math Symbols“Big” Operators23.3 Math Accents23.4 Superscripts and Subscripts23.5 Calculus and Sums23.6 Changing Math 5375376

ath FunctionsFractionsRootsBrackets (Delimiters)Multiline EquationsMatrices and Math ArraysIncluding GraphicsExercise: Putting It All Together376376377377378379380382Appendix A. Glossary386Appendix B. Fortran Quick ReferenceB.1Transferring Files from the CDB.2Using our Fortran Programs395Bibliography400Index405398399

List of Figures1.11.2Left: Computational science is a multidisciplinary field thatcombines science with computer science and mathematics. Right:A new paradigm for science in which simulation plays as essential a role as does experiment and theory.A schematic view of a computer’s kernel and shells.9.1Steps in compiling and executing.10.1 A schematic representation of the limits of single-precisionfloating-point numbers, and the consequences of exceeding thoselimits.10.2 Left: The structure of a Fortran program with no procedures.Right: The structure of a Fortran program with a main program, a subroutine, and a function. The main program andthe two procedures are contained in the same source file, forinstance, ProgName.f90.10.3 A plot of the function γ(v) output from the program Golf.f90.Compare to similar plot done with Maple in Chap. Dislin output from the program EasyDislinPlot.f90.The Dislin output from the program MatrixPlot.f90.The Dislin output from the program Laplace.f90.A gnuplot graph for three data sets with impulses and lines.Gnuplot’s surface plot of a scattering amplitude ImT as a function of complex energy E .12.1 Left: The trajectory of a projectile fired with initial velocityV0 in the θ direction. The nonparabolic curve includes air resistance. Right: The components of the initial velocity V0projected onto the x and y axes.12.2 A flow chart illustrating a possible program to compute projectile motion. On the left, we show the very high-level basiccomponents of the program, while on the right, we show someof the details of the logic flow structures.23199210216223231234237239240243246

xLIST OF FIGURES12.3 Left: Sequential or linear programming. Right: The if-thenelse structure, one of several structures used to write nonlinearprogram segments based on logical decisions.24712.4 Left: The Fortran Do-loop iteration. Right: The Fortran Dowhile loop uses a general test, in contrast to the Do-loop’s iteration count.25114.1 The three models of power consumption. Time t is in 100 daysand power is in GigaWatts.26314.2 Left: Straight-line sections used for the trapezoid rule. An individual trapezoid with area h2 [f (xi ) f (xi 1 )] is highlighted.Right: Parabolas used in Simpson’s rule (a single parabola isfit to each pair of consecutive intervals.26414.3 Energy consumption as a function of time for model 1 computed with Maple.26915.1 Left: The gravitational force on a planet a distance r from thesun. The x and y components of the force are indicated. Right:Output from the applet PlanetRHL showing the precession of aplanet’s orbit when the gravitational force 1/r4 .29016.1 Left: An RLC circuit connected to an alternating voltage source.Right: Two RLC circuits connected in parallel to an alternatingvoltage. Observe that one of the parallel circuits has double thevalues of R, L, and C as does the other.29416.2 Representation of a complex number as a vector in space.29516.3 An abstract drawing, or what?29917.1 Left: A plate sitting in the x y plane with a coordinatesystem at its center. Right: A cube sitting in the center of athree-dimensional coordinate system.31318.1 Left: The structure of a Fortran program containing a procedure module. Right: The structure of a Fortran programcontaining a procedure interface.33019.1 The insect population xn versus generation number n for various survival rates: (A) µ 2.8, a period-one cycle; (B)µ 3.3, a period-two cycle; (C) µ 3.5, a period-four cycle; (D) µ 3.8, a chaotic regime.33919.2 The bifurcation plot, attractor populations versus survival rate,for the logistics map.341

LIST OF FIGURES20.1 Left: Electric-field lines betweens the plates of an ideal parallelplate capacitor. The equal spacing and single direction indicatea uniform field. Right: A representation of the field betweenthe plates of a realistic capacitor. The field tends to “fringe”and extend beyond the ends of the plates.20.2 Left: A parallel-plate capacitor within a grounded box. A realistic capacitor would have the plates closer together in orderto condense the field. Right: A visualization of the electric potential for this geometry. The contours projected onto the xyplane give the equipotential surfaces.20.3 Left: The capacitor’s field is computed only for those (x, y)values on the grid. The voltage of the plates and containingbox are kept constant. Right: The algorithm for Laplace’sequation in which the potential at the point (x, y) (i, j) equals the average of the potential values at the four nearestneighbor points.20.4 Contour plot of equipotential surfaces. The electric field linesare perpendicular to these contours and point toward lower potential.xi34534534735122.1 The steps followed and utilities used in preparing a documentwith LATEX. The source file is Paper.tex, the device-independentfile is Paper.dvi, and the file ready for printing/posting isPaper.ps or Paper.pdf.35823.1 A scaled-down and rotated Figure 9.1.381

PrefaceThis book contains an introduction to scientific computing appropriate for all lowerdivision college students. Its goal is to make students comfortable using computers to do science and to provide them with tools and knowledge they can utilizethroughout their college careers. Its approach is to introduce the requisite mathematics and computer science in the course of solving realistic problems. On thataccount care is given to indicate how each discipline uses its own language to describe the same concept, how their tools are useful to us, and how computationsare often concrete examples of abstract ideas.This is easier said than done. On the one hand, lower-division students aresimultaneously learning elementary mathematics and physics, and so this may bethe first place they encounter the science and mathematics used in the problems.On the other hand, in order for the tools and techniques to be useful for more thanthe assigned problem, we give more than an introduction (the original title of thisbook) to the computational tools. We address the first issue in our teaching byreminding the students that our focus is on having them learn the techniques in theproper context, and that any new science and mathematics they become familiarwith will make it easier for them in their other courses. We address the second issueby placing an asterisk * in the title of chapters and sections containing optionalmaterials and by reminding the students of which sections are most appropriatefor the problem at hand.This book covers some of the basics of computation, numerical analysis, andprogramming from a computational science point of view. We want the reader toacquire some ideas of what is possible with computers, what type of tools thereare for it, and how to go about getting all the pieces to work together. After that,it is easy to use on-line help or the references to get more details. As a result, ourpresentation is more practical and more focused on mathematics and science thanan introductory programming or computer science text, with minimal discussionof computer science theory. The book follows our own personal preference for“just enough” computer information in that it avo

A First Course in Scientific Computing Symbolic, Graphic, and Numeric Modeling Using Maple, Java, Mathematica, and Fortran90 Fortran Version RUBIN H. LANDAU Fortran Coauthors: KYLE AUGUSTSON SALLY D. HAERER PRINCETON UNIVERSITY PRESS PRINCETON AND OXFORD

Related Documents:

A Scienti c Molding Skills Portal from Routsis Training combines foundational eLearning with critical skills-development labs. This in-house training system teaches your production personnel how to develop, document, optimize, and evaluate a robust Scienti c Molding process skills that translate directly into

Applied Mathematics 205 Advanced Scienti c Computing: Numerical Methods Course logistics Instructor: Chris H. Rycroft (chr@seas.harvard.edu) . please upload a PDF conversion of it to Canvas. Writing style and LATEX . Numerical Computing with MATLAB. SIAM, 2004. I L. N. Trefethen and D. Bau. Numerical Linear Algebra. SIAM, 1997. .

in an Introduction to Scienti c Computing Course Erin McNelis Western Carolina University Joint Mathematics Meetings San Diego, California . Introduction to MATLAB Programming and Algorithm Development 6 Individual (Agent) - Based Modeling with NetLogo Erin McNelis Environmentally Themed Scienti c Computing 6/23.

3 Scienti c and Organizing Committees 3.1 Scienti c Committee ( ) Liliane Basso Barichello (UFRGS, Porto Alegre, lbaric@mat.ufrgs.br)( ) Piermarco Cannarsa (Universit a di Roma Tor Vergata, Roma,cannarsa@axp.mat.uniroma2.it)( ) Ciro Ciliberto (Universit a di Roma Tor Vergata, Roma, cilibert@axp.mat.uniroma2.it)- co-chair ( ) Giorgio Fotia (Universit a di Cagliari, Giorgio.Fotia@crs4.it)

scienti c measurement is subject to errors, and the role of the scientist is to understand and quantify them (since you cannot avoid them, learn how to deal with them). Let us start with a discussion of some of the possible sources of errors in a scienti c experiment:

Scilab is the contraction of Scienti c Laboratory. Scilab is : a numerical computing software, an interpreted programming environment, used for any scienti c and engineering applications, multi-platform : Windows, MacOS et Linux, Created by researchers from Inria in the 90’s, the software

Coomassie Blue (GelCode Blue Safe Protein Stain ermo Scienti c, Pierce, Rockford, IL, USA) or with Pierce Silver Stain Kit for Mass Spectrometry ( ermo Scienti c).

Parallel Computing Toolbox Ordinary Di erential Equations Partial Di erential Equations Conclusion Lecture 8 Scienti c Computing: Symbolic Math, Parallel Computing, ODEs/PDEs Matthew J. Zahr CME 292 Advanced MATLAB for Scienti c Computing Stanford University 30th April 2015 CME 292: Advanced MATLAB for SC Lecture 8. Symbolic Math Toolbox .