Introduction to Python and Pylab
|
|
|
- Marjory Floyd
- 9 years ago
- Views:
Transcription
1 Introduction to Python and Pylab Jack Gallimore Bucknell University Department of Physics and Astronomy Table of Contents Using Python on Bucknell Windows Computers...1 Using Python on Bucknell Linux Computers...2 Writing Python Scripts...3 Interactive Python vs. Scripting...3 Interactive Python (ipython)...3 Scripts...3 Python Programming Basics...4 Variables...4 Functions...6 Loops...7 Conditional Operations...9 Structure of a Python Script...9 Variable Scope...10 Example: Trapezoid Integration...11 In-class exercises: The Factorial Function...11 File I/O...12 Numpy Shortcut for File Output...13 Euler Step Integration...13 Using Python on Bucknell Windows Computers Much of your work will be in an ipython terminal and a text editor such as Notepad++. To open ipython, use the start menu in the usual way and navigate to ipython2. Selecting it will start a new command terminal running the ipython environment. To load the pylab libraries (Numpy, Scipy, and Matplotlib in interactive plotting mode), type the following command in the ipython terminal. %pylab You'll also want to navigate to your directory on Netspace. cd 'U:\\Private\\Python301' Your directory might be different, of course. p. 1
2 Next, use the start menu to open your favorite text editor. Under Windows, I prefer Notepad++. However, if you want to use Notepad++, there's a little extra setup to get it to play well with Python scripts. In Notepad++, open the Settings menu. Under Settings, navigate to Preferences Tab Settings. Make sure 'Replace by Space' is checked. Using Python on Bucknell Linux Computers Much of your work will be in a linux terminal and a text editor such as emacs or gedit. To open a terminal, right click on the desktop and select Open a Terminal. This opens a Linux command window in your home directory. Welcome to the world of the command line. Learn this, and your employability increases an order of magnitude. Once in the command shell, you'll need to run a script to access the latest version of python. Use: source /usr/remote/python/setup.sh or source /usr/remote/python/setup.csh depending on your shell. If you get an error with one command, try the other. (Notice that I am using red for Linux/Unix commands.) Change your directory to where you want to work. The following example makes a subdirectory called Python301 and changes the working directory to that subdirectory. mkdir Python301 cd Python301 You don't have to call your directory Python301, of course, it's just an example. Start up a text editor in that directory; use one of emacs & gedit & The & symbol puts the program into the background so that you can still use the terminal. You'll need one of those editors to edit Python scripts in your working directory. If you downloaded any scripts from the Moodle page, they will likely be in your home directory. You'll need to copy them to your working directory. For example, cp ~/constants.py. will copy the file constants.py from your home directory (~) to the current directory (.). p. 2
3 To start ipython with pylab libraries loaded, use the following command. ipython --pylab Now you are in an interactive Python environment that behaves like the Linux command prompt but instead employs Python commands. You can enter Python commands interactively as we discussed in class, or you can run a script using the execfile function. For example, execfile('myscript.py') runs the script called myscript.py. (Notice that, in this document, Python commands use the same font as Linux/Unix commands, but are colored black.) If at any point you want to review a history of what you have done in ipython, use the %hist command as follows. %hist -n To get out of ipython, use ctrl-d. Writing Python Scripts Interactive Python vs. Scripting Interactive Python (ipython) Interactive Python is useful primarily to perform quick calculations. For example, you could import the constants.py module and perform numerical calculations using symbols for physical constants. Interactive Python is also useful for debugging scripts. If a script crashes, you will be returned to a Python command prompt and all global variables retain their values. You can print their values interactively to try and hunt down the problem. Scripts If you want to perform the same calculation many times, or a more detailed calculation requiring many steps, you are better off writing a script that you can edit and run at will. Such tasks require repetition, or loops, and a script more easily handles loops than an interactive session. A script is just a (unicode-based) text-file containing a list of python commands that are executed in sequence. Any command that you can execute in ipython can also be executed within a script. The main advantage of a script is that you have to type the commands only once, and then they can be repeated as often as you are willing to run the shorter command execfile. It is possible in Python to write an object-oriented script that permits asynchronous (non-sequential) operations, such as programming GUI interfaces. We won't work with objects and GUIs in ASTR/PHYS 301. There's nothing all that special about writing a script. If you put a list of python commands into a textp. 3
4 file, you can execute it using the execfile command. From within ipython, execfile('myscript.py') and the commands inside the file 'myscript.py' will be executed in sequence. There is no strict requirement for the name of a python script, but it is good form and will save headaches later on to give the script a.py extension. You can also execute a Python script from a system command prompt by using the python system command. python myscript.py The disadvantage of using this method, especially when you are developing a script, is that all of the variable data are lost if the script crashes, making it tougher to debug the script. The advantage of running scripts from within ipython is that the variable data are retained in the event of a crash. Python Programming Basics Variables In Python, variables are more commonly dynamically assigned. Formally, a variable is just a set of locations in computer memory that stores a value or a string of characters. That variable is a shorthand symbol assigned by the programmer, like the variables x and y from algebra. By dynamic assignment, I mean that you don't have to allocate memory for a variable at the beginning of the program. You can define a variable anywhere in your script, and Python will automatically allocate memory for it. Assignment Statements In all programming languages, the = symbol does not mean the same as in mathematics. The = symbol implies assignment: whatever lies on the RHS of the = is stored in the variable on the LHS. Assignment statements will sometimes read like nonsense if you try to interpret them mathematically. Examples: x = 3 This statement makes sense: we are defining a variable x and assigning the value 3 to it. x = x + 1 Mathematically, this statement is nonsense, because it implies that 1 = 0. In a programming language, the interpretation is different: first evaluate the RHS (x+1 = 4) and assign it to the variable on the LHS; the result is x = 4. p. 4
5 Python can also perform multiple assignments simultaneously. x, y = 3, 5 is the same as the two commands x = 3 y = 5 Floating-Point vs Integer Arithmetic Be careful when you assign variables and perform calculations. Try the following examples. x = 2 y = 3 print x / y x = 2.0 y = 3.0 print x / y If you want decimal (floating-point) division, you should enter your numbers with a decimal point. Otherwise, the calculations will be truncated or floored to an integer. Strings You can also assign strings to variables, such as mystring = 'This is my string.' print mystring Some special characters won't work inside a string without an escape. For example, if you want to put an apostrophe into a string, you have to escape it as follows, mystring = 'You haven\'t seen my string, have you?' The '\' symbol tells python to interpret the following character as something to be stored as a string rather than a Python character. (Here, if you didn't escape the apostrophe, it would have closed the string after 'n.') One use of strings is to format output statements, such as print 'The value of variable x = ', x p. 5
6 Lists and Arrays In Python, there are many ways to store sets of numbers in a variable; for now, we'll concern ourselves with lists and arrays. Lists are just lists of values stored in a single variable. For example, a = [0, 1, 2, 10, 25] or b = ['one', 'two', 'three', 'potato'] If you want to add new elements to a list, use + and another list. b = b + ['rutabaga', 'marshmallow'] print b The range function allows you to define a set of sequential integers. a = range(10) This command is equivalent to a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Notice that the argument is the length of the array, not the highest value. To access an individual element of an array, you have to use an index, which is the position of the element that you want. For example, a[0] accesses the first element of the array a, a[1] the second, and so on. Arrays are unique to numpy and offer the advantage of quick calculations. To define an array, you use the array function around a list variable. a = [0, 1, 2, 3] # list b = array(a) # array containing the same values Suppose I wanted to square each element of a and store the values in a new list, c. Since a is a list, I have to perform a loop (see below), and square each term in sequence. With array b, however, it's easy. c = b**2 print c With numpy arrays, calculations are automatically performed for each element in sequence without having to use a loop. p. 6
7 Functions In computer programming, function has a different meaning than in mathematics. A function is just a virtual machine that takes a variable or set of variables, performs some operations or calculations, and returns some new value or set of values. For example, here is a function that calculates the hypotenuse of a right triangle, given the sides a and b. def hypotenuse(a, b): r = sqrt(a*a + b*b) return r Notice how it's defined: the def statement tells python that a function statement is going to follow. Next is the name of the function, followed by a list of arguments that the function needs to perform the calculation. The colon, :, tells Python that the commands of the function follow. The commands within a function are indented indentations in Python indicate commands that belong to the function (or, as we'll see later, loops). As long as this function is defined in the script before the main program, we can then call it in the main program as follows. print hypotenuse(3., 5.) q = 2.0 w = 10.0 print hypotenuse(q, w) # notice that functions can take appropriate # variables as arguments Functions can of course be much more complicated, and an individual function can be longer than the main program that calls it. Loops Loops are programming structures that allow you to perform repeated calculations. For our purposes, we will concern ourselves with two kinds of loops; for loops and while loops. For Loops For loops iterate over a restricted, well-defined set of values. In Python, the method is to have some predefined list of values that you want to perform calculations or operations on. Go back to the list example, from above. a = [0,1,2,3] p. 7
8 Suppose you wanted to square each element and store the result in a new list c. Notice how commands within the loop are indented, just like in functions. c = [] # declare an empty list # this for-loop takes each element of a in turn # and stores it in the variable value for value in a: c = c + [value**2] # add the value squared to the list print c Hopefully now you can see the advantage to numpy arrays: with an array, you don't need to use a for loop for simple math operations. Sometimes you'll want to loop over the value of the index of an array, rather than the array value itself. For example, a and c are now two lists with the same length. If we want to print each element of each array side-by-side, we'll want to access each element by its index rather than its value. In this case, we use the len command to define a set of indices to iterate over. n = len(a) for j in range(n): print a[j], c[j] While Loops While loops are more useful when you are repeating operations over an set of values that are not predefined or may depend on calculations within the loop. I'll use Zeno's paradox for this example. In Zeno's paradox, you imagine a frog hopping toward a pond. The frog is subject to peculiar jumping arithmetic: for each hop, it can only hop half of the remaining distance to the pond. Suppose the pond is 10 meters away, and the frog itself is 0.05 meters long. Our while loop will consider how many hops it takes the frog before it is less than its length from the pond: at that point, we can consider that the frog has reached the pond. nhops = 0 # initialize our counters distance = 10.0 length = 0.05 while(distance > length): distance = distance / 2 # hop half the remaining distance nhops = nhops + 1 # update the hops counter print nhops, distance You should try this one yourself. I get eight hops before the frog is within its length of the pond. p. 8
9 Notice that the argument for a while loop is boolean: it is a logical statement that can be evaluated as true or false. Boolean statements are easy in python: the one catch is that if you want to establish equivalence, you have to use == instead of =. A while loop terminates when the argument is False. Boolean Statements Here are some Boolean (logical) statements. You should try typing them into an ipython session to verify that the results make sense. 1 == 2 1 == 1 1 > 2 1 < 2 1 <= 2 (1 <=2) and (2 <= 3) (1 <=2) and (2 > 3) (1 <=2) or (2 > 3) Conditional Operations Your program may have to make some choices as it runs. The if-statement sets rules for these choices. For example, suppose you want to square x if it is less than 1, but cube it if it is greater than 1. y = x**2 if x > 1: y = x**3 Alternatively, you could use the else-statement. if x>1: y = x**3 else: y = x**2 You can include even more conditional options using the elif-statement. Notice that an if-statement follows the same structure as a while loop, including a boolean argument, except that it is not executed repeatedly but conditionally. p. 9
10 Structure of a Python Script For the purposes of this course, all python scripts should follow a strict outline, namely, (1) module imports, (2) function definitions, and (3) the main program. The following script illustrates the outline. #!/usr/bin/env python import constants as c from pylab import * # other import statements # function definitions, for example def xsquared(x): y = x*x return y def xcubed(x): return x**3 def xtothethreehalves(x): return pow(x, 1.5) # the main program yarray = arange(5) for y in yarray: # for loop print y, xcubed(y), xtothethreehalves(y) if y > 3: print 'Hey, y is greater than 3!' print 'All done!' Variable Scope Variables and functions will have some scope within your script. Variables with global scope can be accessed anywhere in the program. Variables with local scope can only be accessed from within the function where they are defined. Some basic rules: (1) Any modules or variables that are imported are global. They can be used anywhere in the script that follows. That's why it is a good idea to have your import statements up front. (2) Any function definitions within a script are global: they can be accessed from anywhere in the main program that follows. That's why it is a good idea to have your function definitions before the main p. 10
11 program, to ensure you can use your functions. However, you want your imports before your functions, so you can use the imports in your functions. (3) Variables within a function are defined locally. For example, looking at the example script above, the function xsquared has the argument x, and an internal variable y. These variables are local to the function: they are assigned when you call the function, and they occupy accessible memory only for the brief time that the function is performing the calculation. Local variables in a function are called volatile, because they are lost once the function is done with the calculation. However, the return statement sends local variable values back to the main program, where they can be accessed. Example: Trapezoid Integration Trapezoid integration is a practical application of what we have covered so far. In trapezoid integration, we replace a function with a set of trapezoids and perform Euler step integration. The following code integrates the function x 2 from 0 to 1 using trapezoidal integration. We know in advance the answer should be 1/3. (If you want to integrate a different function, just alter the function myfunc). #!/usr/bin/env python import constants as c from pylab import * def myfunc(x): # function to be integrated return x**2 # define integration interval a = 0.0 b = 1.0 # define step-size dx = 0.1 # Note: the area of a trapezoid = 0.5 * base * sum of heights x0 = a integral = 0.0 # initialize integral while(x0 < b): x1 = x0 + dx y0 = myfunc(x0) if x1 > b: # don't go past the end of the interval x1 = b y1 = myfunc(x1) area = 0.5 * dx * (y0 + y1) integral = integral + area x0 = x0 + dx # slide trapezoid to the next position p. 11
12 print integral In-class exercises: The Factorial Function (1) Make a factorial function and test it in ipython. Difficulty: don't use the built-in factorial functions. (2) Modify the factorial function so that it returns the natural logarithm instead the built-in natural log function is log(). (3) Modify the factorial function so that, for arguments above n = 20, it uses Stirling's approximation to calculate the log factorial. Stirling's approximation ln n! 0.5 ln (2π n)+nln(n) n. File I/O In python calculations, you are likely to generate large tables that you would like to be able to store and inspect later. In other words, we need to save your calculations to a file. In the following discussion, I'll concentrate on data that are stored in columns. For example, if you are calculating the 1-D motion of an object, you would like to have columns for t and x. # t x Writing columnar data to a file involves three steps: (1) Opening the file. Essentially, we pick a name for the file, and assign it to a special variable called a file pointer, which I'll call pointer for short. (2) Printing data to the file, usually within a loop. (3) Closing the file. As data are printed to a file, they are temporarily stored in a reserved area of memory called the cache. By closing the file, we write the remaining data in the cache to the file on disk, and we also free up the file pointer variable for later use. For example, suppose we have data in the arrays t, x, y, and z. The following code snippet writes their data as neighboring columns in a text file. # step 1: assign the file pointer fp to 'data.txt', # open for 'w'riting fp = open('data.txt', 'w') for i in range(len(x)): # loop over all indices of the array p. 12
13 print >>fp, t[i], x[i], y[i], z[i] # step 2 fp.close() # step(3) Notice that we use the familiar command print. The symbol >> tells print to redirect the output to the file. With Numpy, reading those same data back into python is easy: use the loadtxt command. data = loadtxt('data.txt') # loadtxt automates input # data is now a matrix containing all of the columns. # Copy those columns to arrays t = data[:,0] # first columns x = data[:,1] # second column y = data[:,2] # third column z = data[:,3] # fourth column There are ways to read the data in one line at a time, which is useful for more complex data formats (data that includes a mix of strings and floating point numbers, for example). For our purposes, we are better off sticking with columnar data and reading them in using the loadtxt command. Numpy Shortcut for File Output Numpy's loadtxt command reads columnar data from a text file, and savetxt is a shortcut for saving data to a text file. There's a catch, however, if your data are in separate variables instead of a single array. We have to use the zip command to merge vectors into an array. Here's an example in which I define a set of vectors t, x, and y, and then I use savetxt + zip to save the data to a columnar text file in one line. t = arange(0,100) / 10. x = sqrt(t) y = t**2 savetxt('mydatafile.txt', zip(t, x, y)) Euler Step Integration Back in PHYS 211, you had to program an Excel spreadsheet to integrate the 1-D equations of motion for a falling object subject to air drag. The force law in this 1-D case is, F x =mg bv x 2, where we define downwards to be the positive x direction and b is the drag coefficient. To numerically integrate the force law and derive the resulting motion, we start with Newton's second law to get the acceleration, and then we carry out calculations over very small time-steps dt such that we can assume that the accelerations is roughly constant during that time step. In this limit, the equations of motion become, p. 13
14 a x (t) = F x (v x )/m, v x (t+ dt) = v x (t)+ a x (t)dt, x(t+ dt) = x(t)+ v x (t)dt, where the explicit functional dependence is denoted by parentheses; i.e., x(t+dt) indicates x at time t + dt, not x times t+dt. Note that these equations could be applied to any force law, and furthermore they can be extended to 2-D and 3-D force laws (i.e., force laws that include y and z components). The following Python script performs Euler step integration for the 1-D air drag problem. The data are stored in lists, written to a file, and plotted. This provides a nice summary of everything we've covered so far. #!/usr/bin/env python # imports from pylab import * # function definitions def forcelaw(v, m, b): g = 9.8 # m/s**2 F = m*g - b*v*v return F # main program # Describe the object b = # kg / m m = # 8 grams # initialize the Euler steps (boundary conditions) t = 0.0 dt = 0.1 # seconds. Could be smaller. x = 0.0 v = 0.0 # drop from rest a = forcelaw(v, m, b) / m # initial acceleration # define lists to store data p. 14
15 tlist = [t] xlist = [x] vlist = [v] alist = [a] # integrate until terminal velocity is reached # Define terminal velocity acceleration < 1.e-6 while(a >= 1.e-6): # Euler steps x = x + v * dt v = v + a * dt t = t + dt # Update (append) the lists tlist = tlist + [t] xlist = xlist + [x] vlist = vlist + [v] alist = alist + [a] # update the force law and acceleration to use for next step F = forcelaw(v, m, b) a = F / m # write the data to a file fp = open('eulerexperiment.txt', 'w') for i in range(len(tlist)): print >>fp, tlist[i], xlist[i], vlist[i], alist[i] fp.close() # plot the results # first, position plot clf() plot(tlist, xlist) xlabel('time (s)') p. 15
16 ylabel('position (m)') savefig('posplot.pdf') # velocity plot clf() plot(tlist, vlist) xlabel('time (s)') # use TeX formatting on the string ylabel('velocity (m s$^{-1}$)') savefig('velplot.pdf') # first, position plot clf() plot(tlist, alist) xlabel('time (s)') # use TeX formatting on the string ylabel('acceleration (m s$^{-2}$)') savefig('accplot.pdf') p. 16
Computational Mathematics with Python
Boolean Arrays Classes Computational Mathematics with Python Basics Olivier Verdier and Claus Führer 2009-03-24 Olivier Verdier and Claus Führer Computational Mathematics with Python 2009-03-24 1 / 40
Computational Mathematics with Python
Computational Mathematics with Python Basics Claus Führer, Jan Erik Solem, Olivier Verdier Spring 2010 Claus Führer, Jan Erik Solem, Olivier Verdier Computational Mathematics with Python Spring 2010 1
We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.
LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.
Introduction to Python
Introduction to Python Sophia Bethany Coban Problem Solving By Computer March 26, 2014 Introduction to Python Python is a general-purpose, high-level programming language. It offers readable codes, and
Computational Mathematics with Python
Numerical Analysis, Lund University, 2011 1 Computational Mathematics with Python Chapter 1: Basics Numerical Analysis, Lund University Claus Führer, Jan Erik Solem, Olivier Verdier, Tony Stillfjord Spring
Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
Scientific Programming in Python
UCSD March 9, 2009 What is Python? Python in a very high level (scripting) language which has gained widespread popularity in recent years. It is: What is Python? Python in a very high level (scripting)
Introduction to Python
Caltech/LEAD Summer 2012 Computer Science Lecture 2: July 10, 2012 Introduction to Python The Python shell Outline Python as a calculator Arithmetic expressions Operator precedence Variables and assignment
MATLAB Functions. function [Out_1,Out_2,,Out_N] = function_name(in_1,in_2,,in_m)
MATLAB Functions What is a MATLAB function? A MATLAB function is a MATLAB program that performs a sequence of operations specified in a text file (called an m-file because it must be saved with a file
Exercise 1: Python Language Basics
Exercise 1: Python Language Basics In this exercise we will cover the basic principles of the Python language. All languages have a standard set of functionality including the ability to comment code,
CP Lab 2: Writing programs for simple arithmetic problems
Computer Programming (CP) Lab 2, 2015/16 1 CP Lab 2: Writing programs for simple arithmetic problems Instructions The purpose of this Lab is to guide you through a series of simple programming problems,
Hypercosm. Studio. www.hypercosm.com
Hypercosm Studio www.hypercosm.com Hypercosm Studio Guide 3 Revision: November 2005 Copyright 2005 Hypercosm LLC All rights reserved. Hypercosm, OMAR, Hypercosm 3D Player, and Hypercosm Studio are trademarks
Invitation to Ezhil : A Tamil Programming Language for Early Computer-Science Education 07/10/13
Invitation to Ezhil: A Tamil Programming Language for Early Computer-Science Education Abstract: Muthiah Annamalai, Ph.D. Boston, USA. Ezhil is a Tamil programming language with support for imperative
Exercise 4 Learning Python language fundamentals
Exercise 4 Learning Python language fundamentals Work with numbers Python can be used as a powerful calculator. Practicing math calculations in Python will help you not only perform these tasks, but also
Computer Science for San Francisco Youth
Python for Beginners Python for Beginners Lesson 0. A Short Intro Lesson 1. My First Python Program Lesson 2. Input from user Lesson 3. Variables Lesson 4. If Statements How If Statements Work Structure
What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...
What is a Loop? CSC Intermediate Programming Looping A loop is a repetition control structure It causes a single statement or a group of statements to be executed repeatedly It uses a condition to control
Exercise 0. Although Python(x,y) comes already with a great variety of scientic Python packages, we might have to install additional dependencies:
Exercise 0 Deadline: None Computer Setup Windows Download Python(x,y) via http://code.google.com/p/pythonxy/wiki/downloads and install it. Make sure that before installation the installer does not complain
VB.NET Programming Fundamentals
Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements
Modeling with Python
H Modeling with Python In this appendix a brief description of the Python programming language will be given plus a brief introduction to the Antimony reaction network format and libroadrunner. Python
Python for Scientific Computing. http://bender.astro.sunysb.edu/classes/python-science
http://bender.astro.sunysb.edu/classes/python-science Course Goals Simply: to learn how to use python to do Numerical analysis Data analysis Plotting and visualizations Symbol mathematics Write applications...
Sources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
Windows PowerShell Essentials
Windows PowerShell Essentials Windows PowerShell Essentials Edition 1.0. This ebook is provided for personal use only. Unauthorized use, reproduction and/or distribution strictly prohibited. All rights
Introduction. Syntax Statements. Colon : Line Continuation _ Conditions. If Then Else End If 1. block form syntax 2. One-Line syntax. Do...
3 Syntax Introduction Syntax Statements Colon : Line Continuation _ Conditions If Then Else End If 1. block form syntax 2. One-Line syntax Select Case Case Case Else End Select Do...Loop For...Next While...Wend
Introduction to Matlab
Introduction to Matlab Social Science Research Lab American University, Washington, D.C. Web. www.american.edu/provost/ctrl/pclabs.cfm Tel. x3862 Email. [email protected] Course Objective This course provides
by Jonathan Kohl and Paul Rogers 40 BETTER SOFTWARE APRIL 2005 www.stickyminds.com
Test automation of Web applications can be done more effectively by accessing the plumbing within the user interface. Here is a detailed walk-through of Watir, a tool many are using to check the pipes.
Euler s Method and Functions
Chapter 3 Euler s Method and Functions The simplest method for approximately solving a differential equation is Euler s method. One starts with a particular initial value problem of the form dx dt = f(t,
Simulation Tools. Python for MATLAB Users I. Claus Führer. Automn 2009. Claus Führer Simulation Tools Automn 2009 1 / 65
Simulation Tools Python for MATLAB Users I Claus Führer Automn 2009 Claus Führer Simulation Tools Automn 2009 1 / 65 1 Preface 2 Python vs Other Languages 3 Examples and Demo 4 Python Basics Basic Operations
Q&As: Microsoft Excel 2013: Chapter 2
Q&As: Microsoft Excel 2013: Chapter 2 In Step 5, why did the date that was entered change from 4/5/10 to 4/5/2010? When Excel recognizes that you entered a date in mm/dd/yy format, it automatically formats
Lecture 2 Mathcad Basics
Operators Lecture 2 Mathcad Basics + Addition, - Subtraction, * Multiplication, / Division, ^ Power ( ) Specify evaluation order Order of Operations ( ) ^ highest level, first priority * / next priority
Code::Blocks Student Manual
Code::Blocks Student Manual Lawrence Goetz, Network Administrator Yedidyah Langsam, Professor and Theodore Raphan, Distinguished Professor Dept. of Computer and Information Science Brooklyn College of
Introduction. Chapter 1
Chapter 1 Introduction MATLAB (Matrix laboratory) is an interactive software system for numerical computations and graphics. As the name suggests, MATLAB is especially designed for matrix computations:
Excel 2007 Basic knowledge
Ribbon menu The Ribbon menu system with tabs for various Excel commands. This Ribbon system replaces the traditional menus used with Excel 2003. Above the Ribbon in the upper-left corner is the Microsoft
Python. KS3 Programming Workbook. Name. ICT Teacher Form. Do you speak Parseltongue?
Python KS3 Programming Workbook Do you speak Parseltongue? Name ICT Teacher Form Welcome to Python The python software has two windows that we will use. The main window is called the Python Shell and allows
AMATH 352 Lecture 3 MATLAB Tutorial Starting MATLAB Entering Variables
AMATH 352 Lecture 3 MATLAB Tutorial MATLAB (short for MATrix LABoratory) is a very useful piece of software for numerical analysis. It provides an environment for computation and the visualization. Learning
Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products
Chapter 3 Cartesian Products and Relations The material in this chapter is the first real encounter with abstraction. Relations are very general thing they are a special type of subset. After introducing
DATA 301 Introduction to Data Analytics Microsoft Excel VBA. Dr. Ramon Lawrence University of British Columbia Okanagan
DATA 301 Introduction to Data Analytics Microsoft Excel VBA Dr. Ramon Lawrence University of British Columbia Okanagan [email protected] DATA 301: Data Analytics (2) Why Microsoft Excel Visual Basic
CRASH COURSE PYTHON. Het begint met een idee
CRASH COURSE PYTHON nr. Het begint met een idee This talk Not a programming course For data analysts, who want to learn Python For optimizers, who are fed up with Matlab 2 Python Scripting language expensive
I PUC - Computer Science. Practical s Syllabus. Contents
I PUC - Computer Science Practical s Syllabus Contents Topics 1 Overview Of a Computer 1.1 Introduction 1.2 Functional Components of a computer (Working of each unit) 1.3 Evolution Of Computers 1.4 Generations
CS 1133, LAB 2: FUNCTIONS AND TESTING http://www.cs.cornell.edu/courses/cs1133/2015fa/labs/lab02.pdf
CS 1133, LAB 2: FUNCTIONS AND TESTING http://www.cs.cornell.edu/courses/cs1133/2015fa/labs/lab02.pdf First Name: Last Name: NetID: The purpose of this lab is to help you to better understand functions:
CSC 120: Computer Science for the Sciences (R section)
CSC 120: Computer Science for the Sciences (R section) Radford M. Neal, University of Toronto, 2015 http://www.cs.utoronto.ca/ radford/csc120/ Week 2 Typing Stuff into R Can be Good... You can learn a
MATLAB Programming. Problem 1: Sequential
Division of Engineering Fundamentals, Copyright 1999 by J.C. Malzahn Kampe 1 / 21 MATLAB Programming When we use the phrase computer solution, it should be understood that a computer will only follow directions;
Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2
Unix Shell Scripts Norman Matloff July 30, 2008 Contents 1 Introduction 1 2 Invoking Shell Scripts 2 2.1 Direct Interpretation....................................... 2 2.2 Indirect Interpretation......................................
PYTHON Basics http://hetland.org/writing/instant-hacking.html
CWCS Workshop May 2009 PYTHON Basics http://hetland.org/writing/instant-hacking.html Python is an easy to learn, modern, interpreted, object-oriented programming language. It was designed to be as simple
Databases in Microsoft Access David M. Marcovitz, Ph.D.
Databases in Microsoft Access David M. Marcovitz, Ph.D. Introduction Schools have been using integrated programs, such as Microsoft Works and Claris/AppleWorks, for many years to fulfill word processing,
Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.
1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays
Introduction to the UNIX Operating System and Open Windows Desktop Environment
Introduction to the UNIX Operating System and Open Windows Desktop Environment Welcome to the Unix world! And welcome to the Unity300. As you may have already noticed, there are three Sun Microsystems
Moving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
Introduction to Operating Systems
Introduction to Operating Systems It is important that you familiarize yourself with Windows and Linux in preparation for this course. The exercises in this book assume a basic knowledge of both of these
Basic Use of the TI-84 Plus
Basic Use of the TI-84 Plus Topics: Key Board Sections Key Functions Screen Contrast Numerical Calculations Order of Operations Built-In Templates MATH menu Scientific Notation The key VS the (-) Key Navigation
Installing Java. Table of contents
Table of contents 1 Jargon...3 2 Introduction...4 3 How to install the JDK...4 3.1 Microsoft Windows 95... 4 3.1.1 Installing the JDK... 4 3.1.2 Setting the Path Variable...5 3.2 Microsoft Windows 98...
Sequential Program Execution
Sequential Program Execution Quick Start Compile step once always g++ -o Realtor1 Realtor1.cpp mkdir labs cd labs Execute step mkdir 1 Realtor1 cd 1 cp../0/realtor.cpp Realtor1.cpp Submit step cp /samples/csc/155/labs/1/*.
Python Basics. S.R. Doty. August 27, 2008. 1 Preliminaries 4 1.1 What is Python?... 4 1.2 Installation and documentation... 4
Python Basics S.R. Doty August 27, 2008 Contents 1 Preliminaries 4 1.1 What is Python?..................................... 4 1.2 Installation and documentation............................. 4 2 Getting
Intro to scientific programming (with Python) Pietro Berkes, Brandeis University
Intro to scientific programming (with Python) Pietro Berkes, Brandeis University Next 4 lessons: Outline Scientific programming: best practices Classical learning (Hoepfield network) Probabilistic learning
Microsoft Excel Tips & Tricks
Microsoft Excel Tips & Tricks Collaborative Programs Research & Evaluation TABLE OF CONTENTS Introduction page 2 Useful Functions page 2 Getting Started with Formulas page 2 Nested Formulas page 3 Copying
PGR Computing Programming Skills
PGR Computing Programming Skills Dr. I. Hawke 2008 1 Introduction The purpose of computing is to do something faster, more efficiently and more reliably than you could as a human do it. One obvious point
Lab 1: Introduction to C, ASCII ART and the Linux Command Line Environment
.i.-' `-. i..' `/ \' _`.,-../ o o \.' ` ( / \ ) \\\ (_.'.'"`.`._) /// \\`._(..: :..)_.'// \`. \.:-:. /.'/ `-i-->..
VHDL Test Bench Tutorial
University of Pennsylvania Department of Electrical and Systems Engineering ESE171 - Digital Design Laboratory VHDL Test Bench Tutorial Purpose The goal of this tutorial is to demonstrate how to automate
Some programming experience in a high-level structured programming language is recommended.
Python Programming Course Description This course is an introduction to the Python programming language. Programming techniques covered by this course include modularity, abstraction, top-down design,
FX 115 MS Training guide. FX 115 MS Calculator. Applicable activities. Quick Reference Guide (inside the calculator cover)
Tools FX 115 MS Calculator Handouts Other materials Applicable activities Quick Reference Guide (inside the calculator cover) Key Points/ Overview Advanced scientific calculator Two line display VPAM to
VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0
VISUAL GUIDE to RX Scripting for Roulette Xtreme - System Designer 2.0 UX Software - 2009 TABLE OF CONTENTS INTRODUCTION... ii What is this book about?... iii How to use this book... iii Time to start...
Python programming guide for Earth Scientists. Maarten J. Waterloo and Vincent E.A. Post
Python programming guide for Earth Scientists Maarten J. Waterloo and Vincent E.A. Post Amsterdam Critical Zone Hydrology group September 2015 Cover page: Meteorological tower in an abandoned agricultural
Intro to Excel spreadsheets
Intro to Excel spreadsheets What are the objectives of this document? The objectives of document are: 1. Familiarize you with what a spreadsheet is, how it works, and what its capabilities are; 2. Using
Running your first Linux Program
Running your first Linux Program This document describes how edit, compile, link, and run your first linux program using: - Gnome a nice graphical user interface desktop that runs on top of X- Windows
The Center for Teaching, Learning, & Technology
The Center for Teaching, Learning, & Technology Instructional Technology Workshops Microsoft Excel 2010 Formulas and Charts Albert Robinson / Delwar Sayeed Faculty and Staff Development Programs Colston
PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?
1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members
Web Editing Tutorial. Copyright 1995-2010 Esri All rights reserved.
Copyright 1995-2010 Esri All rights reserved. Table of Contents Tutorial: Creating a Web editing application........................ 3 Copyright 1995-2010 Esri. All rights reserved. 2 Tutorial: Creating
Informatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
The Power Loader GUI
The Power Loader GUI (212) 405.1010 [email protected] Follow: @1010data www.1010data.com The Power Loader GUI Contents 2 Contents Pre-Load To-Do List... 3 Login to Power Loader... 4 Upload Data Files to
Programming in Access VBA
PART I Programming in Access VBA In this part, you will learn all about how Visual Basic for Applications (VBA) works for Access 2010. A number of new VBA features have been incorporated into the 2010
A Comparison of C, MATLAB, and Python as Teaching Languages in Engineering
A Comparison of C, MATLAB, and Python as Teaching Languages in Engineering Hans Fangohr University of Southampton, Southampton SO17 1BJ, UK [email protected] Abstract. We describe and compare the programming
0 Introduction to Data Analysis Using an Excel Spreadsheet
Experiment 0 Introduction to Data Analysis Using an Excel Spreadsheet I. Purpose The purpose of this introductory lab is to teach you a few basic things about how to use an EXCEL 2010 spreadsheet to do
Computer Programming In QBasic
Computer Programming In QBasic Name: Class ID. Computer# Introduction You've probably used computers to play games, and to write reports for school. It's a lot more fun to create your own games to play
NLP Programming Tutorial 0 - Programming Basics
NLP Programming Tutorial 0 - Programming Basics Graham Neubig Nara Institute of Science and Technology (NAIST) 1 About this Tutorial 14 parts, starting from easier topics Each time: During the tutorial:
Hands-on Exercise 1: VBA Coding Basics
Hands-on Exercise 1: VBA Coding Basics This exercise introduces the basics of coding in Access VBA. The concepts you will practise in this exercise are essential for successfully completing subsequent
Quick Tour of Mathcad and Examples
Fall 6 Quick Tour of Mathcad and Examples Mathcad provides a unique and powerful way to work with equations, numbers, tests and graphs. Features Arithmetic Functions Plot functions Define you own variables
Creating Basic Excel Formulas
Creating Basic Excel Formulas Formulas are equations that perform calculations on values in your worksheet. Depending on how you build a formula in Excel will determine if the answer to your formula automatically
IT Quick Reference Guides Using Windows 7
IT Quick Reference Guides Using Windows 7 Windows Guides This sheet covers many of the basic commands for using the Windows 7 operating system. WELCOME TO WINDOWS 7 After you log into your machine, the
How To Use Query Console
Query Console User Guide 1 MarkLogic 8 February, 2015 Last Revised: 8.0-1, February, 2015 Copyright 2015 MarkLogic Corporation. All rights reserved. Table of Contents Table of Contents Query Console User
EET 310 Programming Tools
Introduction EET 310 Programming Tools LabVIEW Part 1 (LabVIEW Environment) LabVIEW (short for Laboratory Virtual Instrumentation Engineering Workbench) is a graphical programming environment from National
Repetition Using the End of File Condition
Repetition Using the End of File Condition Quick Start Compile step once always g++ -o Scan4 Scan4.cpp mkdir labs cd labs Execute step mkdir 4 Scan4 cd 4 cp /samples/csc/155/labs/4/*. Submit step emacs
Getting Started with Excel 2008. Table of Contents
Table of Contents Elements of An Excel Document... 2 Resizing and Hiding Columns and Rows... 3 Using Panes to Create Spreadsheet Headers... 3 Using the AutoFill Command... 4 Using AutoFill for Sequences...
High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)
High-Level Programming Languages Nell Dale & John Lewis (adaptation by Michael Goldwasser) Low-Level Languages What are disadvantages of low-level languages? (e.g., machine code or assembly code) Programming
6.170 Tutorial 3 - Ruby Basics
6.170 Tutorial 3 - Ruby Basics Prerequisites 1. Have Ruby installed on your computer a. If you use Mac/Linux, Ruby should already be preinstalled on your machine. b. If you have a Windows Machine, you
Using the JNIOR with the GDC Digital Cinema Server. Last Updated November 30, 2012
Using the JNIOR with the GDC Digital Cinema Server Last Updated November 30, 2012 The following is an explanation of how to utilize the JNIOR with the GDC Digital Cinema Server. Please contact INTEG via
Simple File Input & Output
Simple File Input & Output Handout Eight Although we are looking at file I/O (Input/Output) rather late in this course, it is actually one of the most important features of any programming language. The
Visual Basic Programming. An Introduction
Visual Basic Programming An Introduction Why Visual Basic? Programming for the Windows User Interface is extremely complicated. Other Graphical User Interfaces (GUI) are no better. Visual Basic provides
An Introduction to Using Python with Microsoft Azure
An Introduction to Using Python with Microsoft Azure If you build technical and scientific applications, you're probably familiar with Python. What you might not know is that there are now tools available
Hands-On UNIX Exercise:
Hands-On UNIX Exercise: This exercise takes you around some of the features of the shell. Even if you don't need to use them all straight away, it's very useful to be aware of them and to know how to deal
Tutorial 3. Maintaining and Querying a Database
Tutorial 3 Maintaining and Querying a Database Microsoft Access 2010 Objectives Find, modify, and delete records in a table Learn how to use the Query window in Design view Create, run, and save queries
Microsoft Office 2010
Access Tutorial 3 Maintaining and Querying a Database Microsoft Office 2010 Objectives Find, modify, and delete records in a table Learn how to use the Query window in Design view Create, run, and save
DiskPulse DISK CHANGE MONITOR
DiskPulse DISK CHANGE MONITOR User Manual Version 7.9 Oct 2015 www.diskpulse.com [email protected] 1 1 DiskPulse Overview...3 2 DiskPulse Product Versions...5 3 Using Desktop Product Version...6 3.1 Product
Version Control with Subversion and Xcode
Version Control with Subversion and Xcode Author: Mark Szymczyk Last Update: June 21, 2006 This article shows you how to place your source code files under version control using Subversion and Xcode. By
Lab 2 : Basic File Server. Introduction
Lab 2 : Basic File Server Introduction In this lab, you will start your file system implementation by getting the following FUSE operations to work: CREATE/MKNOD, LOOKUP, and READDIR SETATTR, WRITE and
Beginner s Matlab Tutorial
Christopher Lum [email protected] Introduction Beginner s Matlab Tutorial This document is designed to act as a tutorial for an individual who has had no prior experience with Matlab. For any questions
A Crash Course on UNIX
A Crash Course on UNIX UNIX is an "operating system". Interface between user and data stored on computer. A Windows-style interface is not required. Many flavors of UNIX (and windows interfaces). Solaris,
The C Programming Language course syllabus associate level
TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming
Welcome to GAMS 1. Jesper Jensen TECA TRAINING ApS [email protected]. This version: September 2006
Welcome to GAMS 1 Jesper Jensen TECA TRAINING ApS [email protected] This version: September 2006 1 This material is the copyrighted intellectual property of Jesper Jensen. Written permission must
Solving Math Programs with LINGO
2 Solving Math Programs with LINGO 2.1 Introduction The process of solving a math program requires a large number of calculations and is, therefore, best performed by a computer program. The computer program
Lecture 4: Writing shell scripts
Handout 5 06/03/03 1 Your rst shell script Lecture 4: Writing shell scripts Shell scripts are nothing other than les that contain shell commands that are run when you type the le at the command line. That
Figure 1: Graphical example of a mergesort 1.
CSE 30321 Computer Architecture I Fall 2011 Lab 02: Procedure Calls in MIPS Assembly Programming and Performance Total Points: 100 points due to its complexity, this lab will weight more heavily in your
