Essentials of Scientific Computing} \Author{Kevin Cooper}
Total Page:16
File Type:pdf, Size:1020Kb
Essentials of Scientific Computing Kevin Cooper October 19, 2016 2 Copyright c Kevin Cooper 2016 Contents 0 Introduction 7 0.1 Example – the problem . .8 1 Networking Concepts 11 1.1 Background . 12 1.1.1 Ethernet . 14 1.1.2 Colors . 15 1.2 Packets and the TCP/IP Suite . 16 1.3 Public Key Encryption . 21 1.4 Running commands on a remote computer . 21 1.5 File transfer . 24 1.5.1 Basic FTP commands . 25 2 The World Wide Web 29 2.1 The Browser . 29 2.1.1 Browser Motivation . 30 2.1.2 URLs . 31 2.1.3 Local Customization . 33 2.1.4 Editing Web Pages Using a Browser . 36 2.2 Markup Languages . 44 2.3 Hypertext Markup Language . 45 2.3.1 HTML Principles . 46 2.3.2 Links to external objects . 48 2.3.3 Tables . 49 2.4 Cascading Style Sheets . 50 2.4.1 Style Sheet Properties . 52 2.4.2 Style Classes . 54 2.4.3 Style IDs . 55 2.4.4 Pseudo-classes . 56 2.5 MathML . 58 2.5.1 MathML Syntax . 60 2.5.2 MathML Alignments . 65 2.6 SVG . 68 3 4 CONTENTS 3 LATEX 77 3.1 Starting a document . 78 3.2 Commands and Environments . 79 3.3 Headings . 80 3.4 Mathematical Typesetting . 81 3.4.1 Math Mode . 81 3.4.2 Math Notation . 82 3.4.3 Alignment . 84 3.5 Font modifications . 88 3.6 Counting . 89 3.7 Lists . 91 3.8 Boxes, Glue, and Space . 94 3.9 Page Layout . 98 3.10 Figures . 99 3.11 Tables . 102 3.12 Programming . 105 4 Computers 107 4.1 Using a command line . 108 4.1.1 Directory commands . 109 4.1.2 File commands . 112 4.2 SSH . 113 4.3 SFTP . 113 4.4 Computer numbers . 113 5 Matlab 115 5.1 Matlab Basics . 116 5.2 Matrices . 123 5.3 Elementwise Operations . 128 5.4 Matlab Input and Output . 130 5.5 Matlab Plots . 130 5.6 Matlab Flow Control . 133 5.6.1 Conditionals . 133 5.6.2 for . 135 5.6.3 while . 136 5.6.4 if . 137 5.7 Matlab Programming . 137 5.8 Advanced Matlab Plots . 142 5.8.1 Plot Commands . 142 5.8.2 Plot Parameters . 144 5.9 Matlab Symbolics . 148 CONTENTS 5 6 Maple 155 6.1 Basic Maple . 155 6.1.1 Starting Maple . 155 6.1.2 Expressions . 156 6.1.3 Floating point versus exact arithmetic . 157 6.1.4 Evaluation . 157 6.1.5 Functions . 158 6.2 Maple Arrays . 159 6.2.1 Lists . 159 6.2.2 Sets . 159 6.2.3 Arrays . 160 6.2.4 Vectors and Matrices . 161 6.2.5 Manipulating Arrays . 161 6.3 Flow Control . 162 6.3.1 If . 162 6.3.2 For . 163 6.3.3 while . 163 6.4 Maple Programming . 164 7 Python 167 7.1 Getting Python . 167 7.2 Python Basics . 168 7.2.1 Python as Calculator . 168 7.2.2 Importing Packages . 170 7.2.3 Numpy Functions and Variables . 171 7.2.4 Defining functions . 172 7.3 Data Types . 173 7.4 Arrays . 175 7.5 Ranges . 178 7.6 Functions . 182 7.7 Flow Control . 184 7.7.1 If . 185 7.7.2 For . 186 7.8 Classes . 188 7.9 Strings . 190 7.10 Speed . 191 7.11 Plots . 194 7.12 Symbolics . 197 6 CONTENTS Chapter 0 Introduction In the twenty-first century science flows in a river of computing technology. Sci- entists store their measurements in sophisticated databases that they access and manage across networks. They use powerful software to analyze and model those data. They publish the results in a finished form, both in print and on the World Wide Web. A scientist or mathematician who is ignorant of all the tools of this computing technology will soon drown. Certainly, there are com- puting support personnel that can throw a life ring, perhaps graduate students can be hired to manage a raft of computers, but in the end, a scientist who does not have at least a rudimentary understanding of the tools of modern scientific computing will not navigate the river successfully. In this document we discuss some of the most common tools needed by a modern investigator in mathematical and scientific disciplines. The topics are quite varied, ranging from tools used in reporting results to the tools actually used in the analysis and modeling of data. In most cases we present software and techniques that are actually in use now. In a few cases, we try to do some foreshadowing, bringing in tools we think will be used heavily in the relatively near future. To illustrate this information we will examine the tasks required of a person who wants to analyze data from a database somewhere on the Internet, and then present the results in a mathematical paper or on the World Wide Web. We will necessarily consider a very simple example, so that anyone with a beginning undergraduate background in mathematics can follow it. The stress will not be on the science or mathematics, but instead on the computing tools required to make the final report happen. The proper order of the topics could be debated. It might be argued that analysis comes first, and writing and reporting comes later. On the other hand, one might need to use the Internet extensively early in order to download data from a remote site, or in monitoring equipment at that site. We will not worry excessively about the order in which the tools would be used in actually pro- ducing the science and reports about it. We instead begin by discussing the Internet itself and the ideas that make it work. We then discuss the World Wide 7 8 CHAPTER 0. INTRODUCTION Figure 1: Total landings of commercial fisheries in the U.S. (metric tons) Web and the tools that make it a powerful instrument for retrieving and dissemi- nating data, and particularly scientific and mathematical information. Following that we will spend some time discussing the defacto standard for typesetting mathematical documents. Many areas of science do not use LATEX, but since it remains the most sophisticated software for typesetting documents that use mathematical notation, and because its syntax is widely used among other programs such as Microsoft Word and LibreOffice, we will present it in detail. We finish with a discussion of several commonly-used mathematical/statistical packages: Matlab, Maple, Python/Scipy/Sympy, and R. These represent a wide array of modern scientific software packages. We cannot possibly do justice to all of the software in current use for statistical and mathematical analysis, but these packages and languages.