PHYS 27 Scientific Computing Tutorial Documentation
Total Page:16
File Type:pdf, Size:1020Kb
PHYS 27 Scientific Computing Tutorial Documentation Release 1 James E. Hetrick November 17, 2015 CONTENTS 1 Introduction to Scientific Computing3 1.1 What is Scientific Computing ......................................3 1.2 The Scientific Computing Environment.................................4 1.3 The OS and Unix.............................................8 1.4 The Scientific Software Stack...................................... 12 1.5 Homework................................................ 15 2 Installing your Scientific Computing Environment 17 2.1 Overview................................................. 17 2.2 Prepare to Install............................................. 18 2.3 Install VirtualBox............................................ 21 2.4 Creating a Virtual Machine (VM).................................... 27 2.5 Defining the VM............................................. 27 2.6 Turn on Virtualization in your BIOS?.................................. 29 2.7 Configuring the VM........................................... 31 2.8 Attach the Fedora Scientific ISO Disk.................................. 37 2.9 Installing Fedora Scientific on your VM................................. 42 2.10 Booting Linux from the DVD...................................... 42 2.11 Install to Your Hard Drive........................................ 44 2.12 Create Root and User Accounts..................................... 49 2.13 Boot Linux from Your Hard Drive.................................... 52 2.14 Installing ” Guest Additions ” on your VM............................... 55 2.15 First Look at Linux............................................ 55 2.16 Prepare for Guest Additions....................................... 62 2.17 Upgrade your Kernel........................................... 65 2.18 Configuring the Look-and-Feel..................................... 72 2.19 Shared Folders.............................................. 72 2.20 Terminal/Shell Startup Configuration: the .bashrc file........................ 75 2.21 Examine .bashrc ........................................... 77 2.22 Fixing the Shared Folders........................................ 80 2.23 Fonts and Colors............................................. 83 2.24 Homework................................................ 84 3 Basic Unix Skills 85 3.1 Moving Around in the Unix World................................... 85 3.2 Get Some Files.............................................. 85 3.3 The Unix File System.......................................... 85 3.4 The Directories . and .. ........................................ 88 3.5 Pathnames................................................ 89 3.6 Unix commands for files and directories................................. 90 3.7 Understanding pathnames........................................ 93 i 3.8 Command Summary........................................... 95 3.9 Copy, Move, Delete, and Examine Unix Files.............................. 95 3.10 Video for this section........................................... 95 3.11 Copying Files and Directories...................................... 95 3.12 Moving and Renaming Files and Directories.............................. 97 3.13 Removing Files and Directories..................................... 100 3.14 Manipulating the contents of files.................................... 101 3.15 Searching the contents of a file...................................... 102 3.16 Sort the contents of a file......................................... 104 3.17 Command Summary........................................... 106 3.18 Controlling Data Flow.......................................... 107 3.19 The Pipe: | ................................................ 111 3.20 Command Summary........................................... 113 3.21 Homework................................................ 113 4 The Text Editor 115 4.1 The Text Editor.............................................. 115 4.2 Learning More About Emacs...................................... 122 4.3 Intermediate Emacs........................................... 137 4.4 Homework................................................ 151 5 Scientific Visualization 153 5.1 Scientific Visualization.......................................... 153 5.2 More fun with Gnuplot.......................................... 168 5.3 3-D Plots with Gnuplot.......................................... 172 5.4 Plotting Data from a File......................................... 178 5.5 Homework................................................ 182 6 Data Analysis 183 6.1 User Defined Functions......................................... 183 6.2 Fitting Functions to Data......................................... 186 6.3 Fitting Data II.............................................. 189 6.4 Saving and Printing........................................... 206 6.5 Homework................................................ 210 6.6 A Worked Example: Theory meets Experiment............................. 210 7 Scientific Publication 219 7.1 Scientific Publications.......................................... 219 7.2 Latex Document Environments and Layout............................... 225 7.3 Error Messages from Latex....................................... 245 7.4 Homework................................................ 249 8 Intermediate LaTeX 253 8.1 LaTeX Error Messages.......................................... 253 8.2 Physics Department LaTeX Templates.................................. 253 9 Scientific Drawings 255 9.1 Using Xfig for Drawings......................................... 255 9.2 Starting Xfig............................................... 259 9.3 Using Xfig................................................ 260 9.4 Homework................................................ 266 10 Remote Login and File Transfer 267 10.1 Remote Login and File Transfer..................................... 267 10.2 Get Connected with SSH......................................... 269 ii 10.3 SFTP and SCP.............................................. 272 10.4 Homework................................................ 277 11 Symbolic Math and Numerical Linear Algebra 279 11.1 Symbolic Math and Numerical Linear Algebra............................. 279 11.2 Linear Algebra.............................................. 288 11.3 Homework................................................ 295 iii iv PHYS 27 Scientific Computing Tutorial Documentation, Release 1 Contents: CONTENTS 1 PHYS 27 Scientific Computing Tutorial Documentation, Release 1 2 CONTENTS CHAPTER ONE INTRODUCTION TO SCIENTIFIC COMPUTING 1.1 What is Scientific Computing In this course we will learn some of the basic techiniques involved in using your computer to do scientific tasks. Since our course has students with different experience using computers, some tasks will be familiar (I hope to start out that way), and some will not. Along the way, I hope to add a few simple applications to your computer that will help you be a better scientist, engineer, mathematician, or philosopher, astronomer, accountant, of whatever it is that you do. The tools (software) and techniques that you use when doing science with your computer, are somewhat different than those that you use when you use your computer for doing other, non-scientific, tasks. Let’s examine the differences between these two ways of using your computer. That will help us outline the things that we will study in this course. 1.1.1 Non-scientific computing: While you might do several of the following things in the course of some scientific project, these computer activities would not be considered scientific computing • Email • Surfing the Internet • Word Processing (non-scientific) • Organizing and saving information in documents (files). • Using a spreadsheet for bookeeping or tabulating things. • Listening to / downloading / making music • Editing movies • Storing pictures • Gaming 1.1.2 Scientific Computing When using your computer for science, you do many different things. These might include 3 PHYS 27 Scientific Computing Tutorial Documentation, Release 1 Scientific Computing Activities • Analyzing data, for example: – doing statistics on data to compare with theories – curve fitting to find mathematical relations in data • Graphing data and mathematical functions: scientific visualization • Doing algebra and calculus using the computer: symbolic mathematics • Numerical calculations: – computing numerical approximations to mathematical quantites like definate integrals (often called numerical quadrature ) – linear algebra (vector and matrix computations) – solving systems of linear equations – solving non-linear equations – and much more... (like computational fluid dynamics and lattice quantum chromodynamics ) • Scientific publication • Scientific programming There are lots more, not covered in this course, such as: • Machine Learning • Recording data from experiments • Solving differential equations • Computational Chemistry • Computational Fluid Dynamaics • Lattice Quantum Chromodynamics It is these types of scientific tasks that we will cover in this course (except the last item). Many of these topics are the subject of Ph.D. theses, and one could devote decades to learning how to do them well. Our goal is much simpler. Our Goal in this course To introduce you to some of these topics in order to get you started, and To outfit your computer with the free tools needed to do so. With just this, and a little diligence (i.e. webhunting for examples and tutorials) you’ll be surprised how much more useful your computer can be. First, we must setup a scientific