Example: tourism industry

Python for Computational Science and Engineering

Introduction toPython for Computational Science and Engineering (A beginner s guide)Hans FangohrFaculty of Engineering and the EnvironmentUniversity of SouthamptonSeptember 7, 20152 Contents1 Computational Modelling .. Modelling .. to support Computational modelling .. Why Python for scientific computing? .. strategies .. it right first, then make it fast .. in Python .. Literature .. video lectures on Python for beginners .. tutor mailing list .. Python version .. This document .. Your feedback ..142 A powerful Python prompt and Read-Eval-Print Loop (REPL) .. Calculator .. Integer division .. to avoid integer division .. should I care about this division problem? .. Mathematical functions .. Variables .. Impossible equations .. +=notation ..233 Data Types and Data What type is it? .. Numbers.

The emphasis is on introducing some basic Python (programming) concepts that are relevant for numerical algorithms. The later chapters touch upon numerical libraries such ... To study a process with a computer simulation we distinguish two steps: the rst one is to develop a model of the real system. When studying the motion of a small object ...

Tags:

  Programming, Python, Computational, Engineering, Sciences, Simulation, Python for computational science and engineering

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Python for Computational Science and Engineering

1 Introduction toPython for Computational Science and Engineering (A beginner s guide)Hans FangohrFaculty of Engineering and the EnvironmentUniversity of SouthamptonSeptember 7, 20152 Contents1 Computational Modelling .. Modelling .. to support Computational modelling .. Why Python for scientific computing? .. strategies .. it right first, then make it fast .. in Python .. Literature .. video lectures on Python for beginners .. tutor mailing list .. Python version .. This document .. Your feedback ..142 A powerful Python prompt and Read-Eval-Print Loop (REPL) .. Calculator .. Integer division .. to avoid integer division .. should I care about this division problem? .. Mathematical functions .. Variables .. Impossible equations .. +=notation ..233 Data Types and Data What type is it? .. Numbers.

2 Integers .. Point numbers .. numbers .. applicable to all types of numbers .. Sequences .. type 1: String .. type 2: List .. type 3: Tuples .. sequences .. sequences .. Passing arguments to functions .. by value .. by reference .. passing in Python .. considerations .. modification of data .. objects .. Equality and Identity/Sameness .. / Sameness .. : Equality and identity ..434 dir() .. names .. type .. isinstance .. help .. Docstrings ..495 Input and Printing to standard output (normally the screen) .. print (not compatible with Python ) .. printing .. str and str .. repr and repr .. from Python 2 to Python 3:print.. from Python 2 to Python 3: formatting of strings .. Reading and writing files .. reading examples ..566 Control Basics .. If-then-else.

3 For loop .. While loop .. Relational operators (comparisons) inifandwhilestatements .. Exceptions .. Exceptions .. our own exceptions .. vs EAFP ..657 Functions and Introduction .. Using functions .. Defining functions .. Default values and optional parameters .. Modules .. modules .. modules .. ofname.. 1 .. 2 ..748 Functional Anonymous functions .. Map .. Filter .. List comprehension .. Reduce .. Why not just use for-loops? .. Speed ..839 Common Many ways to compute a series .. Sorting ..8810 From Matlab to Important commands .. The for-loop .. The if-then statement .. Indexing .. Matrices ..9211 Python IDLE .. Python (command line) .. Interactive Python (IPython) .. IPython console .. IPython Notebook .. Spyder .. Editors.

4 9512 Symbolic SymPy .. Symbols .. isympy .. Numeric types .. Differentiation and Integration .. Ordinary differential equations .. Series expansions and plotting .. Linear equations and matrix inversion .. Non linear equations .. Output: LATEX interface and pretty-printing .. Automatic generation of C code .. Related tools .. 1096 CONTENTS13 Numerical Numbers and numbers .. Limitations of number types .. Using floating point numbers (carelessly) .. Using floating point numbers carefully 1 .. Using floating point numbers carefully 2 .. Symbolic calculation .. Summary .. Exercise: infinite or finite loop .. 11714 Numerical Python (numpy): Numpy introduction .. History .. Arrays .. Convert from array to list or tuple .. Standard Linear Algebra operations.

5 More numpy examples.. Numpy for Matlab users .. 12315 Visualising Matplotlib (Pylab) plotting y=f(x), (and a bit more) .. Matplotlib and Pylab .. First example .. How to import matplotlib, pylab, pyplot, numpy and all that .. IPython s inline mode .. Saving the figure to a file .. Interactive mode .. Fine tuning your plot .. Plotting more than one curve .. Histograms .. Visualising matrix data .. Plots ofz=f(x,y) and other features of Matplotlib .. Visual Python .. Basics, rotating and zooming .. Setting the frame rate for animations .. Tracking trajectories .. Connecting objects (Cylinders, springs, .. ) .. 3d vision .. Visualising higher dimensional data .. Mayavi, Paraview, Visit .. Writing vtk files from Python (pyvtk) .. 14416 Numerical Methods using Python (scipy) Overview.

6 SciPy .. Numerical integration .. Exercise: integrate a function .. Exercise: plot before you integrate .. Solving ordinary differential equations .. Exercise: usingodeint.. Root finding .. Root finding using the bisection method .. Exercise: root finding using the bisect method .. Root finding using thefsolvefuncion .. Interpolation .. Curve fitting .. Fourier transforms .. Optimisation .. numerical methods .. : Scipy-input output .. 16117 Where to go from here? Advanced programming .. Compiled programming language .. Testing .. simulation models .. Software Engineering for research codes .. Data and visualisation .. Version control .. Parallel execution .. 1668 CONTENTSC hapter 1 IntroductionThis text summarises a number of core ideas relevant to Computational Engineering and ScientificComputing using Python .

7 The emphasis is on introducing some basic Python ( programming ) conceptsthat are relevant for numerical algorithms. The later chapters touch upon numerical libraries suchasnumpyandscipyeach of which deserves much more space than provided here. We aim to enablethe reader to learn independently how to use other functionality of these libraries using the availabledocumentation (online and through the packages itself). , processes and systems are researched or developed through computer simulations: newaircraft prototypes such as for the recent A380 are first designed and tested virtually through computersimulations. With the ever increasing Computational power available through supercomputers, clustersof computers and even desktop and laptop machines, this trend is likely to simulations are routinely used in fundamental research to help understand experimentalmeasurements, and to replace for example growth and fabrication of expensive samples/experimentswhere possible.

8 In an industrial context, product and device design can often be done much morecost effectively if carried out virtually through simulation rather than through building and testingprototypes. This is in particular so in areas where samples are expensive such as nanoscience (where itis expensive to create small things) and aerospace industry (where it is expensive to build large things).There are also situations where certain experiments can only be carried out virtually (ranging fromastrophysics to study of effects of large scale nuclear or chemical accidents). Computational modelling,including use of Computational tools to post-process, analyse and visualise data, has been used inengineering, physics and chemistry for many decades but is becoming more important due to thecheap availability of Computational resources. Computational Modelling is also starting to play amore important role in studies of biological systems, the economy, archeology, medicine, health care,and many other ModellingTo study a process with a computer simulation we distinguish two steps: the first one is to develop amodelof the real system.

9 When studying the motion of a small object, such as a penny, say, under theinfluence of gravity, we may be able to ignore friction of air: our model which might only considerthe gravitational force and the penny s inertia, (t) =F/m= is an approximationof the real system. The model will normally allow us to express the behaviour of the system (in910 CHAPTER 1. INTRODUCTION some approximated form) through mathematical equations, which often involve ordinary differentialequations (ODEs) or partial differential equatons (PDEs).In the natural sciences such as physics, chemistry and related Engineering , it is often not so difficultto find a suitable model, although the resulting equations tend to be very difficult to solve, and canin most cases not be solved analytically at the other hand, in subjects that are not as well described through a mathematical frameworkand depend on behaviour of objects whose actions are impossible to predict deterministically (suchas humans), it is much more difficult to find a good model to describe reality.

10 As a rule of thumb,in these disciplines the resulting equations are easier to solve, but they are harder to find and thevalidity of a model needs to be questioned much more. Typical examples are attempts to simulate theeconomy, the use of global resources, the behaviour of a panicking crowd, far, we have just discussed the development ofmodelsto describe reality, and using these modelsdoes not necessarily involve any computers or numerical work at all. In fact, if a model s equation canbe solved analytically, then one should do this and write down the solution to the practice, hardly any model equations of systems of interest can be solved analytically, and thisis where the computer comes in: using numerical methods, we can at least study the modelfor aparticular set of boundary conditions. For the example considered above, we may not be able to easilysee from a numerical solution that the penny s velocity under the influence of gravity will changelinearly with time (which we can read easily from the analytical solution that is available for thissimple system:v(t) =t +v0).


Related search queries