Working Environment : Python #1

Size: px
Start display at page:

Download "Working Environment : Python #1"

Transcription

1 Working Environment : Python #1 Serdar ARITAN Biomechanics Research Group, Faculty of Sports Sciences, and Department of Computer Graphics Hacettepe University, Ankara, Turkey 1

2 Physics has several aspects: Physics as a science represents the quest to understand the basic laws of nature. Physics provides the tools to understand the processes occurring in nature on all time and length scales. Physics also provides the conceptual and theoretical background for developing new technologies. Mechanics is the part of physics that addresses the motion of objects. However, in order to predict motion, we need quantitative tools to describe motion. Our main tool is calculus and associated analytical and numerical methods. The study of motion is traditionally called kinematics, which is in many ways closer to mathematics than to physics. 2

3 3

4 The Mars Climate Orbiter was a 338 kilogram robotic space probe launched by NASA on December 11, 1998 to study the Martian climate, atmosphere, and surface changes and to act as the communications relay in the Mars Surveyor '98 program for Mars Polar Lander. However, on September 23, 1999, communication with the spacecraft was lost as the spacecraft went into orbital insertion, due to ground-based computer software which produced output in non-si units of pound-seconds instead of the metric units of newton-seconds specified in the contract between NASA and Lockheed. 4

5 5

6 TIOBE has been collecting data on programming language popularity for many years 6

7 7

8 8

9 Distinct Features of Python Extensible (packages) Embeddable into applications Functional programming Object-Oriented programming Rapid Prototyping Great for readability and presentation White space is significant Low maintenance costs Exception handling Free (open source) 9

10 The core philosophy of the language is summarized by the document "PEP 20 (The Zen of Python)", Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Readability counts. Try; >>>import this 10

11 11

12 12

13 There are no units in your program, so you need to keep track of the units yourself. If you calculate the velocity of a car driving 20.0 m in 1.0 s, you find: >>> x = 20.0 >>> t = 1.0 >>> v = x/t >>> v 20 It is your job to know that the units for the answer is m/s. In your script, you could write: x = 20.0 # m t = 1.0 # s This does not solve the problem, but this is a habit that makes it easier for you to spot the units. 13

14 Your program tends to return a long sequence of numbers irrespective of the number of digits you put in: It does not care about significant numbers as do we: >>> x = 10.0; >>> t = 3.0; >>> x/t It is therefore always your job not to report the numbers you get out directly, but to apply the rules of the number of significant digits before you report the calculated value. 14

15 Digital Representation of Numbers The numbers you use in your program can be of various types and are stored digitally in various ways. Numbers in computers are stored in units of 4 or 8 bytes, which is the size most efficiently handled by the hardware. One byte corresponds to an 8-bit binary number. One bit is a binary number, which means that it is either 0 or 1. With 8 bits we can make 2 8 different numbers. For example, we could enumerate the numbers from 0 to 255 = You may use binary as a data type in your programs, but you will usually use either integers, called integers, or real numbers, called floating point numbers. 15

16 Your program tends to return a long sequence of numbers irrespective of the number of digits you put in: It does not care about significant numbers as do we: >>> x = 10.0; >>> t = 3.0; >>> x/t It is therefore always your job not to report the numbers you get out directly, but to apply the rules of the number of significant digits before you report the calculated value. 16

17 Integers Integers are usually either represented by 4 or 8 bytes of computer memory. This means that there is a maximum number that can be represented. If you use a 4-byte integer the integers can range from 2 31 = to = However, in Python your programming language will sort out problems if you exceed this number by automatically switching to a data type such as a 8 byte integer. 17

18 Floating-Point Numbers While floating-point numbers are supposed to represent real numbers, they also have a finite digital precision, corresponding to the number of possible values that can be spanned by the 4 or 8 bytes used to represent the floating-point number. Floating point numbers are represented by the (significant) digits, and an exponent, using the method that we called scientific notation. For a 4-byte floating-point number, the IEEE4 standard determines that 23 bits are used for the digits and 9 bits are used for the exponents - including the signs for both. 4-byte floating point numbers therefore have 6-9 (significant) digits, and cover a range from to for negative numbers, and from to for positive numbers. 18

19 Floating-Point Numbers However, you will not encounter 4-byte numbers when programming in Python since by default the floating-point numbers are 8-byte. In this case, numbers have (significant) digits, and cover a range from to for negative numbers, and from to for positive numbers. With 8-byte floating-point numbers you will seldom encounter cases where you are limited by the numerical precision. 19

20 Floating-Point Numbers >>> import sys >>> sys.float_info sys.float_info(max= e+308, max_exp=1024, max_10_exp=308, min= e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon= e- 16, radix=2, rounds=1) >>> sys.int_info sys.int_info(bits_per_digit=30, sizeof_digit=4) >>> # Guess what is the answer? >>> # it must be ZERO!! 20

21 Functions A user defined function acts just like a predefined mathematical function such as sin or exp. def convertf(tc): # Converts from centigrade to Fahrenheit TF = 9.0/5.0*TC return TF We call our new function by typing: >> convertf(45.0) Notice that Python requires each such used-defined function to either be in the same file as the script using the function, of the function must be in a separate file, and that the file must be in the search path for Python. 21

22 Plotting Data-Sets Python not only works as a numerical calculator, it also has advanced data visualization capabilities from pylab import * m = array([1.0,2.0,4.0,6.0,9.0,11.0]) V = array([0.13,0.26,0.50,0.77,1.15,1.36]) plot(m, V, o ) xlabel( m (kg) ) ylabel( V (l) ) 22

23 Plotting a Function using SymPy SymPy is a Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible and easily extensible. SymPy is written entirely in Python and does not require any external libraries. from sympy import symbols from sympy.plotting import plot x = symbols('x') p1 = plot(x*x) p2 = plot(x) 23

24 Plotting a Function We must first generate a sequences of numbers that sequence for the x es and one sequence for the corresponding values of (x) and (x 2 ), and then plot the two sequences. from pylab import * x0, x1, dx = -10.0, 10.0, 0.1 n = int(ceil((x1-x0)/dx) + 1) x = zeros((n,1),float) for i in range(n): x[i] = x0 + i*dx plot(x, x, '-'), show() plot(x, x*x, '-'), show() 24

25 Vectorization We can make a sequence of x es in several ways using functions that are built into Python instead of using a loop. For example, the function linspace generates a sequence of equidistant numbers from 0.0 to 10.0:. >>> x = linspace(0,10,10) >>> print(x) [ ] In this case we generated 10 numbers, but you are free to choose your own resolution. 25

26 Vectorization An alternative to specifying the number of points you want, as we do with linspace, is to specify the step size. The expression ([0.0:10.0:0.3]) returns an array starting at the value 0 and ending at 10.0 in steps of 0.3. >>> x = arange(0.0, 10.0, 0.3) >>> x array([ 0., 0.3, 0.6, 0.9, 1.2, 1.5, 1.8, 2.1, 2.4, 2.7, 3., 3.3, 3.6, 3.9, 4.2, 4.5, 4.8, 5.1, 5.4, 5.7, 6., 6.3, 6.6, 6.9, 7.2, 7.5, 7.8, 8.1, 8.4, 8.7, 9., 9.3, 9.6, 9.9]) 26

27 Random Numbers Sometimes you need randomness to enter your physical simulation. For example, you may want to model the motion of a tiny dust of grain in the air bouncing about due to random hits by the air molecules, so called Brownian motion. Unfortunately, we cannot generate really random numbers, but most programs have decent pseudo-random number generators, which generate a sequence of numbers that appear to be random. In Python we can simulate the throw of a dice using >>> randint(6) where randint(n) generates a random integer between 0 and n 1. 27

28 Conditions if we return to discuss the motion of the grain of dust, we want to model its motion according to a simple rule: I throw a dice. If I get between 1 and 3, the grain moves a step forward, otherwise it moves a step backward. Every time we throw the dice, the grain moves a distance dx = ±1. If the grain is at position x i at step i, the grain will be at a position x i + 1 = x i + dx at step i + 1. from pylab import * n = 1000 x = zeros(n, float) for i in range(n - 1): if (randint(6)+1<=3): dx = -1 else: dx = 1 x[i+1] = x[i] + dx 28

29 Conditions plot(x), xlabel( i ), ylabel( x(i) ) show() 29

30 Conditions Pythonic formulation of the random walk, which you may have fun trying to understand. from pylab import * x = cumsum(2*(randint(1,7,1000)<=3)-1) plot(x), show() You can research help about cumsum by pressing CTRL+I in Ipython console. 30

31 Reading Real Data When you work with physics you need to handle real data. Fortunately, it is very simple to read such as file into Python. It is done by a single command: >>> runner = loadtxt("run100m.txt") We split the data into two arrays t and x by: >>> t = runner[:,0] >>> x = runner[:,1] 31

32 Summary Direct calculations are done on the command line >>> 10.0*sin(pi/3)+4.0**3 Defining and reusing variables >>> a = 2.0, b = 4.5, c = a**2 + b**2 Vectorized plotting of functions >>> x=linspace(0,10,0.01), y=exp(-x)*sin(x),plot(x,y),show() A function can be part of a script of stored in a separate.py file. It has the syntax def myfunction(a,b,c): v = a*b*c d = v**2 y = 2.0*d return y 32

33 Summary Plotting You plot two arrays t and x versus each other by plot(t,x, -b ), xlabel( t (s) ), ylabel( x (m) ) Plotting several data-sets in the same plot: plot(t1,x1, -b,t2,x2, -r ) 33

34 Summary Loops for-loops run a counter sequentially through a list of values: for i in range(100): x[i] = sin(i/100.0) while-loops run until a given expression is true i = 0 while (i<100): i = i + 1 x[i] = sin(i/100.0) 34

35 Seconds Exercises (a)write a script that calculates the number of seconds, s, given the number of hours, h, according to the formula s = 3600 h. (b) Use the script to find the number of seconds in 1.5, 12 and 24 h. Spherical mass (a) Write a script that calculates the mass of a sphere given its radius r and mass density ρ according to the formula m = (4π/3) ρr 3. (b) Use the script to find the mass of a sphere of steel of radius r = 1mm, r = 1m, and r = 10 m. 35

Introduction to mechanics

Introduction to mechanics Anders Malthe-Sørenssen Introduction to mechanics Integrating numerical and analytical methods c AMS 2013 Preface This compium is inted as a support for teaching in preparatory course in computer programming

More information

SBT 645 Introduction to Scientific Computing in Sports Science

SBT 645 Introduction to Scientific Computing in Sports Science SBT 645 Introduction to Scientific Computing in Sports Science SERDAR ARITAN serdar.aritan@hacettepe.edu.tr Biyomekanik Araştırma Grubu www.biomech.hacettepe.edu.tr Spor Bilimleri Fakültesi www.sbt.hacettepe.edu.tr

More information

ERTH2020 Introduction to Geophysics

ERTH2020 Introduction to Geophysics ERTH2020 Practical:: Introduction to Python Page 1 ERTH2020 Introduction to Geophysics 2018 Practical 1: Introduction to scientific programming using Python, and revision of basic mathematics Purposes

More information

Improving System Integration with the FACE TM Technical Standard and Dexter

Improving System Integration with the FACE TM Technical Standard and Dexter Improving System Integration with the FACE TM Technical Standard and Dexter US Army Aviation FACE TIM Paper by: SimVentions, Inc. Tram Chase Mason Vines Traci McDonald November, 2015 SimVentions acknowledges

More information

SBT 645 Introduction to Scientific Computing in Sports Science #3

SBT 645 Introduction to Scientific Computing in Sports Science #3 SBT 645 Introduction to Scientific Computing in Sports Science #3 SERDAR ARITAN serdar.aritan@hacettepe.edu.tr Biyomekanik Araştırma Grubu www.biomech.hacettepe.edu.tr Spor Bilimleri Fakültesi www.sbt.hacettepe.edu.tr

More information

EE 301 Signals & Systems I MATLAB Tutorial with Questions

EE 301 Signals & Systems I MATLAB Tutorial with Questions EE 301 Signals & Systems I MATLAB Tutorial with Questions Under the content of the course EE-301, this semester, some MATLAB questions will be assigned in addition to the usual theoretical questions. This

More information

Computational Programming with Python

Computational Programming with Python Numerical Analysis, Lund University, 2017 1 Computational Programming with Python Lecture 1: First steps - A bit of everything. Numerical Analysis, Lund University Lecturer: Claus Führer, Alexandros Sopasakis

More information

Workpackage 5 - Ordinary Differential Equations

Workpackage 5 - Ordinary Differential Equations Mathematics for I Workpackage 5 - Ordinary Differential Equations Introduction During this laboratory you will be introduced to some of Matlab s facilities for solving ordinary differential equations (ode).

More information

CITS2401 Computer Analysis & Visualisation

CITS2401 Computer Analysis & Visualisation FACULTY OF ENGINEERING, COMPUTING AND MATHEMATICS CITS2401 Computer Analysis & Visualisation SCHOOL OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING Topic 3 Introduction to Matlab Material from MATLAB for

More information

Introductory Scientific Computing with Python

Introductory Scientific Computing with Python Introductory Scientific Computing with Python Introduction, IPython and Plotting FOSSEE Department of Aerospace Engineering IIT Bombay SciPy India, 2015 December, 2015 FOSSEE group (IIT Bombay) Interactive

More information

ERTH3021 Exploration and Mining Geophysics

ERTH3021 Exploration and Mining Geophysics ERTH3021 Exploration and Mining Geophysics Practical 1: Introduction to Scientific Programming using Python Purposes To introduce simple programming skills using the popular Python language. To provide

More information

CSC 221: Introduction to Programming. Fall 2013

CSC 221: Introduction to Programming. Fall 2013 CSC 221: Introduction to Programming Fall 2013 Python data, assignments & turtles Scratch programming review Python & IDLE numbers & expressions variables & assignments strings & concatenation input &

More information

Introduction to Scientific Computing Lecture 1

Introduction to Scientific Computing Lecture 1 Introduction to Scientific Computing Lecture 1 Professor Hanno Rein Last updated: September 10, 2017 1 Number Representations In this lecture, we will cover two concept that are important to understand

More information

Basics of Computation. PHY 604:Computational Methods in Physics and Astrophysics II

Basics of Computation. PHY 604:Computational Methods in Physics and Astrophysics II Basics of Computation Basics of Computation Computers store information and allow us to operate on it. That's basically it. Computers have finite memory, so it is not possible to store the infinite range

More information

Introduction to computers and Python. Matthieu Choplin

Introduction to computers and Python. Matthieu Choplin Introduction to computers and Python Matthieu Choplin matthieu.choplin@city.ac.uk http://moodle.city.ac.uk/ 1 Objectives To get a brief overview of what Python is To understand computer basics and programs

More information

CPS 101 Introduction to Computational Science

CPS 101 Introduction to Computational Science CPS 101 Introduction to Computational Science Wensheng Shen Department of Computational Science SUNY Brockport Chapter 6 Modeling Process Definition Model classification Steps of modeling 6.1 Definition

More information

SD314 Outils pour le Big Data

SD314 Outils pour le Big Data Institut Supérieur de l Aéronautique et de l Espace SD314 Outils pour le Big Data Functional programming in Python Christophe Garion DISC ISAE Christophe Garion SD314 Outils pour le Big Data 1/ 35 License

More information

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis Introduction to Matlab 1 Outline What is Matlab? Matlab desktop & interface Scalar variables Vectors and matrices Exercise 1 Booleans Control structures File organization User defined functions Exercise

More information

Lecture Objectives. Structured Programming & an Introduction to Error. Review the basic good habits of programming

Lecture Objectives. Structured Programming & an Introduction to Error. Review the basic good habits of programming Structured Programming & an Introduction to Error Lecture Objectives Review the basic good habits of programming To understand basic concepts of error and error estimation as it applies to Numerical Methods

More information

Turtle Graphics Conditional Statements, Loops 3#

Turtle Graphics Conditional Statements, Loops 3# Turtle Graphics Conditional Statements, Loops 3# Serdar ARITAN Biomechanics Research Group, Faculty of Sports Sciences, and Department of Computer Graphics Hacettepe University, Ankara, Turkey 1 Turtle

More information

Introduction to Computer Programming with MATLAB Calculation and Programming Errors. Selis Önel, PhD

Introduction to Computer Programming with MATLAB Calculation and Programming Errors. Selis Önel, PhD Introduction to Computer Programming with MATLAB Calculation and Programming Errors Selis Önel, PhD Today you will learn Numbers, Significant figures Error analysis Absolute error Relative error Chopping

More information

Lecture Notes: Floating-Point Numbers

Lecture Notes: Floating-Point Numbers Lecture Notes: Floating-Point Numbers CS227-Scientific Computing September 8, 2010 What this Lecture is About How computers represent numbers How this affects the accuracy of computation Positional Number

More information

Introduction to numerical algorithms

Introduction to numerical algorithms Introduction to numerical algorithms Given an algebraic equation or formula, we may want to approximate the value, and while in calculus, we deal with equations or formulas that are well defined at each

More information

Outline. Numerical Analysis Basics. Some Higher-Level Languages. Programming Languages. BASIC and VBA MATLAB

Outline. Numerical Analysis Basics. Some Higher-Level Languages. Programming Languages. BASIC and VBA MATLAB umerical Analysis Basics Larry Caretto Mechanical Engineering 39 umerical Analysis of Engineering Systems February 5, 214 Outline Programming Languages Binary umbers and Data Types Limits on the size and

More information

Activity A 1-D Free-Fall with v i = 0

Activity A 1-D Free-Fall with v i = 0 Physics 151 Practical 3 Python Programming Freefall Kinematics Department of Physics 60 St. George St. NOTE: Today's activities must be done in teams of one or two. There are now twice as many computers

More information

Binary floating point encodings

Binary floating point encodings Week 1: Wednesday, Jan 25 Binary floating point encodings Binary floating point arithmetic is essentially scientific notation. Where in decimal scientific notation we write in floating point, we write

More information

Interactive MATLAB use. Often, many steps are needed. Automated data processing is common in Earth science! only good if problem is simple

Interactive MATLAB use. Often, many steps are needed. Automated data processing is common in Earth science! only good if problem is simple Chapter 2 Interactive MATLAB use only good if problem is simple Often, many steps are needed We also want to be able to automate repeated tasks Automated data processing is common in Earth science! Automated

More information

PART 1 PROGRAMMING WITH MATHLAB

PART 1 PROGRAMMING WITH MATHLAB PART 1 PROGRAMMING WITH MATHLAB Presenter: Dr. Zalilah Sharer 2018 School of Chemical and Energy Engineering Universiti Teknologi Malaysia 23 September 2018 Programming with MATHLAB MATLAB Environment

More information

ENGR Fall Exam 1 PRACTICE EXAM

ENGR Fall Exam 1 PRACTICE EXAM ENGR 13100 Fall 2012 Exam 1 PRACTICE EXAM INSTRUCTIONS: Duration: 60 minutes Keep your eyes on your own work! Keep your work covered at all times! 1. Each student is responsible for following directions.

More information

Floating Point Arithmetic

Floating Point Arithmetic Floating Point Arithmetic CS 365 Floating-Point What can be represented in N bits? Unsigned 0 to 2 N 2s Complement -2 N-1 to 2 N-1-1 But, what about? very large numbers? 9,349,398,989,787,762,244,859,087,678

More information

Introduction to Python: The Multi-Purpose Programming Language. Robert M. Porsch June 14, 2017

Introduction to Python: The Multi-Purpose Programming Language. Robert M. Porsch June 14, 2017 Introduction to Python: The Multi-Purpose Programming Language Robert M. Porsch June 14, 2017 What is Python Python is Python is a widely used high-level programming language for general-purpose programming

More information

Chapter 3. Errors and numerical stability

Chapter 3. Errors and numerical stability Chapter 3 Errors and numerical stability 1 Representation of numbers Binary system : micro-transistor in state off 0 on 1 Smallest amount of stored data bit Object in memory chain of 1 and 0 10011000110101001111010010100010

More information

Symbols. Anscombe s quartet, antiderivative, 200. bar charts for exercise, for expenses, Barnsley fern, drawing,

Symbols. Anscombe s quartet, antiderivative, 200. bar charts for exercise, for expenses, Barnsley fern, drawing, Index Symbols + (addition operator), 2 {} (curly brackets), to define a set, 122 δ (delta), 184 / (division operator), 2 ε (epsilon), 192, 197 199 == (equality operator), 124 e (Euler s number), 179 **

More information

Basics of Computational Geometry

Basics of Computational Geometry Basics of Computational Geometry Nadeem Mohsin October 12, 2013 1 Contents This handout covers the basic concepts of computational geometry. Rather than exhaustively covering all the algorithms, it deals

More information

Introduction to programming with Python

Introduction to programming with Python Introduction to programming with Python Ing. Lelio Campanile 1/61 Main Goal - Introduce you to programming - introduce you to the most essential feature of python programming 2/61 Before to start The name

More information

FLOATING POINT NUMBERS

FLOATING POINT NUMBERS FLOATING POINT NUMBERS Robert P. Webber, Longwood University We have seen how decimal fractions can be converted to binary. For instance, we can write 6.25 10 as 4 + 2 + ¼ = 2 2 + 2 1 + 2-2 = 1*2 2 + 1*2

More information

Representing numbers on the computer. Computer memory/processors consist of items that exist in one of two possible states (binary states).

Representing numbers on the computer. Computer memory/processors consist of items that exist in one of two possible states (binary states). Representing numbers on the computer. Computer memory/processors consist of items that exist in one of two possible states (binary states). These states are usually labeled 0 and 1. Each item in memory

More information

Numerical Precision. Or, why my numbers aren t numbering right. 1 of 15

Numerical Precision. Or, why my numbers aren t numbering right. 1 of 15 Numerical Precision Or, why my numbers aren t numbering right 1 of 15 What s the deal? Maybe you ve seen this #include int main() { float val = 3.6f; printf( %.20f \n, val); Print a float with

More information

The Sign consists of a single bit. If this bit is '1', then the number is negative. If this bit is '0', then the number is positive.

The Sign consists of a single bit. If this bit is '1', then the number is negative. If this bit is '0', then the number is positive. IEEE 754 Standard - Overview Frozen Content Modified by on 13-Sep-2017 Before discussing the actual WB_FPU - Wishbone Floating Point Unit peripheral in detail, it is worth spending some time to look at

More information

Programming in the Real World. Dr. Baldassano Yu s Elite Education

Programming in the Real World. Dr. Baldassano Yu s Elite Education Programming in the Real World Dr. Baldassano chrisb@princeton.edu Yu s Elite Education Our programs are getting bigger! Our game was already over 100 lines long - most programs are worked on by teams of

More information

MS6021 Scientific Computing. TOPICS: Python BASICS, INTRO to PYTHON for Scientific Computing

MS6021 Scientific Computing. TOPICS: Python BASICS, INTRO to PYTHON for Scientific Computing MS6021 Scientific Computing TOPICS: Python BASICS, INTRO to PYTHON for Scientific Computing Preliminary Notes on Python (v MatLab + other languages) When you enter Spyder (available on installing Anaconda),

More information

AMS 27L LAB #2 Winter 2009

AMS 27L LAB #2 Winter 2009 AMS 27L LAB #2 Winter 2009 Plots and Matrix Algebra in MATLAB Objectives: 1. To practice basic display methods 2. To learn how to program loops 3. To learn how to write m-files 1 Vectors Matlab handles

More information

Lecture 6: Specifications & Testing

Lecture 6: Specifications & Testing http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 6: Specifications & Testing (Sections 4.9, 9.5) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner,

More information

BIOMECHANICAL MODELLING

BIOMECHANICAL MODELLING BIOMECHANICAL MODELLING SERDAR ARITAN serdar.aritan@hacettepe.edu.tr Biomechanics Research Group www.biomech.hacettepe.edu.tr School of Sport Science&Technology www.sbt.hacettepe.edu.tr Hacettepe University,

More information

LECTURE 0: Introduction and Background

LECTURE 0: Introduction and Background 1 LECTURE 0: Introduction and Background September 10, 2012 1 Computational science The role of computational science has become increasingly significant during the last few decades. It has become the

More information

Chapter Three. Arithmetic

Chapter Three. Arithmetic Chapter Three 1 Arithmetic Where we've been: Performance (seconds, cycles, instructions) Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's up ahead: Implementing

More information

1 Introduction to Matlab

1 Introduction to Matlab 1 Introduction to Matlab 1. What is Matlab? Matlab is a computer program designed to do mathematics. You might think of it as a super-calculator. That is, once Matlab has been started, you can enter computations,

More information

Introduction to Computer Programming for Non-Majors

Introduction to Computer Programming for Non-Majors Introduction to Computer Programming for Non-Majors CSC 2301, Fall 2014 Chapter 3 The Department of Computer Science Review of Chapter 2 Stages of creating a program: Analyze the problem Determine specifications

More information

Introduction to Scientific Computing with Python, part two.

Introduction to Scientific Computing with Python, part two. Introduction to Scientific Computing with Python, part two. M. Emmett Department of Mathematics University of North Carolina at Chapel Hill June 20 2012 The Zen of Python zen of python... fire up python

More information

Reals 1. Floating-point numbers and their properties. Pitfalls of numeric computation. Horner's method. Bisection. Newton's method.

Reals 1. Floating-point numbers and their properties. Pitfalls of numeric computation. Horner's method. Bisection. Newton's method. Reals 1 13 Reals Floating-point numbers and their properties. Pitfalls of numeric computation. Horner's method. Bisection. Newton's method. 13.1 Floating-point numbers Real numbers, those declared to be

More information

Object Oriented Programming #10

Object Oriented Programming #10 Object Oriented Programming #10 Serdar ARITAN Biomechanics Research Group, Faculty of Sports Sciences, and Department of Computer Graphics Hacettepe University, Ankara, Turkey 1 Simple programming tasks

More information

ENGR 102 Engineering Lab I - Computation

ENGR 102 Engineering Lab I - Computation ENGR 102 Engineering Lab I - Computation Week 03: Data Types and Console Input / Output Introduction to Types As we have already seen, 1 computers store numbers in a binary sequence of bits. The organization

More information

CS321. Introduction to Numerical Methods

CS321. Introduction to Numerical Methods CS31 Introduction to Numerical Methods Lecture 1 Number Representations and Errors Professor Jun Zhang Department of Computer Science University of Kentucky Lexington, KY 40506 0633 August 5, 017 Number

More information

Program Planning, Data Comparisons, Strings

Program Planning, Data Comparisons, Strings Program Planning, Data Comparisons, Strings Program Planning Data Comparisons Strings Reading for this class: Dawson, Chapter 3 (p. 80 to end) and 4 Program Planning When you write your first programs,

More information

Signed umbers. Sign/Magnitude otation

Signed umbers. Sign/Magnitude otation Signed umbers So far we have discussed unsigned number representations. In particular, we have looked at the binary number system and shorthand methods in representing binary codes. With m binary digits,

More information

Process model formulation and solution, 3E4 Computer software tutorial - Tutorial 3

Process model formulation and solution, 3E4 Computer software tutorial - Tutorial 3 Process model formulation and solution, 3E4 Computer software tutorial - Tutorial 3 Kevin Dunn, dunnkg@mcmaster.ca October 2 Tutorial solutions: Elliot Cameron. Tutorial objectives Understand computer

More information

Reminders. Lecture Outline. Lecture Agenda. Lecture Outline. Remember This? COMP10001 Foundations of Computing Testing and Debugging

Reminders. Lecture Outline. Lecture Agenda. Lecture Outline. Remember This? COMP10001 Foundations of Computing Testing and Debugging COMP10001 Foundations of Computing Testing and Debugging Reminders Semester 1, 2017 Tim Baldwin & Egemen Tanin version: 1103, date: March 30, 2017 Grok Worksheets 8 11 due at the end of this week Advanced/revision

More information

COMP10001 Foundations of Computing Testing and Debugging

COMP10001 Foundations of Computing Testing and Debugging COMP10001 Foundations of Computing Testing and Debugging Semester 1, 2017 Tim Baldwin & Egemen Tanin version: 1103, date: March 30, 2017 2017 The University of Melbourne Reminders Grok Worksheets 8 11

More information

Math 340 Fall 2014, Victor Matveev. Binary system, round-off errors, loss of significance, and double precision accuracy.

Math 340 Fall 2014, Victor Matveev. Binary system, round-off errors, loss of significance, and double precision accuracy. Math 340 Fall 2014, Victor Matveev Binary system, round-off errors, loss of significance, and double precision accuracy. 1. Bits and the binary number system A bit is one digit in a binary representation

More information

MATH 353 Engineering mathematics III

MATH 353 Engineering mathematics III MATH 353 Engineering mathematics III Instructor: Francisco-Javier Pancho Sayas Spring 2014 University of Delaware Instructor: Francisco-Javier Pancho Sayas MATH 353 1 / 20 MEET YOUR COMPUTER Instructor:

More information

Computational Physics

Computational Physics Computational Physics Python Programming Basics Prof. Paul Eugenio Department of Physics Florida State University Jan 17, 2019 http://hadron.physics.fsu.edu/~eugenio/comphy/ Announcements Exercise 0 due

More information

2 Computation with Floating-Point Numbers

2 Computation with Floating-Point Numbers 2 Computation with Floating-Point Numbers 2.1 Floating-Point Representation The notion of real numbers in mathematics is convenient for hand computations and formula manipulations. However, real numbers

More information

6.S189 Homework 2. What to turn in. Exercise 3.1 Defining A Function. Exercise 3.2 Math Module.

6.S189 Homework 2. What to turn in. Exercise 3.1 Defining A Function. Exercise 3.2 Math Module. 6.S189 Homework 2 http://web.mit.edu/6.s189/www/materials.html What to turn in Checkoffs 3, 4 and 5 are due by 5 PM on Monday, January 15th. Checkoff 3 is over Exercises 3.1-3.2, Checkoff 4 is over Exercises

More information

Partial Derivatives (Online)

Partial Derivatives (Online) 7in x 10in Felder c04_online.tex V3 - January 21, 2015 9:44 A.M. Page 1 CHAPTER 4 Partial Derivatives (Online) 4.7 Tangent Plane Approximations and Power Series It is often helpful to use a linear approximation

More information

Python - a Dynamic Programming Language. Guido van Rossum May 31, 2007

Python - a Dynamic Programming Language. Guido van Rossum May 31, 2007 Python - a Dynamic Programming Language Guido van Rossum May 31, 2007 Outline What is Python? Origins, history and design philosophy Python today The future: Python 3000 Links, Q&A 3 Copyright 2007 Google

More information

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types Introduction to Computer Programming in Python Dr William C Bulko Data Types 2017 What is a data type? A data type is the kind of value represented by a constant or stored by a variable So far, you have

More information

(Ca...

(Ca... 1 of 8 9/7/18, 1:59 PM Getting started with 228 computational exercises Many physics problems lend themselves to solution methods that are best implemented (or essentially can only be implemented) with

More information

10.4 Linear interpolation method Newton s method

10.4 Linear interpolation method Newton s method 10.4 Linear interpolation method The next best thing one can do is the linear interpolation method, also known as the double false position method. This method works similarly to the bisection method by

More information

CS450 - Structure of Higher Level Languages

CS450 - Structure of Higher Level Languages Spring 2018 Streams February 24, 2018 Introduction Streams are abstract sequences. They are potentially infinite we will see that their most interesting and powerful uses come in handling infinite sequences.

More information

Floating-point representation

Floating-point representation Lecture 3-4: Floating-point representation and arithmetic Floating-point representation The notion of real numbers in mathematics is convenient for hand computations and formula manipulations. However,

More information

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms:

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms: Appendix A Basic MATLAB Tutorial Extracted from: http://www1.gantep.edu.tr/ bingul/ep375 http://www.mathworks.com/products/matlab A.1 Introduction This is a basic tutorial for the MATLAB program which

More information

OOP and Scripting in Python

OOP and Scripting in Python DIEE - Università degli Studi di Cagliari OOP and Scripting in Python Introduction Giuliano Armano DIEE Univ. di Cagliari Python Roots... Object Oriented Programming (C++, Modula-3, ABC, Icon) Scripting

More information

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices Introduction to Interactive Calculations Matlab is interactive, no need to declare variables >> 2+3*4/2 >> V = 50 >> V + 2 >> V Ans = 52 >> a=5e-3; b=1; a+b Most elementary functions and constants are

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab The purpose of this intro is to show some of Matlab s basic capabilities. Nir Gavish, 2.07 Contents Getting help Matlab development enviroment Variable definitions Mathematical operations

More information

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures Introduction to Octave/Matlab Deployment of Telecommunication Infrastructures 1 What is Octave? Software for numerical computations and graphics Particularly designed for matrix computations Solving equations,

More information

Floating-point numbers. Phys 420/580 Lecture 6

Floating-point numbers. Phys 420/580 Lecture 6 Floating-point numbers Phys 420/580 Lecture 6 Random walk CA Activate a single cell at site i = 0 For all subsequent times steps, let the active site wander to i := i ± 1 with equal probability Random

More information

MAT 275 Laboratory 1 Introduction to MATLAB

MAT 275 Laboratory 1 Introduction to MATLAB MATLAB sessions: Laboratory 1 1 MAT 275 Laboratory 1 Introduction to MATLAB MATLAB is a computer software commonly used in both education and industry to solve a wide range of problems. This Laboratory

More information

User-Defined Function

User-Defined Function ENGR 102-213 (Socolofsky) Week 11 Python scripts In the lecture this week, we are continuing to learn powerful things that can be done with userdefined functions. In several of the examples, we consider

More information

What Every Programmer Should Know About Floating-Point Arithmetic

What Every Programmer Should Know About Floating-Point Arithmetic What Every Programmer Should Know About Floating-Point Arithmetic Last updated: October 15, 2015 Contents 1 Why don t my numbers add up? 3 2 Basic Answers 3 2.1 Why don t my numbers, like 0.1 + 0.2 add

More information

Set Theory in Computer Science. Binary Numbers. Base 10 Number. What is a Number? = Binary Number Example

Set Theory in Computer Science. Binary Numbers. Base 10 Number. What is a Number? = Binary Number Example Set Theory in Computer Science Binary Numbers Part 1B Bit of This and a Bit of That What is a Number? Base 10 Number We use the Hindu-Arabic Number System positional grouping system each position is a

More information

Numerical Methods in Engineering Sciences

Numerical Methods in Engineering Sciences Numerical Methods in Engineering Sciences Lecture 1: Brief introduction to MATLAB Pablo Antolin pablo.antolinsanchez@unipv.it October 29th 2013 How many of you have used MATLAB before? How many of you

More information

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor. https://xkcd.com/217/

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor. https://xkcd.com/217/ CS 261 Fall 2017 Mike Lam, Professor https://xkcd.com/217/ Floating-Point Numbers Floating-point Topics Binary fractions Floating-point representation Conversions and rounding error Binary fractions Now

More information

List of Exercises: Data Mining 1 December 12th, 2015

List of Exercises: Data Mining 1 December 12th, 2015 List of Exercises: Data Mining 1 December 12th, 2015 1. We trained a model on a two-class balanced dataset using five-fold cross validation. One person calculated the performance of the classifier by measuring

More information

Physics 251 Laboratory Introduction to Spreadsheets

Physics 251 Laboratory Introduction to Spreadsheets Physics 251 Laboratory Introduction to Spreadsheets Pre-Lab: Please do the lab-prep exercises on the web. Introduction Spreadsheets have a wide variety of uses in both the business and academic worlds.

More information

Review Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts

Review Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts Review Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts Simple Data Types There are a number of data types that are considered primitive in that they contain only a single value. These data

More information

A Brief Introduction to Matlab for Econometrics Simulations. Greg Fischer MIT February 2006

A Brief Introduction to Matlab for Econometrics Simulations. Greg Fischer MIT February 2006 A Brief Introduction to Matlab for Econometrics Simulations Greg Fischer MIT February 2006 Introduction First, Don t Panic! As the problem set assured you, the point of the programming exercises is to

More information

Computer Systems C S Cynthia Lee

Computer Systems C S Cynthia Lee Computer Systems C S 1 0 7 Cynthia Lee 2 Today s Topics LECTURE: Floating point! Real Numbers and Approximation MATH TIME! Some preliminary observations on approximation We know that some non-integer numbers

More information

CS321 Introduction To Numerical Methods

CS321 Introduction To Numerical Methods CS3 Introduction To Numerical Methods Fuhua (Frank) Cheng Department of Computer Science University of Kentucky Lexington KY 456-46 - - Table of Contents Errors and Number Representations 3 Error Types

More information

Writing MATLAB Programs

Writing MATLAB Programs Outlines September 14, 2004 Outlines Part I: Review of Previous Lecture Part II: Review of Previous Lecture Outlines Part I: Review of Previous Lecture Part II: Control Structures If/Then/Else For Loops

More information

Mining di Dati Web. Lezione 3 - Clustering and Classification

Mining di Dati Web. Lezione 3 - Clustering and Classification Mining di Dati Web Lezione 3 - Clustering and Classification Introduction Clustering and classification are both learning techniques They learn functions describing data Clustering is also known as Unsupervised

More information

Introductory Scientific Computing with Python

Introductory Scientific Computing with Python Introductory Scientific Computing with Python More plotting, lists and FOSSEE Department of Aerospace Engineering IIT Bombay SciPy India, 2015 December, 2015 FOSSEE (FOSSEE IITB) Interactive Plotting 1

More information

A Brief Introduction to MATLAB

A Brief Introduction to MATLAB A Brief Introduction to MATLAB MATLAB (Matrix Laboratory) is an interactive software system for numerical computations and graphics. As the name suggests, MATLAB was first designed for matrix computations:

More information

Molecular Statistics Exercise 1. As was shown to you this morning, the interactive python shell can add, subtract, multiply and divide numbers.

Molecular Statistics Exercise 1. As was shown to you this morning, the interactive python shell can add, subtract, multiply and divide numbers. Molecular Statistics Exercise 1 Introduction This is the first exercise in the course Molecular Statistics. The exercises in this course are split in two parts. The first part of each exercise is a general

More information

Ray Trace Notes. Charles Rino. September 2010

Ray Trace Notes. Charles Rino. September 2010 Ray Trace Notes Charles Rino September 2010 1 Introduction A MATLAB function that performs a direct numerical integration to the ray optics equation described in book Section 1.3.2 has been implemented.

More information

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor.

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor. CS 261 Fall 2018 Mike Lam, Professor https://xkcd.com/217/ Floating-Point Numbers Floating-point Topics Binary fractions Floating-point representation Conversions and rounding error Binary fractions Now

More information

Functions and Transformations

Functions and Transformations Using Parametric Representations to Make Connections Richard Parr T 3 Regional, Stephenville, Texas November 7, 009 Rice University School Mathematics Project rparr@rice.edu If you look up parametric equations

More information

Proceedings of the Third International DERIVE/TI-92 Conference

Proceedings of the Third International DERIVE/TI-92 Conference Using the TI-92 and TI-92 Plus to Explore Derivatives, Riemann Sums, and Differential Equations with Symbolic Manipulation, Interactive Geometry, Scripts, Regression, and Slope Fields Sally Thomas, Orange

More information

Sample: Do Not Reproduce QUAD4 STUDENT PAGES. QUADRATIC FUNCTIONS AND EQUATIONS Student Pages for Packet 4: Quadratic Functions and Applications

Sample: Do Not Reproduce QUAD4 STUDENT PAGES. QUADRATIC FUNCTIONS AND EQUATIONS Student Pages for Packet 4: Quadratic Functions and Applications Name Period Date QUADRATIC FUNCTIONS AND EQUATIONS Student Pages for Packet 4: Quadratic Functions and Applications QUAD 4.1 Vertex Form of a Quadratic Function 1 Explore how changing the values of h and

More information

Math 250A (Fall 2009) - Lab I: Estimate Integrals Numerically with Matlab. Due Date: Monday, September 21, INSTRUCTIONS

Math 250A (Fall 2009) - Lab I: Estimate Integrals Numerically with Matlab. Due Date: Monday, September 21, INSTRUCTIONS Math 250A (Fall 2009) - Lab I: Estimate Integrals Numerically with Matlab Due Date: Monday, September 21, 2009 4:30 PM 1. INSTRUCTIONS The primary purpose of this lab is to understand how go about numerically

More information

New Mexico Tech Hyd 510

New Mexico Tech Hyd 510 Numerics Motivation Modeling process (JLW) To construct a model we assemble and synthesize data and other information to formulate a conceptual model of the situation. The model is conditioned on the science

More information