Statistical Data Analysis: Python Tutorial

Size: px
Start display at page:

Download "Statistical Data Analysis: Python Tutorial"

Transcription

1 1 October 4, 2017 Statistical Data Analysis: Python Tutorial Dr A. J. Bevan, Contents 1 Getting started 1 2 Basic calculations 2 3 More advanced calculations 4 4 Data sets CSV file input Plotting data 7 1 Getting started Python is an open source statistical programming language which can be downloaded from the following website: This scripting language is useful for this course, and some sectors value familiarity with Python. You may wish to use these tutorials to introduce yourself to this package to bolster your CV. In these notes type in bold is entered into a command line terminal, and italicised text appears on the command line as a result. We will use Anaconda that is a bundle that comes with python as well as a GUI called Spyder. The latter provides you with the opportunity to write scripts in an integrated environment without needing to know how to use a separate editor. Anaconda can be downloaded from The student services Windows 10 machines at QMUL have anaconda installed, however given the nature of the setup you will need to copy a shortcut to the anaconda install that will be used. The following directory on the J drive J:\Physics\Teaching\spa6328 contains this shortcut (LaunchSpyder-anaconda3) as well as the python example scripts prepared for the module. You should copy the content of this directory to your area (e.g. Desktop) in order to start working with the files. a.j.bevan at qmul.ac.uk

2 2 The shortcut itself is setup to run the following command 1. %windir%\system32\cmd.exe /K L:\Anaconda3\python3.5\Scripts\activate.bat && spyder The first part (up to and including /K ) starts a command terminal, the second part (up to activate.bat) sets the anaconda environment, including the python path, and the last part launches Spyder. 2. The shortcut should start on your desktop. This is specified as G:\Desktop In order to start Python from a LINIX/UNIX or Mac OSX computer that has python or anaconda installed correctly just open a Darwin (Mac) or command line terminal and type the following at the command prompt python This should result in the following output being displayed on the command line terminal Python Anaconda (x86 64) (default, May , 13:04:09) [GCC Compatible Apple LLVM 6.0 (clang )] on darwin Type help, copyright, credits or license for more information. >>> As noted above, the use of the python command line tool is limited and you will soon want to write python scripts, where we resort to Spyder. First open the anaconda-navigator (type this at the terminal prompt and press return). Once the navigator has opened you should see Spyder and a button that when clicked will launch this GUI. In order to quit an interactive Python session one simply enters quit() or Ctrl-D at the prompt (>>>). More information on the use of Python can be found online at the Python website and as the result of performing a google search for Python. In addition to this there are a number of books available on the use of this language. 2 Basic calculations You can perform simple arithmetic in Python in a logical way using operators akin to any other programming language. For example 3* / It is convenient to abstract quantities and refer to them via names. Different data types exist, and above we see integers being used. Python dynamically determines the type of a variable based on the usage of that variable (unlike most other languages). For example to create a variable called x and assign a number to it we can enter x = 3 At some later time we can re-assign a value to that variable, and we can refer to the variable as x without having to worry about what the actual value is assigned to this. Integer division will be evaluated at the command prompt as the division of two real numbers, but in a script will be taken as the division of two integers. This can lead to an incorrect computation, so be careful to ensure that you have the correct calculation being performed.

3 3 There is a command line help function that enables you to find out more about a particular built-in Python command. This will not work for classes that are in modules (see below for modules). For example if you wish to query the help for the built in type list simply enter help(list) at the Python prompt. This will result in the following output. Help on class list in module builtins: class list(object) list() -> new empty list list(iterable) -> new list initialized from iterable s items Methods defined here: add (self, value, /) Return self+value.... The real power of a language is the higher level functionality provided by libraries. Basic mathematical operations are built in types in Python. For more advanced computation (for example trig functions) we need to import the math library. This is done by typing import math The functions provided by this library can be seen by first importing the library and then help(math) The following functions are available in the math library : acos inverse cosine acosh inverse hyperbolic cosine asin inverse sine asinh inverse hyperbolic sine atan/atan2 inverse tangent atanh inverse hyperbolic ceil round up argument to nearest integer cos cosine cosh hyperbolic cosine degrees convert from radians to degrees erf error function erfc complementary error function exp exponential expm1 exponential minus 1 (use for precision when computing exp(x)-1) fabs absolute value of a float factorial factorial floor round down to the nearest integer gamma gamma function isnan return TRUE if x is not a number, otherwise FALSE log natural logarithm log10 log base 10 pow raise x to some power radians convert degrees to radians sin sine sinh hyperbolic sine sqrt square root tan tangent tanh hyperbolic tangent Note that trig functions are computed in radians. Not all functions in math are listed here.

4 4 Note that function names in Python are followed by arguments in parentheses. So for some number x, one can compute the square root of x as sqrt(x) and so on. In addition to this one can define arrays of numbers and perform simple calculations on these sets of data. The following example creates an ordered list of data in an array with variable name x, and computes the arithmetic mean, variance and standard deviation for these data. AnArray = [1, 2, 3, 4] print(anarray) [1, 2, 3, 4] numpy.mean(anarray) 2.5 numpy.var(anarray) numpy.std(anarray, ddof=1) NumPy has many other functions, including average ceil cov floor median prod sum Compute the weighted average Round up to the nearest integer Estimate the covariance matrix Round down to the nearest integer Determine the median Return the product Compute the sum The user guide for this package can be found at Exercises 1. Define the variables θ = 3.2 and φ = 1.7 and print out these variables. 2. Compute θ + φ. 3. Compute θ φ. 4. Compute θφ. 5. Compute θ/φ. 6. Define an array x containing the prime numbers between 1 and Print out the array x. 8. Compute the arithmetic mean, variance and standard deviation of x. 3 More advanced calculations It is possible to perform more advanced calculations using additional functionality in Python, for example via numpy or the math libraries. However sometimes we need to define higher level functionality in a script

5 5 that is not already implemented. For this we need to utilise more advanced control features such as loop statements and functions. Loops: allow us to iterate over variables like arrays. For example the numpy function mean for some array can be coded up in python as a loop in the following way AnArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] sum = 0 for i in AnArray: sum += AnArray[i-1] sum = sum/len(anarray) Note that python determines how many elements are in the array, and when indexing the array, the number of elements starts being counted at zero (0) and runs to N-1. This convention is the same as other popular languages (e.g. C, C++, Java), but differs from older languages such as FORTRAN (still used for some scientific programming). The first line defines the data array to be analysed; the second provides an initilised counter variable; the third is a loop over elements in the variable AnArray; within this loop there is an indentation (this is how Python deals with scope); the last line is normalising the sum over elements to compute the average. In terms of pseudo-code we can express this calculation as: 1. Define the data 2. Sum over the data 3. Divide the data by the number of elements Each time you have to perform a complicated operation, such as the arithmetic average calculation above, it would be unproductive to have to re-write the code. We can turn this code snippet into a re-usable element by using the concept of a function. Let s call this function average, and we can define the function average as def average(a): sum = 0 for i in a: sum += a[i-1] sum = sum/len(a) return sum Now when we call this function av = average(anarray) av will be assigned the value corresponding to the average. This will be 5.5 using the data provided above. Exercises 1. Using the data set Ω = {1, 1.2, 1.5, 1.7, 2.3} compute the arithmetic mean without resorting to the built in function. 2. Using the data set Ω = {1, 1.2, 1.5, 1.7, 2.3} compute the standard deviation without resorting to the built in function. 3. Using the data set Ω = {1, 1.2, 1.5, 1.7, 2.3} compute the skew without resorting to the built in function. 4 Data sets There are several data sets that are available via SciKitLearn. To access these data sets you will need that package installed, then you can load datasets from sklearn into your session via from sklearn import datasets

6 6 The sda 2.py example script will use the Iris data from the Fisher publication, where the aim of that paper was to classify the different types of Iris using features of the data. The paper itself will be a reading homework later in the module. The Iris data includes four features: Sepal length (cm) Sepal width (cm) Petal length (cm) Petal width (cm) These are extracted from the dataset as X using the commands below iris = datasets.load iris() X = iris.data[:, :4] Y = iris.target Y is the target variable (the type of iris: either setosa, versicolor or verginica). It is possible to divide the ensemble of data up into the individual types of iris using Xsetosa = X[Y==0] Ysetosa = Y[Y==0] Xversicolor = X[Y==1] Yversicolor = Y[Y==1] Xvirginica = X[Y==2] Yvirginica = Y[Y==2] This helps with plotting the features for one particular type of the data. SciKit Learn has several other example data sets that are described at CSV file input Often we are interested in analysing data collated in a CSV file format (e.g. from an Excel spread sheet or a flat file). Some HEP data (for example the data format provided for the Kaggle Higgs data challenge) is represented as a CSV file with real valued and string valued data elements. As a result there is an example CSV file reader that addresses the issues with extracting data into columns that are numerical and columns that are string data. If only one type of data exist then the arrays for the other type is returned null. The file CSV IO.py includes a function ReadCSV that takes one or two arguments; the first argument being the CSV filename and the second being either quiet or verbose (controls the level of information printed out when reading the file). The following shows an example of how to use this functionality import CSV IO.py dat, col, strdat, strcol = CSV IO.ReadCSV( test data.csv ) Here dat and strdat are the numerical and string data, respectively. The corresponding column names are stored in col and strcol. The example data file test data.csv only has numerical data with 6 entries and three columns (x, y and z). Exercises

7 7 1. Inspect (printout) the Fisher data set to understand how the arrays are related and to make sure you are comfortable with selecting sub-sets of an array by cutting on values. 2. Extract one of the other data types (e.g. Boston house prices) and try to understand the format by comparing with the Fisher data. 5 Plotting data matplotlib is used in sda 2.py to illustrate plotting in python. There are histogram and scatter plot examples, where the Fisher data described above are used to make plots. The starting point is to import the matplotlib.pyploy functionality using import matplotlib.pyplot as plt Having split the Fisher data up into different types of iris, we can choose to plot the first feature of the iris data set for type setosa using the following fig hist = plt.figure() ax = fig hist.add subplot(1, 1, 1) ax.hist(xsetosa[:, 0], 10, label= setosa ) plt.title( Iris Setosa ) ax.set xlabel( Sepal length (cm) ) ax.set ylabel( Number of entries ) plt.show() This will produce a plot like the one shown in Figure 1. Figure 1: The sepal length data for iris setosa from the Fisher data sample. Sometimes we want to visually inspect the change in one variable as a function of another. An example of this is shown in Figure 2, where the iris sepal length is plotted against the sepal width for the three iris types. The corresponding python to create this plot is

8 8 plt.figure(2, figsize=(8, 6)) plt.scatter(xsetosa[:, 0], Xsetosa[:, 1], c= b, cmap=plt.cm.set1, edgecolor= k, label= setosa ) plt.scatter(xversicolor[:, 0], Xversicolor[:, 1], c= r, cmap=plt.cm.set1, edgecolor= k, label= versicolor ) plt.scatter(xvirginica[:, 0], Xvirginica[:, 1], c= g, cmap=plt.cm.set1, edgecolor= k, label= verginica ) # The plot needs to have axis labels and the legend should be appropriately placed plt.legend(loc= upper left ) plt.xlabel( Sepal length (cm) ) plt.ylabel( Sepal width (cm) ) # set appropriate plot ranges to avoid having a crowded image x min, x max = X[:, 0].min() -.5, X[:, 0].max() +.5 y min, y max = X[:, 1].min() -.5, X[:, 1].max() +.5 plt.xlim(x min, x max) plt.ylim(y min, y max) plt.show() Figure 2: The sepal length and width data for different iris types found in the Fisher data sample. Exercises Adapt the sda 2.py script to do the following 1. Create a histogram of the petal length for each type of iris using the Fisher data; Add axis labels to the plot you ve created. 2. Save the plot to a file (click on the disc icon to open the save dialogue window). 3. Create a scatter plot of the petal length vs petal width for each type of iris using the Fisher data. As before include axis labels, and now also include a legend. More information (including extensive source of documentation) can be found on the following web pages: Python: Anaconda: NumPy: Matplotlib:

Built-in Types of Data

Built-in Types of Data Built-in Types of Data Types A data type is set of values and a set of operations defined on those values Python supports several built-in data types: int (for integers), float (for floating-point numbers),

More information

Statistical Data Analysis: R Tutorial

Statistical Data Analysis: R Tutorial 1 August 29, 2012 Statistical Data Analysis: R Tutorial Dr A. J. Bevan, Contents 1 Getting started 1 2 Basic calculations 2 3 More advanced calulations 3 4 Plotting data 4 5 The quantmod package 5 1 Getting

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

LAB 1 General MATLAB Information 1

LAB 1 General MATLAB Information 1 LAB 1 General MATLAB Information 1 General: To enter a matrix: > type the entries between square brackets, [...] > enter it by rows with elements separated by a space or comma > rows are terminated by

More information

Introduction to GNU-Octave

Introduction to GNU-Octave Introduction to GNU-Octave Dr. K.R. Chowdhary, Professor & Campus Director, JIETCOE JIET College of Engineering Email: kr.chowdhary@jietjodhpur.ac.in Web-Page: http://www.krchowdhary.com July 11, 2016

More information

Programming for Engineers in Python. Recitation 2

Programming for Engineers in Python. Recitation 2 Programming for Engineers in Python Recitation 2 Plan Range For loop While loop Lists Modules Operations Arithmetic Operations: + plus - minus * multiply / divide (int / float) % modulo (remainder) **

More information

Starting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below.

Starting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below. What is MATLAB? MATLAB (short for MATrix LABoratory) is a language for technical computing, developed by The Mathworks, Inc. (A matrix is a rectangular array or table of usually numerical values.) MATLAB

More information

A Guide to Using Some Basic MATLAB Functions

A Guide to Using Some Basic MATLAB Functions A Guide to Using Some Basic MATLAB Functions UNC Charlotte Robert W. Cox This document provides a brief overview of some of the essential MATLAB functionality. More thorough descriptions are available

More information

Introduction to Python Practical 1

Introduction to Python Practical 1 Introduction to Python Practical 1 Daniel Carrera & Brian Thorsbro October 2017 1 Introduction I believe that the best way to learn programming is hands on, and I tried to design this practical that way.

More information

Introduction to MATLAB

Introduction to MATLAB Outlines September 9, 2004 Outlines Part I: Review of Previous Lecture Part II: Part III: Writing MATLAB Functions Review of Previous Lecture Outlines Part I: Review of Previous Lecture Part II: Part III:

More information

ARTIFICIAL INTELLIGENCE AND PYTHON

ARTIFICIAL INTELLIGENCE AND PYTHON ARTIFICIAL INTELLIGENCE AND PYTHON DAY 1 STANLEY LIANG, LASSONDE SCHOOL OF ENGINEERING, YORK UNIVERSITY WHAT IS PYTHON An interpreted high-level programming language for general-purpose programming. Python

More information

Arithmetic and Logic Blocks

Arithmetic and Logic Blocks Arithmetic and Logic Blocks The Addition Block The block performs addition and subtractions on its inputs. This block can add or subtract scalar, vector, or matrix inputs. We can specify the operation

More information

Introduction to Scientific and Engineering Computing, BIL108E. Karaman

Introduction to Scientific and Engineering Computing, BIL108E. Karaman USING MATLAB INTRODUCTION TO SCIENTIFIC & ENGINEERING COMPUTING BIL 108E, CRN24023 To start from Windows, Double click the Matlab icon. To start from UNIX, Dr. S. Gökhan type matlab at the shell prompt.

More information

MATLAB INTRODUCTION. Matlab can be used interactively as a super hand calculator, or, more powerfully, run using scripts (i.e., programs).

MATLAB INTRODUCTION. Matlab can be used interactively as a super hand calculator, or, more powerfully, run using scripts (i.e., programs). L A B 6 M A T L A B MATLAB INTRODUCTION Matlab is a commercial product that is used widely by students and faculty and researchers at UTEP. It provides a "high-level" programming environment for computing

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 2 Basic MATLAB Operation Dr Richard Greenaway 2 Basic MATLAB Operation 2.1 Overview 2.1.1 The Command Line In this Workshop you will learn how

More information

Introduction to Programming

Introduction to Programming Introduction to Programming Department of Computer Science and Information Systems Tingting Han (afternoon), Steve Maybank (evening) tingting@dcs.bbk.ac.uk sjmaybank@dcs.bbk.ac.uk Autumn 2017 Week 4: More

More information

Consider this m file that creates a file that you can load data into called rain.txt

Consider this m file that creates a file that you can load data into called rain.txt SAVING AND IMPORTING DATA FROM A DATA FILES AND PROCESSING AS A ONE DIMENSIONAL ARRAY If we save data in a file sequentially than we can call it back sequentially into a row vector. Consider this m file

More information

Script started on Thu 25 Aug :00:40 PM CDT

Script started on Thu 25 Aug :00:40 PM CDT Script started on Thu 25 Aug 2016 02:00:40 PM CDT < M A T L A B (R) > Copyright 1984-2014 The MathWorks, Inc. R2014a (8.3.0.532) 64-bit (glnxa64) February 11, 2014 To get started, type one of these: helpwin,

More information

General MATLAB Information 1

General MATLAB Information 1 Introduction to MATLAB General MATLAB Information 1 Once you initiate the MATLAB software, you will see the MATLAB logo appear and then the MATLAB prompt >>. The prompt >> indicates that MATLAB is awaiting

More information

Chapter 1 Introduction to MATLAB

Chapter 1 Introduction to MATLAB Chapter 1 Introduction to MATLAB 1.1 What is MATLAB? MATLAB = MATrix LABoratory, the language of technical computing, modeling and simulation, data analysis and processing, visualization and graphics,

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab By:Mohammad Sadeghi *Dr. Sajid Gul Khawaja Slides has been used partially to prepare this presentation Outline: What is Matlab? Matlab Screen Basic functions Variables, matrix, indexing

More information

Introduction to MATLAB

Introduction to MATLAB Outlines January 30, 2008 Outlines Part I: Part II: Writing MATLAB Functions Starting MATLAB Exiting MATLAB Getting Help Command Window Workspace Command History Current Directory Selector Real Values

More information

A. Python Crash Course

A. Python Crash Course A. Python Crash Course Agenda A.1 Installing Python & Co A.2 Basics A.3 Data Types A.4 Conditions A.5 Loops A.6 Functions A.7 I/O A.8 OLS with Python 2 A.1 Installing Python & Co You can download and install

More information

Lab Five. COMP Advanced Artificial Intelligence Xiaowei Huang Cameron Hargreaves. October 29th 2018

Lab Five. COMP Advanced Artificial Intelligence Xiaowei Huang Cameron Hargreaves. October 29th 2018 Lab Five COMP 219 - Advanced Artificial Intelligence Xiaowei Huang Cameron Hargreaves October 29th 2018 1 Decision Trees and Random Forests 1.1 Reading Begin by reading chapter three of Python Machine

More information

Fathom Dynamic Data TM Version 2 Specifications

Fathom Dynamic Data TM Version 2 Specifications Data Sources Fathom Dynamic Data TM Version 2 Specifications Use data from one of the many sample documents that come with Fathom. Enter your own data by typing into a case table. Paste data from other

More information

AMS 27L LAB #1 Winter 2009

AMS 27L LAB #1 Winter 2009 AMS 27L LAB #1 Winter 2009 Introduction to MATLAB Objectives: 1. To introduce the use of the MATLAB software package 2. To learn elementary mathematics in MATLAB Getting Started: Log onto your machine

More information

Ebooks Chemical Engineering

Ebooks Chemical Engineering Uploaded by: Ebooks Chemical Engineering https://www.facebook.com/pages/ebooks-chemical-engineering/238197077030 For More Books, softwares & tutorials Related to Chemical Engineering Join Us @facebook:

More information

GRAPH 4.4. Megha K. Raman APRIL 22, 2015

GRAPH 4.4. Megha K. Raman APRIL 22, 2015 GRAPH 4.4 By Megha K. Raman APRIL 22, 2015 1. Preface... 4 2. Introduction:... 4 3. Plotting a function... 5 Sample funtions:... 9 List of Functions:... 10 Constants:... 10 Operators:... 11 Functions:...

More information

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano MATLAB Lesson I Chiara Lelli Politecnico di Milano October 2, 2012 MATLAB MATLAB (MATrix LABoratory) is an interactive software system for: scientific computing statistical analysis vector and matrix computations

More information

Excel Tool: Calculations with Data Sets

Excel Tool: Calculations with Data Sets Excel Tool: Calculations with Data Sets The best thing about Excel for the scientist is that it makes it very easy to work with data sets. In this assignment, we learn how to do basic calculations that

More information

Python Programming Exercises 1

Python Programming Exercises 1 Python Programming Exercises 1 Notes: throughout these exercises >>> preceeds code that should be typed directly into the Python interpreter. To get the most out of these exercises, don t just follow them

More information

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial CSI31 Lecture 5 Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial 1 3.1 Numberic Data Types When computers were first developed, they were seen primarily as

More information

6-1 (Function). (Function) !*+!"#!, Function Description Example. natural logarithm of x (base e) rounds x to smallest integer not less than x

6-1 (Function). (Function) !*+!#!, Function Description Example. natural logarithm of x (base e) rounds x to smallest integer not less than x (Function) -1.1 Math Library Function!"#! $%&!'(#) preprocessor directive #include !*+!"#!, Function Description Example sqrt(x) square root of x sqrt(900.0) is 30.0 sqrt(9.0) is 3.0 exp(x) log(x)

More information

Introduction to Engineering gii

Introduction to Engineering gii 25.108 Introduction to Engineering gii Dr. Jay Weitzen Lecture Notes I: Introduction to Matlab from Gilat Book MATLAB - Lecture # 1 Starting with MATLAB / Chapter 1 Topics Covered: 1. Introduction. 2.

More information

Lecture 1: What is MATLAB?

Lecture 1: What is MATLAB? Lecture 1: What is MATLAB? Dr. Mohammed Hawa Electrical Engineering Department University of Jordan EE201: Computer Applications. See Textbook Chapter 1. MATLAB MATLAB (MATrix LABoratory) is a numerical

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

MATLAB Constants, Variables & Expression. 9/12/2015 By: Nafees Ahmed

MATLAB Constants, Variables & Expression. 9/12/2015 By: Nafees Ahmed MATLAB Constants, Variables & Expression Introduction MATLAB can be used as a powerful programming language. It do have IF, WHILE, FOR lops similar to other programming languages. It has its own vocabulary

More information

Basic stuff -- assignments, arithmetic and functions

Basic stuff -- assignments, arithmetic and functions Basic stuff -- assignments, arithmetic and functions Most of the time, you will be using Maple as a kind of super-calculator. It is possible to write programs in Maple -- we will do this very occasionally,

More information

Introduction to MATLAB for CSE390

Introduction to MATLAB for CSE390 Introduction Introduction to MATLAB for CSE390 Professor Vijay Kumar Praveen Srinivasan University of Pennsylvania MATLAB is an interactive program designed for scientific computations, visualization and

More information

Introduction to MatLab. Introduction to MatLab K. Craig 1

Introduction to MatLab. Introduction to MatLab K. Craig 1 Introduction to MatLab Introduction to MatLab K. Craig 1 MatLab Introduction MatLab and the MatLab Environment Numerical Calculations Basic Plotting and Graphics Matrix Computations and Solving Equations

More information

Math 2250 MATLAB TUTORIAL Fall 2005

Math 2250 MATLAB TUTORIAL Fall 2005 Math 2250 MATLAB TUTORIAL Fall 2005 Math Computer Lab The Mathematics Computer Lab is located in the T. Benny Rushing Mathematics Center (located underneath the plaza connecting JWB and LCB) room 155C.

More information

A QUICK INTRODUCTION TO MATLAB

A QUICK INTRODUCTION TO MATLAB A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Basic operations and a few illustrations This set is independent from rest of the class notes. Matlab will be covered in recitations and occasionally

More information

Matlab Introduction. Scalar Variables and Arithmetic Operators

Matlab Introduction. Scalar Variables and Arithmetic Operators Matlab Introduction Matlab is both a powerful computational environment and a programming language that easily handles matrix and complex arithmetic. It is a large software package that has many advanced

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

Python Crash Course Numpy, Scipy, Matplotlib

Python Crash Course Numpy, Scipy, Matplotlib Python Crash Course Numpy, Scipy, Matplotlib That is what learning is. You suddenly understand something you ve understood all your life, but in a new way. Doris Lessing Steffen Brinkmann Max-Planck-Institut

More information

Computer Lab 1: Introduction to Python

Computer Lab 1: Introduction to Python Computer Lab 1: Introduction to Python 1 I. Introduction Python is a programming language that is fairly easy to use. We will use Python for a few computer labs, beginning with this 9irst introduction.

More information

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Intro to matlab getting started Basic operations and a few illustrations This set is indepent from rest of the class notes. Matlab will be covered

More information

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS 1 6 3 Matlab 3.1 Fundamentals Matlab. The name Matlab stands for matrix laboratory. Main principle. Matlab works with rectangular

More information

Lecturer: Keyvan Dehmamy

Lecturer: Keyvan Dehmamy MATLAB Tutorial Lecturer: Keyvan Dehmamy 1 Topics Introduction Running MATLAB and MATLAB Environment Getting help Variables Vectors, Matrices, and linear Algebra Mathematical Functions and Applications

More information

3+2 3*2 3/2 3^2 3**2 In matlab, use ^ or ** for exponentiation. In fortran, use only ** not ^ VARIABLES LECTURE 1: ARITHMETIC AND FUNCTIONS

3+2 3*2 3/2 3^2 3**2 In matlab, use ^ or ** for exponentiation. In fortran, use only ** not ^ VARIABLES LECTURE 1: ARITHMETIC AND FUNCTIONS LECTURE 1: ARITHMETIC AND FUNCTIONS MATH 190 WEBSITE: www.math.hawaii.edu/ gautier/190.html PREREQUISITE: You must have taken or be taking Calculus I concurrently. If not taken here, specify the college

More information

Programming for Engineers in Python. Recitation 3

Programming for Engineers in Python. Recitation 3 Programming for Engineers in Python Recitation 3 Plan Modules / Packages Tuples Mutable / Imutable Dictionaries Functions: Scope Call by Ref / Call by Val Frequency Counter Python Code Hierarchy Statement

More information

Some elements for Matlab programming

Some elements for Matlab programming Some elements for Matlab programming Nathalie Thomas 2018 2019 Matlab, which stands for the abbreviation of MATrix LABoratory, is one of the most popular language for scientic computation. The classical

More information

ENGR Fall Exam 1

ENGR Fall Exam 1 ENGR 1300 Fall 01 Exam 1 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. Read carefully..

More information

Functions. Systems Programming Concepts

Functions. Systems Programming Concepts Functions Systems Programming Concepts Functions Simple Function Example Function Prototype and Declaration Math Library Functions Function Definition Header Files Random Number Generator Call by Value

More information

ENGR Fall Exam 1

ENGR Fall Exam 1 ENGR 13100 Fall 2012 Exam 1 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. Read carefully.

More information

Lab 1 Intro to MATLAB and FreeMat

Lab 1 Intro to MATLAB and FreeMat Lab 1 Intro to MATLAB and FreeMat Objectives concepts 1. Variables, vectors, and arrays 2. Plotting data 3. Script files skills 1. Use MATLAB to solve homework problems 2. Plot lab data and mathematical

More information

Excel R Tips. is used for multiplication. + is used for addition. is used for subtraction. / is used for division

Excel R Tips. is used for multiplication. + is used for addition. is used for subtraction. / is used for division Excel R Tips EXCEL TIP 1: INPUTTING FORMULAS To input a formula in Excel, click on the cell you want to place your formula in, and begin your formula with an equals sign (=). There are several functions

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

A General Introduction to Matlab

A General Introduction to Matlab Master Degree Course in ELECTRONICS ENGINEERING http://www.dii.unimore.it/~lbiagiotti/systemscontroltheory.html A General Introduction to Matlab e-mail: luigi.biagiotti@unimore.it http://www.dii.unimore.it/~lbiagiotti

More information

MATLAB Workshop Dr. M. T. Mustafa Department of Mathematical Sciences. Introductory remarks

MATLAB Workshop Dr. M. T. Mustafa Department of Mathematical Sciences. Introductory remarks MATLAB Workshop Dr. M. T. Mustafa Department of Mathematical Sciences Introductory remarks MATLAB: a product of mathworks www.mathworks.com MATrix LABoratory What can we do (in or ) with MATLAB o Use like

More information

PIV Programming. Today s Contents: 1. Matlab Programming 2. An example of PIV in Matlab code 3. EDPIV 4. PIV plugin for ImageJ 5.

PIV Programming. Today s Contents: 1. Matlab Programming 2. An example of PIV in Matlab code 3. EDPIV 4. PIV plugin for ImageJ 5. PIV Programming Last Class: 1. Introduction of μpiv 2. Considerations of Microscopy in μpiv 3. Depth of Correlation 4. Physics of Particles in Micro PIV 5. Measurement Errors 6. Special Processing Methods

More information

Computer Programming in MATLAB

Computer Programming in MATLAB Computer Programming in MATLAB Prof. Dr. İrfan KAYMAZ Atatürk University Engineering Faculty Department of Mechanical Engineering What is a computer??? Computer is a device that computes, especially a

More information

Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003

Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003 Introduction to MATLAB Computational Probability and Statistics CIS 2033 Section 003 About MATLAB MATLAB (MATrix LABoratory) is a high level language made for: Numerical Computation (Technical computing)

More information

CT 229 Java Syntax Continued

CT 229 Java Syntax Continued CT 229 Java Syntax Continued 06/10/2006 CT229 Lab Assignments Due Date for current lab assignment : Oct 8 th Before submission make sure that the name of each.java file matches the name given in the assignment

More information

The Very Basics of the R Interpreter

The Very Basics of the R Interpreter Chapter 2 The Very Basics of the R Interpreter OK, the computer is fired up. We have R installed. It is time to get started. 1. Start R by double-clicking on the R desktop icon. 2. Alternatively, open

More information

Table of Contents EVALUATION COPY

Table of Contents EVALUATION COPY Table of Contents Introduction... 1-2 A Brief History of Python... 1-3 Python Versions... 1-4 Installing Python... 1-5 Environment Variables... 1-6 Executing Python from the Command Line... 1-7 IDLE...

More information

Ch.1 Introduction. Why Machine Learning (ML)? manual designing of rules requires knowing how humans do it.

Ch.1 Introduction. Why Machine Learning (ML)? manual designing of rules requires knowing how humans do it. Ch.1 Introduction Syllabus, prerequisites Notation: Means pencil-and-paper QUIZ Means coding QUIZ Code respository for our text: https://github.com/amueller/introduction_to_ml_with_python Why Machine Learning

More information

CDA5530: Performance Models of Computers and Networks. Chapter 8: Using Matlab for Performance Analysis and Simulation

CDA5530: Performance Models of Computers and Networks. Chapter 8: Using Matlab for Performance Analysis and Simulation CDA5530: Performance Models of Computers and Networks Chapter 8: Using Matlab for Performance Analysis and Simulation Objective Learn a useful tool for mathematical analysis and simulation Interpreted

More information

1001ICT Introduction To Programming Lecture Notes

1001ICT Introduction To Programming Lecture Notes 1001ICT Introduction To Programming Lecture Notes School of Information and Communication Technology Griffith University Semester 1, 2015 1 M Environment console M.1 Purpose This environment supports programming

More information

C++, How to Program. Spring 2016 CISC1600 Yanjun Li 1

C++, How to Program. Spring 2016 CISC1600 Yanjun Li 1 Chapter 6 Function C++, How to Program Deitel & Deitel Spring 2016 CISC1600 Yanjun Li 1 Function A function is a collection of statements that performs a specific task - a single, well-defined task. Divide

More information

Introduction to Programming

Introduction to Programming Introduction to Programming session 9 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2010 These slides are created using Deitel s slides Sahrif University of Technology Outlines

More information

Description/History Objects/Language Description Commonly Used Basic Functions. More Specific Functionality Further Resources

Description/History Objects/Language Description Commonly Used Basic Functions. More Specific Functionality Further Resources R Outline Description/History Objects/Language Description Commonly Used Basic Functions Basic Stats and distributions I/O Plotting Programming More Specific Functionality Further Resources www.r-project.org

More information

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP) Digital Signal Processing Prof. Nizamettin AYDIN naydin@yildiz.edu.tr naydin@ieee.org http://www.yildiz.edu.tr/~naydin Course Details Course Code : 0113620 Course Name: Digital Signal Processing (Sayısal

More information

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX 1) Objective The objective of this lab is to review how to access Matlab, Simulink, and the Communications Toolbox, and to become familiar

More information

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4 BIL 104E Introduction to Scientific and Engineering Computing Lecture 4 Introduction Divide and Conquer Construct a program from smaller pieces or components These smaller pieces are called modules Functions

More information

Introduction to Programming with Python 3, Ami Gates. Chapter 1: Creating a Programming Environment

Introduction to Programming with Python 3, Ami Gates. Chapter 1: Creating a Programming Environment Introduction to Programming with Python 3, Ami Gates Chapter 1: Creating a Programming Environment 1.1: Python, IDEs, Libraries, Packages, and Platforms A first step to learning and using any new programming

More information

Chap 6 Function Define a function, which can reuse a piece of code, just with a few different values.

Chap 6 Function Define a function, which can reuse a piece of code, just with a few different values. Chap 6 Function Define a function, which can reuse a piece of code, just with a few different values. def tax(bill): """Adds 8% tax to a restaurant bill.""" bill *= 1.08 print "With tax: %f" % bill return

More information

A very brief Matlab introduction

A very brief Matlab introduction A very brief Matlab introduction Siniša Krajnović January 24, 2006 This is a very brief introduction to Matlab and its purpose is only to introduce students of the CFD course into Matlab. After reading

More information

Applied Calculus. Lab 1: An Introduction to R

Applied Calculus. Lab 1: An Introduction to R 1 Math 131/135/194, Fall 2004 Applied Calculus Profs. Kaplan & Flath Macalester College Lab 1: An Introduction to R Goal of this lab To begin to see how to use R. What is R? R is a computer package for

More information

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation CDA6530: Performance Models of Computers and Networks Chapter 4: Using Matlab for Performance Analysis and Simulation Objective Learn a useful tool for mathematical analysis and simulation Interpreted

More information

C Functions. 5.2 Program Modules in C

C Functions. 5.2 Program Modules in C 1 5 C Functions 5.2 Program Modules in C 2 Functions Modules in C Programs combine user-defined functions with library functions - C standard library has a wide variety of functions Function calls Invoking

More information

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation CDA6530: Performance Models of Computers and Networks Chapter 4: Using Matlab for Performance Analysis and Simulation Objective Learn a useful tool for mathematical analysis and simulation Interpreted

More information

Programming for Engineers in Python. Recitation 3 Functions

Programming for Engineers in Python. Recitation 3 Functions Programming for Engineers in Python Recitation 3 Functions Plan Short review FOR and Lists Python references Mutable vs. immutable data types List references Functions Scope Call by assignment Global variables

More information

VARIABLES Storing numbers:

VARIABLES Storing numbers: VARIABLES Storing numbers: You may create and use variables in Matlab to store data. There are a few rules on naming variables though: (1) Variables must begin with a letter and can be followed with any

More information

(DRAFT) PYTHON FUNDAMENTALS II: NUMPY & MATPLOTLIB

(DRAFT) PYTHON FUNDAMENTALS II: NUMPY & MATPLOTLIB (DRAFT) PYTHON FUNDAMENTALS II: NUMPY & MATPLOTLIB TROY P. KLING Contents 1. Importing Libraries 1 2. Introduction to numpy 2 3. Introduction to matplotlib 5 4. Image Processing 8 5. The Mandelbrot Set

More information

Programming in MATLAB

Programming in MATLAB trevor.spiteri@um.edu.mt http://staff.um.edu.mt/trevor.spiteri Department of Communications and Computer Engineering Faculty of Information and Communication Technology University of Malta 17 February,

More information

YEAR 12 Core 1 & 2 Maths Curriculum (A Level Year 1)

YEAR 12 Core 1 & 2 Maths Curriculum (A Level Year 1) YEAR 12 Core 1 & 2 Maths Curriculum (A Level Year 1) Algebra and Functions Quadratic Functions Equations & Inequalities Binomial Expansion Sketching Curves Coordinate Geometry Radian Measures Sine and

More information

Introduction to MATLAB Practical 1

Introduction to MATLAB Practical 1 Introduction to MATLAB Practical 1 Daniel Carrera November 2016 1 Introduction I believe that the best way to learn Matlab is hands on, and I tried to design this practical that way. I assume no prior

More information

Single row numeric functions

Single row numeric functions Single row numeric functions Oracle provides a lot of standard numeric functions for single rows. Here is a list of all the single row numeric functions (in version 10.2). Function Description ABS(n) ABS

More information

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT PROGRAMMING WITH MATLAB DR. AHMET AKBULUT OVERVIEW WEEK 1 What is MATLAB? A powerful software tool: Scientific and engineering computations Signal processing Data analysis and visualization Physical system

More information

Getting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text

Getting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text Chapter 1 Getting Started How to Get Matlab Matlab physically resides on each of the computers in the Olin Hall labs. See your instructor if you need an account on these machines. If you are going to go

More information

High Level Scripting. Gino Tosti University & INFN Perugia. 06/09/2010 SciNeGhe Data Analysis Tutorial

High Level Scripting. Gino Tosti University & INFN Perugia. 06/09/2010 SciNeGhe Data Analysis Tutorial High Level Scripting Part I Gino Tosti University & INFN Perugia What is a script? Scripting Languages It is a small program able to automate a repetitive and boring job; It is a list of commands that

More information

A. Matrix-wise and element-wise operations

A. Matrix-wise and element-wise operations USC GSBME MATLAB CLASS Reviewing previous session Second session A. Matrix-wise and element-wise operations A.1. Matrix-wise operations So far we learned how to define variables and how to extract data

More information

TS Calc 1.6 User Guide

TS Calc 1.6 User Guide ! TS Calc 1.6 User Guide We Make Software - TensionSoftware.com TS Calc 2009-2018 Tension Software all rights reserved Every effort has been made to ensure that the information in this manual is accurate.

More information

Downloaded from Chapter 2. Functions

Downloaded from   Chapter 2. Functions Chapter 2 Functions After studying this lesson, students will be able to: Understand and apply the concept of module programming Write functions Identify and invoke appropriate predefined functions Create

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

Computer Science 121. Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans

Computer Science 121. Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans Computer Science 121 Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans 3.1 The Organization of Computer Memory Computers store information as bits : sequences of zeros and

More information

Data Science and Machine Learning Essentials

Data Science and Machine Learning Essentials Data Science and Machine Learning Essentials Lab 3A Visualizing Data By Stephen Elston and Graeme Malcolm Overview In this lab, you will learn how to use R or Python to visualize data. If you intend to

More information

Chapter 3 - Functions

Chapter 3 - Functions Chapter 3 - Functions 1 Outline 3.1 Introduction 3.2 Program Components in C++ 3.3 Math Library Functions 3.4 Functions 3.5 Function Definitions 3.6 Function Prototypes 3.7 Header Files 3.8 Random Number

More information

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window. EE 350L: Signals and Transforms Lab Spring 2007 Lab #1 - Introduction to MATLAB Lab Handout Matlab Software: Matlab will be the analytical tool used in the signals lab. The laboratory has network licenses

More information