Bi 1x Spring 2014: Plotting and linear regression

Size: px
Start display at page:

Download "Bi 1x Spring 2014: Plotting and linear regression"

Transcription

1 Bi 1x Spring 2014: Plotting and linear regression In this tutorial, we will learn some basics of how to plot experimental data. We will also learn how to perform linear regressions to get parameter estimates. In doing so, we will also get an introduction to NumPy s random number generation module, numpy.random, which we will use later on in the course. I also note that for the purposes of this simple tutorial, we are not going to consider error bars on experimental measurements nor error estimates on computed regression parameters. 1 Generating fake data For the purposes of this tutorial, we will generate some fake data to use for plotting. I chose to do this instead of giving you data because I want to also introduce you to random number generation in Python. We will create a module to generate fake data. Store it in a file fake_data.py. 1 """ Module to generate random data 3 """ 5 import numpy. random as np_rand 7 # ######################## def generate_ fake_ data (x, f, args =(), noise_ factor =0.1) : 9 """ Generates fake data that follows a function f(x, * args ) with random noise The data are generate at points x. The amplitude of the noise from the function scales like 15 noise_factor * mean ( abs (f(x))). 17 args is a tuple of other parameters that are passed into f. """ 19 # Generate base curve 21 base_ curve = f(x, * args ) 23 # Generate random noise ( sample random numbers on interval [ -1,1] noise = 2.0 * np_rand. rand ( len (x)) # Add noise 27 y = base_ curve + noise_ factor * abs ( base_ curve ). mean () * noise 29 return y 31 # ###################### def linear_ function (x, m, b): 33 """ Returns m * x + b. 35 """ 1

2 return m * x + b The function numpy.random.rand generates uniformly distributed random numbers on the interval [0, 1). The argument to the functions says how many numbers to generate. For example, rand(100) returns an np.ndarray of 100 random numbers between zero and one. To get uniformly distributed random numbers on the interval [ 1, 1), we linearly transform the numbers, as in line 27 above. For today, we will generate fake data that falls along a line. We therefore also include a simple linear function in our fake_data module. Note that in the generate_data function, we has used a function call f(x, *args). In Python, we can take a tuple and pass it as separate arguments into a function by using the * operator. We can test it out In [1]: import fake_ data In [2]: x = 1.0 In [3]: m, b = 4.0, 5.0 In [4]: args = (4.0, 5.0) In [5]: fake_ data. linear_ function (x, m, b) In [6]: fake_data. linear_function (x, * args ) In [7]: fake_ data. linear_ function (x, args ) The last function call will give an error, because without the *, args is just a single argument passed into the function. To generate the fake data for use within our Python window in Canopy, we simply use these functions. In [8]: import numpy as np In [9]: x = np. linspace (0.0, 10.0, 20) # 20 evenly spaces pts from 0 to 10 In [10]: y = fake_ data. generate_ fake_ data (x, fake_ data. linear_ function, args = args ) In [11]: x, y We now have our fake data, and we can begin plotting. 2 Plotting experimental data 2.1 Plotting data points The plt.plot function is the main utility for plotting data. You have seen the plt.fill_between function in the image processing tutorial, which was useful for viewing histograms, but that is in a way a fancy plotting function. You have also used skimage.io.imshow repeatedly, which is plotting data, as we have discussed. plt.plot is the workhorse of plotting. So, let s start by naively just plotting our data. 2

3 In [12]: import matplotlib. pyplot as plt In [13]: plt. plot (x, y) In [14]: plt. draw () In [15]: plt. show () First off, note that the function calls to plt.draw and plt.show are often unnecessary when operating in the Canopy Python window. They are necessary, however, to pull up windows with plots when you are running scripts. Now, when we look at our plot, we see that the default is to connect points with straight lines. This is useful when plotting theoretical curves. We sample the curves at dense points (e.g., x = np.linspace(0, 1, 200)), and then plot the function as a line. However, for experimental data do not plot your data as lines unless it is very highly sampled, like in an electrocardiogram. Plot your data as individual points. To do this, we can make use of plt.plot s many keyword arguments. In [16]: plt. clf () # This clears the figure window In [17]: plt. plot (x, y, marker = o, linestyle = none ) In [18]: plt. draw () ; plt. show () Now, we have a series of dots. There are many keyword arguments that give you lots of control over how the data are presented. In [19]: plt. plot? Finally, we most often plot our data as black dots. A shortcut to get this kind of plot is In [20]: plt. clf () In [21]: plt. plot (x, y, ko ) In [22]: plt. draw () ; plt. show () 2.2 Labeling axes Now that we have a plot to work with, we can label our axes. Always label your axes. As a reminder, always label your axes. I would say it a third time, but that would be obnoxious. Let us pretend for a moment that our x-axis is time in units of years and the y-axis is the average height of trees in my yard. Then, we would label our axes as In [23]: plt. xlabel ( time [ years ], fontsize =18) In [24]: plt. ylabel ( average height [ feet ], fontsize =18) In [25]: plt. draw () ; plt. show () Note that I have used the fontsize keyword argument to control the font size. Always make your fonts large enough to be easily legible. You can play around with with the font size to make it look right. 3

4 2.3 Legends If you have multiple plots, it is often useful to have a legend. Just for demonstration purposes, we ll make a legend for our single plot, In [26]: plt. legend (( tree height,), loc = upper left, numpoints =1, fontsize =16) In [27]: plt. draw () ; plt. show () Notices that the first argument is a tuple containing the labels for your curves. The ordering of the tuple corresponds to the order in which the curves were put in the figure using plt.plot. For multiple curves, it would have more than one entry. I also like to use the numpoints keyword argument to include only one marker in the legend. The default is to include two, which I think is ugly. Note that the text may seem off-center in the legend. This is usually corrected with you save the figure (see below). 2.4 Saving your plot You can save your figure. It is best to save it as vector graphics, such as PDF or SVG. PDF is usually preferred. In [28]: plt. tight_ layout () In [29]: plt. draw () ; plt. show () In [30]: plt. savefig ( tree_height. pdf ) The plt.tight_layout function is convenient to make sure all axis labels, etc., will appear properly in your saved figure. 3 Performing a linear regression To perform a linear regression, we try to find the values of m and b for the line y = mx + b that best describe the data. To do so, we minimize the sum of the square of the residuals. A residual is the difference between the line you are fitting and the data point itself for a given point x. For example, let s say experimental data point i, (x i, y i ), should fall on the line y = mx + b. The residual for point i is r i y i y = y i (mx i + b). (1) To get an idea of what the residuals are, we can draw a line through our data and plot the residuals in red. In [31]: y_theor = 4.0 * x In [32]: plot (x, y_theor, linestyle = -, color = gray ) In [33]: for i in xrange ( len (x)):...: plot ((x[i], x[i]), (y[i], y_theor [i]), r- ) In [34]: plt. draw () ; plt. show () 4

5 We can see from the plot that if we minimize the sum of the squares of the residuals, we can get the line that is closest to all the points taken together. (Note: This is a very deep topic, and we are only scratching the very surface.) So, the linear regression problem can be stated as m, b = arg min m,b [y i (mx i + b)] 2, (2) i where the term in brackets is the residual for data point i. This optimization problem is called a least squares problem. For the case where the function we are fitting our data with is a polynomial (such as a line), the problem has a unique solution that can be found by matrix operations. The details can be found in most introductory linear algebra textbooks. We will instead use the curve_fit function in the scipy.optimize module to perform the curve fit. I chose to do this instead of working through the linear algebra because this function can also be used to perform nonlinear regression. It is well-worth reading the doc string for this function. In [35]: from scipy. optimize import curve_ fit In [36]: curve_ fit? The first argument is the function we are fitting the data to. It must be of the form f(x, *args), which is conveniently what we already specified. The keyword argument p0 is the guess at the best parameters as an np.ndarray. For fitting a linear function, it is not important to specify this, but it is a very good idea to do so, as it can be very important for nonlinear regression (which we will do later in Bi 1x). The function curve_fit will assume that p0 is all ones otherwise. curve_fit returns to np.ndarrays. The first contains the best-fit parameters, given in the order that they are inputted into the fit function f. The second is the covariance matrix, the diagonals of which are supposed to give the variance of the fit parameters. Warning: in curve_fit s implementation, they variances will not be correctly reported unless you include error bars with you data, which we will not be doing in Bi 1x. Therefore, you should ignore the covariance matrix returned by curve_fit for the purposes of Bi 1x. Note also that if you want more control over your curve fitting routines and want to do more sophisticated error analysis, you can directly use scipy.optimize.leastsq, which is what curve_fit uses under the hood. Without further ado, let s fit our data with a line. In [37]: popt, pcov = curve_ fit ( fake_ data. linear_ function, x, y, p0 =(4.0, 5.0) ) In [38]: m, b = popt In [39]: m, b We can make a plot of our data with the curve fit. In [39]: x_theor = np. linspace (x[0], x[ -1], 200) In [40]: y_theor = fake_ data. linear_ function ( x_theor, * popt ) In [41]: plt. clf () In [42]: plt. plot (x, y, ko ) 5

6 In [43]: plt. plot ( x_theor, y_theor, linestyle = -, color = gray ) In [44]: plt. xlabel ( time [ years ], fontsize =18) In [45]: plt. ylabel ( average height [ feet ], fontsize =18) In [46]: plt. draw () ; plt. show () Now that you know how to do a linear regression, I d like you to think about this: If you know that your data had to pass through zero, i.e., that you only had to fit the slope and not the slope plus intercept, how would you do it? 6

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

Plotting With matplotlib

Plotting With matplotlib Lab Plotting With matplotlib and Mayavi Lab Objective: Introduce some of the basic plotting functions available in matplotlib and Mayavi. -D plotting with matplotlib The Python library matplotlib will

More information

Chemistry 1A Graphing Tutorial CSUS Department of Chemistry

Chemistry 1A Graphing Tutorial CSUS Department of Chemistry Chemistry 1A Graphing Tutorial CSUS Department of Chemistry Please go to the Lab webpage to download your own copy for reference. 1 When you open Microsoft Excel 2003, you will see a blank worksheet: Enter

More information

Tutorial 2 PHY409 Anadi Canepa Office, TRIUMF MOB 92 B ( )

Tutorial 2 PHY409 Anadi Canepa Office, TRIUMF MOB 92 B ( ) Tutorial 2 PHY409 Anadi Canepa canepa@triumf.ca Office, TRIUMF MOB 92 B (1-604- 222-7330) Alan Manning mannin2@phas.ubc.ca Mohammad Samani samani@physics.ubc.ca During the 1 st tutorial We learnt What

More information

APPM 2460 PLOTTING IN MATLAB

APPM 2460 PLOTTING IN MATLAB APPM 2460 PLOTTING IN MATLAB. Introduction Matlab is great at crunching numbers, and one of the fundamental ways that we understand the output of this number-crunching is through visualization, or plots.

More information

Interpolation and curve fitting

Interpolation and curve fitting CITS2401 Computer Analysis and Visualization School of Computer Science and Software Engineering Lecture 9 Interpolation and curve fitting 1 Summary Interpolation Curve fitting Linear regression (for single

More information

AMath 483/583 Lecture 28 June 1, Notes: Notes: Python scripting for Fortran codes. Python scripting for Fortran codes.

AMath 483/583 Lecture 28 June 1, Notes: Notes: Python scripting for Fortran codes. Python scripting for Fortran codes. AMath 483/583 Lecture 28 June 1, 2011 Today: Python plus Fortran Comments on quadtests.py for project Linear vs. log-log plots Visualization Friday: Animation: plots to movies Binary I/O Parallel IPython

More information

Intro to Research Computing with Python: Visualization

Intro to Research Computing with Python: Visualization Intro to Research Computing with Python: Visualization Erik Spence SciNet HPC Consortium 20 November 2014 Erik Spence (SciNet HPC Consortium) Visualization 20 November 2014 1 / 29 Today s class Today we

More information

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as Geog 271 Geographic Data Analysis Fall 2015 PyPlot Graphicscanbeproducedin Pythonviaavarietyofpackages. We willuseapythonplotting package that is part of MatPlotLib, for which documentation can be found

More information

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as Geog 271 Geographic Data Analysis Fall 2017 PyPlot Graphicscanbeproducedin Pythonviaavarietyofpackages. We willuseapythonplotting package that is part of MatPlotLib, for which documentation can be found

More information

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

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

More information

Experimental Design and Graphical Analysis of Data

Experimental Design and Graphical Analysis of Data Experimental Design and Graphical Analysis of Data A. Designing a controlled experiment When scientists set up experiments they often attempt to determine how a given variable affects another variable.

More information

Tutorial Four: Linear Regression

Tutorial Four: Linear Regression Tutorial Four: Linear Regression Imad Pasha Chris Agostino February 25, 2015 1 Introduction When looking at the results of experiments, it is critically important to be able to fit curves to scattered

More information

699DR git/github Tutorial

699DR git/github Tutorial 699DR git/github Tutorial Sep 20 2017 This tutorial gives a high-level introduction into basic usage of the version control software git in combination with the online platform Github. The git commands

More information

Using the Matplotlib Library in Python 3

Using the Matplotlib Library in Python 3 Using the Matplotlib Library in Python 3 Matplotlib is a Python 2D plotting library that produces publication-quality figures in a variety of hardcopy formats and interactive environments across platforms.

More information

Getting Started with MATLAB

Getting Started with MATLAB Getting Started with MATLAB Math 315, Fall 2003 Matlab is an interactive system for numerical computations. It is widely used in universities and industry, and has many advantages over languages such as

More information

User-Defined Function

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

More information

Visualisation in python (with Matplotlib)

Visualisation in python (with Matplotlib) Visualisation in python (with Matplotlib) Thanks to all contributors: Ag Stephens, Stephen Pascoe. Introducing Matplotlib Matplotlib is a python 2D plotting library which produces publication quality figures

More information

Lab 4: Structured Programming I

Lab 4: Structured Programming I 4.1 Introduction Lab 4: Structured Programming I Lab this week is going to focus on selective structures and functions. 4.2 Resources The additional resources required for this assignment include: 0 Books:

More information

No more questions will be added

No more questions will be added CSC 2545, Spring 2017 Kernel Methods and Support Vector Machines Assignment 2 Due at the start of class, at 2:10pm, Thurs March 23. No late assignments will be accepted. The material you hand in should

More information

An introduction to plotting data

An introduction to plotting data An introduction to plotting data Eric D. Black California Institute of Technology February 25, 2014 1 Introduction Plotting data is one of the essential skills every scientist must have. We use it on a

More information

Scientific Python: matplotlib

Scientific Python: matplotlib Scientific Python: matplotlib 17 July 2014 Introduction and Aims This exercise introduces the matplotlib module of Python. Matplotlib is a versatile plotting library that can be used to produce both quick

More information

5 File I/O, Plotting with Matplotlib

5 File I/O, Plotting with Matplotlib 5 File I/O, Plotting with Matplotlib Bálint Aradi Course: Scientific Programming / Wissenchaftliches Programmieren (Python) Installing some SciPy stack components We will need several Scipy components

More information

Euler s Method with Python

Euler s Method with Python Euler s Method with Python Intro. to Differential Equations October 23, 2017 1 Euler s Method with Python 1.1 Euler s Method We first recall Euler s method for numerically approximating the solution of

More information

Python Matplotlib. MACbioIDi February March 2018

Python Matplotlib. MACbioIDi February March 2018 Python Matplotlib MACbioIDi February March 2018 Introduction Matplotlib is a Python 2D plotting library Its origins was emulating the MATLAB graphics commands It makes heavy use of NumPy Objective: Create

More information

Programming for Engineers in Python

Programming for Engineers in Python Programming for Engineers in Python Autumn 2016-17 Lecture 11: NumPy & SciPy Introduction, Plotting and Data Analysis 1 Today s Plan Introduction to NumPy & SciPy Plotting Data Analysis 2 NumPy and SciPy

More information

26, 2016 TODAY'S AGENDA QUIZ

26, 2016 TODAY'S AGENDA QUIZ TODAY'S AGENDA - Complete Bell Ringer (in Canvas) - Complete Investigation 1 QUIZ (40 minutes) - Be sure your assignments from the week are complete (bell ringers, hw, makeup work) - Investigation 2.1

More information

10.4 Linear interpolation method Newton s method

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

More information

4. BASIC PLOTTING. JHU Physics & Astronomy Python Workshop Lecturer: Mubdi Rahman

4. BASIC PLOTTING. JHU Physics & Astronomy Python Workshop Lecturer: Mubdi Rahman 4. BASIC PLOTTING JHU Physics & Astronomy Python Workshop 2016 Lecturer: Mubdi Rahman INTRODUCING MATPLOTLIB! Very powerful plotting package. The Docs: http://matplotlib.org/api/pyplot_api.html GETTING

More information

Introductory Scientific Computing with Python

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

More information

Introduction to Matlab

Introduction to Matlab What is Matlab? Introduction to Matlab Matlab is software written by a company called The Mathworks (mathworks.com), and was first created in 1984 to be a nice front end to the numerical routines created

More information

LECTURE 22. Numerical and Scientific Computing Part 2

LECTURE 22. Numerical and Scientific Computing Part 2 LECTURE 22 Numerical and Scientific Computing Part 2 MATPLOTLIB We re going to continue our discussion of scientific computing with matplotlib. Matplotlib is an incredibly powerful (and beautiful!) 2-D

More information

Nonlinear curve-fitting example

Nonlinear curve-fitting example Nonlinear curve-fitting example Implementation of curve-fitting in Python. Compare with results of Mathematica for same data sets: see pythontest.nb. In [1]: import scipy as sp from scipy.optimize import

More information

INTRODUCTION TO DATA VISUALIZATION WITH PYTHON. Working with 2D arrays

INTRODUCTION TO DATA VISUALIZATION WITH PYTHON. Working with 2D arrays INTRODUCTION TO DATA VISUALIZATION WITH PYTHON Working with 2D arrays Reminder: NumPy arrays Homogeneous in type Calculations all at once Indexing with brackets: A[index] for 1D array A[index0, index1]

More information

Lecture 8. Divided Differences,Least-Squares Approximations. Ceng375 Numerical Computations at December 9, 2010

Lecture 8. Divided Differences,Least-Squares Approximations. Ceng375 Numerical Computations at December 9, 2010 Lecture 8, Ceng375 Numerical Computations at December 9, 2010 Computer Engineering Department Çankaya University 8.1 Contents 1 2 3 8.2 : These provide a more efficient way to construct an interpolating

More information

EE 350. Continuous-Time Linear Systems. Recitation 1. 1

EE 350. Continuous-Time Linear Systems. Recitation 1. 1 EE 350 Continuous-Time Linear Systems Recitation 1 Recitation 1. 1 Recitation 1 Topics MATLAB Programming Basic Operations, Built-In Functions, and Variables m-files Graphics: 2D plots EE 210 Review Branch

More information

NAVIGATING UNIX. Other useful commands, with more extensive documentation, are

NAVIGATING UNIX. Other useful commands, with more extensive documentation, are 1 NAVIGATING UNIX Most scientific computing is done on a Unix based system, whether a Linux distribution such as Ubuntu, or OSX on a Mac. The terminal is the application that you will use to talk to the

More information

CME 193: Introduction to Scientific Python Lecture 5: Numpy, Scipy, Matplotlib

CME 193: Introduction to Scientific Python Lecture 5: Numpy, Scipy, Matplotlib CME 193: Introduction to Scientific Python Lecture 5: Numpy, Scipy, Matplotlib Sven Schmit stanford.edu/~schmit/cme193 5: Numpy, Scipy, Matplotlib 5-1 Contents Second part of course Numpy Scipy Matplotlib

More information

Effective Programming Practices for Economists. 10. Some scientific tools for Python

Effective Programming Practices for Economists. 10. Some scientific tools for Python Effective Programming Practices for Economists 10. Some scientific tools for Python Hans-Martin von Gaudecker Department of Economics, Universität Bonn A NumPy primer The main NumPy object is the homogeneous

More information

3.7. Vertex and tangent

3.7. Vertex and tangent 3.7. Vertex and tangent Example 1. At the right we have drawn the graph of the cubic polynomial f(x) = x 2 (3 x). Notice how the structure of the graph matches the form of the algebraic expression. The

More information

Newton and Quasi-Newton Methods

Newton and Quasi-Newton Methods Lab 17 Newton and Quasi-Newton Methods Lab Objective: Newton s method is generally useful because of its fast convergence properties. However, Newton s method requires the explicit calculation of the second

More information

Python for Scientists

Python for Scientists High level programming language with an emphasis on easy to read and easy to write code Includes an extensive standard library We use version 3 History: Exists since 1991 Python 3: December 2008 General

More information

Here is the data collected.

Here is the data collected. Introduction to Scientific Analysis of Data Using Spreadsheets. Computer spreadsheets are very powerful tools that are widely used in Business, Science, and Engineering to perform calculations and record,

More information

Ingredients of Change: Nonlinear Models & 2.1 Exponential Functions and Models

Ingredients of Change: Nonlinear Models & 2.1 Exponential Functions and Models Chapter 2 Ingredients of Change: Nonlinear Models & 2.1 Exponential Functions and Models As we consider models that are not linear, it is very important that you be able to use scatter plots, numerical

More information

CME 193: Introduction to Scientific Python Lecture 6: Numpy, Scipy, Matplotlib

CME 193: Introduction to Scientific Python Lecture 6: Numpy, Scipy, Matplotlib CME 193: Introduction to Scientific Python Lecture 6: Numpy, Scipy, Matplotlib Nolan Skochdopole stanford.edu/class/cme193 6: Numpy, Scipy, Matplotlib 6-1 Contents Homeworks and Project Numpy Scipy Matplotlib

More information

ENGR (Socolofsky) Week 07 Python scripts

ENGR (Socolofsky) Week 07 Python scripts ENGR 102-213 (Socolofsky) Week 07 Python scripts A couple programming examples for this week are embedded in the lecture notes for Week 7. We repeat these here as brief examples of typical array-like operations

More information

Part VI. Scientific Computing in Python. Alfredo Parra : Scripting with Python Compact Max-PlanckMarch 6-10,

Part VI. Scientific Computing in Python. Alfredo Parra : Scripting with Python Compact Max-PlanckMarch 6-10, Part VI Scientific Computing in Python Compact Course @ Max-PlanckMarch 6-10, 2017 63 Doing maths in Python Standard sequence types (list, tuple,... ) Can be used as arrays Can contain different types

More information

0 Graphical Analysis Use of Excel

0 Graphical Analysis Use of Excel Lab 0 Graphical Analysis Use of Excel What You Need To Know: This lab is to familiarize you with the graphing ability of excels. You will be plotting data set, curve fitting and using error bars on the

More information

Matlab Tutorial 1: Working with variables, arrays, and plotting

Matlab Tutorial 1: Working with variables, arrays, and plotting Matlab Tutorial 1: Working with variables, arrays, and plotting Setting up Matlab First of all, let's make sure we all have the same layout of the different windows in Matlab. Go to Home Layout Default.

More information

Grace days can not be used for this assignment

Grace days can not be used for this assignment CS513 Spring 19 Prof. Ron Matlab Assignment #0 Prepared by Narfi Stefansson Due January 30, 2019 Grace days can not be used for this assignment The Matlab assignments are not intended to be complete tutorials,

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab November 22, 2013 Contents 1 Introduction to Matlab 1 1.1 What is Matlab.................................. 1 1.2 Matlab versus Maple............................... 2 1.3 Getting

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

Scientific Programming. Lecture A08 Numpy

Scientific Programming. Lecture A08 Numpy Scientific Programming Lecture A08 Alberto Montresor Università di Trento 2018/10/25 Acknowledgments: Stefano Teso, Documentation http://disi.unitn.it/~teso/courses/sciprog/python_appendices.html https://docs.scipy.org/doc/numpy-1.13.0/reference/

More information

EOSC 473/573 Matlab Tutorial R. Pawlowicz with changes by M. Halverson

EOSC 473/573 Matlab Tutorial R. Pawlowicz with changes by M. Halverson EOSC 473/573 Matlab Tutorial R. Pawlowicz with changes by M. Halverson February 12, 2008 Getting help 1. Local On-line help (a) text-based help: >> help (b) GUI-help >> helpwin (c) Browser-based

More information

Lab 6: Graphical Methods

Lab 6: Graphical Methods Lab 6: Graphical Methods 6.1 Introduction EGR 53L - Fall 2009 Lab this week is going to introduce graphical solution and presentation techniques as well as surface plots. 6.2 Resources The additional resources

More information

Polymath 6. Overview

Polymath 6. Overview Polymath 6 Overview Main Polymath Menu LEQ: Linear Equations Solver. Enter (in matrix form) and solve a new system of simultaneous linear equations. NLE: Nonlinear Equations Solver. Enter and solve a new

More information

Graphing Linear Equations

Graphing Linear Equations Graphing Linear Equations A.REI.10 Understand that the graph of an equation in two variables is the set of all its solutions plotted in the coordinate plane. What am I learning today? How to graph a linear

More information

Introduction to Matplotlib: 3D Plotting and Animations

Introduction to Matplotlib: 3D Plotting and Animations 1 Introduction to Matplotlib: 3D Plotting and Animations Lab Objective: 3D plots and animations are useful in visualizing solutions to ODEs and PDEs found in many dynamics and control problems. In this

More information

Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving MATLAB Tutorial Vb

Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving MATLAB Tutorial Vb Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving MATLAB Tutorial Vb Making Plots with Matlab (last updated 5/29/05 by GGB) Objectives: These tutorials are

More information

Objectives. 1 Basic Calculations. 2 Matrix Algebra. Physical Sciences 12a Lab 0 Spring 2016

Objectives. 1 Basic Calculations. 2 Matrix Algebra. Physical Sciences 12a Lab 0 Spring 2016 Physical Sciences 12a Lab 0 Spring 2016 Objectives This lab is a tutorial designed to a very quick overview of some of the numerical skills that you ll need to get started in this class. It is meant to

More information

MATLAB Modul 3. Introduction

MATLAB Modul 3. Introduction MATLAB Modul 3 Introduction to Computational Science: Modeling and Simulation for the Sciences, 2 nd Edition Angela B. Shiflet and George W. Shiflet Wofford College 2014 by Princeton University Press Introduction

More information

dyplot Documentation Release Tsung-Han Yang

dyplot Documentation Release Tsung-Han Yang dyplot Documentation Release Tsung-Han Yang February 25, 2016 Contents 1 Motivation 3 2 Introduction 5 3 Tutorials 7 3.1 Plot three series.............................................. 7 3.2 Pie Chart.................................................

More information

Skills Quiz - Python Edition Solutions

Skills Quiz - Python Edition Solutions 'XNH8QLYHUVLW\ (GPXQG73UDWW-U6FKRRORI(QJLQHHULQJ EGR 103L Fall 2017 Skills Quiz - Python Edition Solutions Michael R. Gustafson II Name (please print): NetID (please print): In keeping with the Community

More information

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix. MATLAB Tutorial 1 1 Department of Mathematics and Statistics, The University of New Mexico, Albuquerque, NM 87131 August 28, 2016 Contents: 1. Scalars, Vectors, Matrices... 1 2. Built-in variables, functions,

More information

Math Scientific Computing - Matlab Intro and Exercises: Spring 2003

Math Scientific Computing - Matlab Intro and Exercises: Spring 2003 Math 64 - Scientific Computing - Matlab Intro and Exercises: Spring 2003 Professor: L.G. de Pillis Time: TTh :5pm 2:30pm Location: Olin B43 February 3, 2003 Matlab Introduction On the Linux workstations,

More information

Computational Physics Programming Style and Practices & Visualizing Data via Plotting

Computational Physics Programming Style and Practices & Visualizing Data via Plotting Computational Physics Programming Style and Practices & Visualizing Data via Plotting Prof. Paul Eugenio Department of Physics Florida State University Jan 30, 2018 http://comphy.fsu.edu/~eugenio/comphy/

More information

Sketching graphs of polynomials

Sketching graphs of polynomials Sketching graphs of polynomials We want to draw the graphs of polynomial functions y = f(x). The degree of a polynomial in one variable x is the highest power of x that remains after terms have been collected.

More information

Basic Beginners Introduction to plotting in Python

Basic Beginners Introduction to plotting in Python Basic Beginners Introduction to plotting in Python Sarah Blyth July 23, 2009 1 Introduction Welcome to a very short introduction on getting started with plotting in Python! I would highly recommend that

More information

UNIVERSITETET I OSLO

UNIVERSITETET I OSLO (Continued on page 2.) UNIVERSITETET I OSLO Det matematisk-naturvitenskapelige fakultet Examination in: INF1100 Introduction to programming with scientific applications Day of examination: Thursday, October

More information

Sampling from distributions

Sampling from distributions Sampling from distributions December 17, 2015 1 Sampling from distributions Now that we are able to sample equally distributed (pseudo-)random numbers in the interval [1, 0), we are now able to sample

More information

Lecture 15: High Dimensional Data Analysis, Numpy Overview

Lecture 15: High Dimensional Data Analysis, Numpy Overview Lecture 15: High Dimensional Data Analysis, Numpy Overview Chris Tralie, Duke University 3/3/2016 Announcements Mini Assignment 3 Out Tomorrow, due next Friday 3/11 11:55PM Rank Top 3 Final Project Choices

More information

More on Curve Fitting

More on Curve Fitting PHY 310 DataAnalysis 5 More on Curve Fitting In [1]: # All the standard "import" stuff import scipy as sp from scipy.optimize import curve_fit from scipy.linalg import lstsq import matplotlib.pyplot as

More information

Introductory Scientific Computing with Python

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

More information

UNIT I READING: GRAPHICAL METHODS

UNIT I READING: GRAPHICAL METHODS UNIT I READING: GRAPHICAL METHODS One of the most effective tools for the visual evaluation of data is a graph. The investigator is usually interested in a quantitative graph that shows the relationship

More information

9.1 Linear Inequalities in Two Variables Date: 2. Decide whether to use a solid line or dotted line:

9.1 Linear Inequalities in Two Variables Date: 2. Decide whether to use a solid line or dotted line: 9.1 Linear Inequalities in Two Variables Date: Key Ideas: Example Solve the inequality by graphing 3y 2x 6. steps 1. Rearrange the inequality so it s in mx ± b form. Don t forget to flip the inequality

More information

EE 301 Signals & Systems I MATLAB Tutorial with Questions

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

More information

ENV Laboratory 2: Graphing

ENV Laboratory 2: Graphing Name: Date: Introduction It is often said that a picture is worth 1,000 words, or for scientists we might rephrase it to say that a graph is worth 1,000 words. Graphs are most often used to express data

More information

#To import the whole library under a different name, so you can type "diff_name.f unc_name" import numpy as np import matplotlib.

#To import the whole library under a different name, so you can type diff_name.f unc_name import numpy as np import matplotlib. In [1]: #Here I import the relevant function libraries #This can be done in many ways #To import an entire library (e.g. scipy) so that functions accessed by typing "l ib_name.func_name" import matplotlib

More information

windrose Documentation Lionel Roubeyrie & Sebastien Celles

windrose Documentation Lionel Roubeyrie & Sebastien Celles Lionel Roubeyrie & Sebastien Celles Sep 04, 2018 Contents: 1 Install 3 1.1 Requirements............................................... 3 1.2 Install latest release version via pip...................................

More information

Objectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014

Objectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014 PS 12a Laboratory 1 Spring 2014 Objectives This session is a tutorial designed to a very quick overview of some of the numerical skills that you ll need to get started. Throughout the tutorial, the instructors

More information

Numerical Calculations

Numerical Calculations Fundamentals of Programming (Python) Numerical Calculations Sina Sajadmanesh Sharif University of Technology Some slides have been adapted from Scipy Lecture Notes at http://www.scipy-lectures.org/ Outline

More information

Test 1 - Python Edition

Test 1 - Python Edition 'XNH8QLYHUVLW\ (GPXQG73UDWW-U6FKRRORI(QJLQHHULQJ EGR 103L Spring 2018 Test 1 - Python Edition Shaundra B. Daily & Michael R. Gustafson II NetID (please print): In keeping with the Community Standard, I

More information

Pre-Lab Excel Problem

Pre-Lab Excel Problem Pre-Lab Excel Problem Read and follow the instructions carefully! Below you are given a problem which you are to solve using Excel. If you have not used the Excel spreadsheet a limited tutorial is given

More information

Graphical Analysis of Data using Microsoft Excel [2016 Version]

Graphical Analysis of Data using Microsoft Excel [2016 Version] Graphical Analysis of Data using Microsoft Excel [2016 Version] Introduction In several upcoming labs, a primary goal will be to determine the mathematical relationship between two variable physical parameters.

More information

2. For each of the regular expressions, give a string that will matches it:

2. For each of the regular expressions, give a string that will matches it: CMP 464-C401 Sample Final Exam, Spring 2016 1. What will the following code draw: n = 10 X = np.arange(n) Y1 = X/2.0 Y2 = X/4.0 plt.bar(x, +Y1, facecolor= blue ) plt.bar(x, -Y2, facecolor= red ) for x,

More information

Section Graphs and Lines

Section Graphs and Lines Section 1.1 - Graphs and Lines The first chapter of this text is a review of College Algebra skills that you will need as you move through the course. This is a review, so you should have some familiarity

More information

Polynomial and Rational Functions. Copyright Cengage Learning. All rights reserved.

Polynomial and Rational Functions. Copyright Cengage Learning. All rights reserved. 2 Polynomial and Rational Functions Copyright Cengage Learning. All rights reserved. 2.1 Quadratic Functions Copyright Cengage Learning. All rights reserved. What You Should Learn Analyze graphs of quadratic

More information

CSC Advanced Scientific Computing, Fall Numpy

CSC Advanced Scientific Computing, Fall Numpy CSC 223 - Advanced Scientific Computing, Fall 2017 Numpy Numpy Numpy (Numerical Python) provides an interface, called an array, to operate on dense data buffers. Numpy arrays are at the core of most Python

More information

The Python interpreter

The Python interpreter The Python interpreter Daniel Winklehner, Remi Lehe US Particle Accelerator School (USPAS) Summer Session Self-Consistent Simulations of Beam and Plasma Systems S. M. Lund, J.-L. Vay, D. Bruhwiler, R.

More information

Experiment 1 CH Fall 2004 INTRODUCTION TO SPREADSHEETS

Experiment 1 CH Fall 2004 INTRODUCTION TO SPREADSHEETS Experiment 1 CH 222 - Fall 2004 INTRODUCTION TO SPREADSHEETS Introduction Spreadsheets are valuable tools utilized in a variety of fields. They can be used for tasks as simple as adding or subtracting

More information

Computational Optimization Homework 3

Computational Optimization Homework 3 Computational Optimization Homework 3 Nedialko B. Dimitrov By completing this homework assignment you will learn about: Organizing code by creating your own objects. Vectorizing complex operations, and

More information

L15. 1 Lecture 15: Data Visualization. July 10, Overview and Objectives. 1.2 Part 1: Introduction to matplotlib

L15. 1 Lecture 15: Data Visualization. July 10, Overview and Objectives. 1.2 Part 1: Introduction to matplotlib L15 July 10, 2017 1 Lecture 15: Data Visualization CSCI 1360E: Foundations for Informatics and Analytics 1.1 Overview and Objectives Data visualization is one of, if not the, most important method of communicating

More information

LECTURE 19. Numerical and Scientific Packages

LECTURE 19. Numerical and Scientific Packages LECTURE 19 Numerical and Scientific Packages NUMERICAL AND SCIENTIFIC APPLICATIONS As you might expect, there are a number of third-party packages available for numerical and scientific computing that

More information

Exercise 4. AMTH/CPSC 445a/545a - Fall Semester October 30, 2017

Exercise 4. AMTH/CPSC 445a/545a - Fall Semester October 30, 2017 Exercise 4 AMTH/CPSC 445a/545a - Fall Semester 2016 October 30, 2017 Problem 1 Compress your solutions into a single zip file titled assignment4.zip, e.g. for a student named Tom

More information

Introduction to Scientific Computing with Matlab

Introduction to Scientific Computing with Matlab Introduction to Scientific Computing with Matlab In the previous reading, we discussed the basics of vectors and matrices, including matrix addition and multiplication. In this class, we ll explore more

More information

Math 182. Assignment #4: Least Squares

Math 182. Assignment #4: Least Squares Introduction Math 182 Assignment #4: Least Squares In any investigation that involves data collection and analysis, it is often the goal to create a mathematical function that fits the data. That is, a

More information

[CALCULATOR OPERATIONS]

[CALCULATOR OPERATIONS] Example 1: Set up a table of values (with x-values between 3 and 3) and use it to draw the graph of 3. Press MENU 2: VIEW A: SHOW TABLE 1. Select the GRAPHS option: Or Press MENU 5: TRACE 1: GRAPH TRACE

More information

Derek Bridge School of Computer Science and Information Technology University College Cork

Derek Bridge School of Computer Science and Information Technology University College Cork CS468: Artificial Intelligence I Ordinary Least Squares Regression Derek Bridge School of Computer Science and Information Technology University College Cork Initialization In [4]: %load_ext autoreload

More information

Introduction to Python and NumPy I

Introduction to Python and NumPy I Introduction to Python and NumPy I This tutorial is continued in part two: Introduction to Python and NumPy II Table of contents Overview Launching Canopy Getting started in Python Getting help Python

More information

1 Introduction. 2 Useful linear algebra (reprise) Introduction to MATLAB Reading. Spencer and Ware (2008), secs. 1-7, 9-9.3,

1 Introduction. 2 Useful linear algebra (reprise) Introduction to MATLAB Reading. Spencer and Ware (2008), secs. 1-7, 9-9.3, Introduction to MATLAB Reading Spencer and Ware (2008), secs. 1-7, 9-9.3, 12-12.4. For reference: matlab online help desk 1 Introduction MATLAB is commercial software that provides a computing environment

More information