Skills Quiz - Python Edition Solutions

Size: px
Start display at page:

Download "Skills Quiz - Python Edition Solutions"

Transcription

1 '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 Standard, I have neither provided nor received any assistance on this test. I understand if it is later determined that I gave or received assistance, I will be brought before the Undergraduate Conduct Board and, if found responsible for academic dishonesty or academic contempt, fail the class. I also understand that I am not allowed to speak to anyone except the instructor about any aspect of this test until the instructor announces it is allowed. I understand if it is later determined that I did speak to another person about the test before the instructor said it was allowed, I will be brought before the Undergraduate Conduct Board and, if found responsible for academic dishonesty or academic contempt, fail the class. Signature: Notes You will be turning in each problem in a separate pile. Most of these problems will require working on additional pieces of paper - Make sure that you do not put work for more than any one problem on any one piece of paper. For this test, you will be turning in four different sets of work. Again, Please do not work on multiple problems on the same sheet of paper. Also - please do not put work for one problem on the back of another problem. Be sure your name and NetID show up on every page of the test. If you are including work on extra sheets of paper, put your name and NetID on each and be sure to staple them to the appropriate problem. Problems without names will incur at least a 25% penalty for the problem. Work must be down in dark ink and on only one side of the page. This first page should have your name, NetID, and signature on it. It should be stapled on top of and turned in with your submission for Problem I. Every other pile should have your test page on top followed by any previously blank paper used for that problem. You will not need and can not use a calculator on this test. You will be asked to write several lines of code on this test. Make sure what you write is Python code and not mathematics. Be very careful with any symbols you use and carefully indent lines! You do not need to put the honor code statement in your codes. The honor code statement on this page and your NetID on each problem stands in for that. You may assume that the following have been run for any code you write: import math as m import numpy as np import matplotlib. pyplot as plt If you specifically want to import things in a different way, you need to show that explicitly on each code.

2 Name (please print): Community Standard (print NetID): Problem I: [30 pts.] The Basics - NOT IN PYTHON YET!!! See CS 101 tests, specifically first problems, for similar code.

3 Name (please print): Community Standard (print NetID): Problem II: [24 pts.] Smart Home A home automation system collects temperature and humidity information every ten minutes and saves the readings each day to a text file. The file from yesterday is called Data dat and has five columns of information: the reading number, the hour the reading was taken (between 0 and 23), the minute of the hour the reading was taken (between 0 and 50), the temperature in Fahrenheit (the sensor can read between 40 and 110 degrees) and the relative humidity (reported as a percentage between 0 and 100). The start and end of the data table might resemble: e e e e e e+01 <etc> e e e e e e+01 but there are actually a total of 144 lines. (1) Load the data set into an array called home_info. (2) Copy the reading hours into an array called hours. (3) Copy the reading minutes into an array called minutes. (4) Copy the temperatures into an array called temps. (5) Copy the humidity readings into an array called hum. (6) Make a plot of the temperatures at the top of each hour (that is, when the minute value is 0) as a function of the hour using blue circles at each reading. The circles should not be connected to each other. Add a proper title, axis labels, and grid. Save this plot to a color Encapsulated Postscript file called temp_plot.eps. (7) Determine the lowest, average, and highest values of the temperatures and the lowest, average, and highest values of the humidity and print them out as follows: Measurement Low Average High Temperature: 6.23e e e+01 Humidity: 5.02e e e+01 where the represents a space. In your code for this part, you should use or spaces. or some other symbol to clearly indicate

4 1 # %% Imports (not required in solution) 2 import numpy as np 3 import matplotlib.pyplot as plt 4 5 # %% (1) 6 home_info = np.loadtxt( ³Data dat ³) 7 8 # %% (2) - (5) 9 hours = home_info[:, 1].copy() 10 minutes = home_info[:, 2].copy() 11 temps = home_info[:, 3].copy() 12 hum = home_info[:, 4].copy() # %% (6) 15 plt.plot(hours[0::6], temps[0::6], ³bo ³) 16 plt.title( ³Temperature vs. Time ³) 17 plt.xlabel( ³Time, Hr ³) 18 plt.ylabel( ³Temp, ^o F ³) 19 plt.grid(1) 20 plt.savefig( ³temp_plot.eps ³) # %% (7) 23 print( ³Measurement Low Average High ³) 24 print( ³Temperature:_{:8.2e}_{:9.2e}_{:9.2e} ³.format( 25 np.min(temps), np.mean(temps), np.max(temps))) 26 print( ³ Humidity:_{:8.2e}_{:9.2e}_{:9.2e} ³.format( 27 np.min(hum), np.mean(hum), np.max(hum))) # Note: if spaces are included correctly, {:0.2e} through {:8.2e} 30 # or {:10.2e} could also work

5 Name (please print): Community Standard (print NetID): Problem III: [22 pts.] Plots (1) Write a script that will first ask the user for an integer N between 10 and 100; you may assume the user correctly enters a value. Create an N x1 matrix of uniformly distributed random numbers between 0 and 500 and call it rand_vals. Then have your code generate a plot of your random numbers using green diamonds not connected by lines. This plot does not need axis labels but should have a grid and be titled Random Numbers. Save the plot to a color Encapsulated Postscript file called rand_plot.eps. Then save the rand_vals data to a text file named rand_data.dat. (2) Write a script that will define a function called cossin that will take three arguments - two single frequencies and a matrix of times. The output should be defined as: cossin(ω 1,ω 2,t) = cos(ω 1 t) sin(ω 2 t) where denotes multiplication and the ω values are given in rad/s. Then use this function to make a single plot showing three different frequency combinations over a domain of 50 times between 0 to 2π. The frequencies and line styles should be: ω 1 ω 2 Style 1 2 Blue dashed line with blue circles at the points 1 3 Red dotted line with red squares at the points 2 3 Purple solid line with black pluses at the points You do not need a title, a grid, axis labels, or a title, nor do you need to save this figure. (3) Assuming your cossin function from above is working, and that you have already created a linearly spaced array of 50 times between 0 and 2π, write the additional code you would need to generate a figure with six different plots (all using black points connected by a solid black line) with the following frequency combinations: ω 1 = 1,ω 2 = 1 ω 1 = 1,ω 2 = 3 ω 1 = 1,ω 2 = 5 ω 1 = 2,ω 2 = 1 ω 1 = 2,ω 2 = 3 ω 1 = 2,ω 2 = 5 You do not need titles, grids, axis labels, or titles, nor do you need to save this figure.

6 1 # %% Imports 2 import numpy as np 3 import matplotlib.pyplot as plt 4 5 # %% (1) 6 N = int(input( ³Integer between 10 and 100: ³)) 7 rand_vals = np.random.uniform(0, 500, size=n) 8 9 plt.figure(1) 10 plt.clf() 11 plt.plot(rand_vals, ³gd ³) 12 plt.grid(1) 13 plt.title( ³Random Numbers ³) 14 plt.savefig( ³rand_plot.eps ³) np.savetxt( ³rand_data.dat ³, rand_vals) 1 #%% Imports 2 import numpy as np 3 import matplotlib.pyplot as plt 4 5 #%% (2) 6 def cossin(w1, w2, t): 7 return np.cos(w1*t)*np.sin(w2*t) 8 9 plt.figure(1) 10 plt.clf() 11 tvals = np.linspace(0, 2*np.pi, 50) plt.plot(tvals, cossin(1, 2, tvals), ³b--o ³) 14 plt.plot(tvals, cossin(1, 3, tvals), ³r:s ³) 15 plt.plot(tvals, cossin(2, 3, tvals), ³m-+ ³, markeredgecolor= ³k ³) #%% (3) 18 plt.figure(2) 19 plt.clf() 20 plt.subplot(2, 3, 1) 21 plt.plot(tvals, cossin(1, 1, tvals), ³k.- ³) # k-. incorrect 22 plt.subplot(2, 3, 2) 23 plt.plot(tvals, cossin(1, 3, tvals), ³k.- ³) 24 plt.subplot(2, 3, 3) 25 plt.plot(tvals, cossin(1, 5, tvals), ³k.- ³) 26 plt.subplot(2, 3, 4) 27 plt.plot(tvals, cossin(2, 1, tvals), ³k.- ³) 28 plt.subplot(2, 3, 5) 29 plt.plot(tvals, cossin(2, 3, tvals), ³k.- ³) 30 plt.subplot(2, 3, 6) 31 plt.plot(tvals, cossin(2, 5, tvals), ³k.- ³) #%% (3) in a loop 34 plt.figure(2) 35 plt.clf() 36 for row in range(2): 37 for col in range(3): 38 plt.subplot(2, 3, 3*row+col+1) 39 plt.plot(tvals, 40 cossin(row+1, 2*col+1, tvals), ³k.- ³) 41 42

7 43 #%% (3) future way: 44 fig, ax = plt.subplots(2, 3, num=2) 45 for row in range(2): 46 for col in range(3): 47 ax[row][col].plot(tvals, 48 cossin(row+1, 2*col+1, tvals), ³k.- ³)

8 Name (please print): Community Standard (print NetID): Problem IV: [24 pts.] Roy G. Functions The wavelength ranges for yellow, orange, and red light are (from Wikipedia): Color Minimum Wavelength (nm) Maximum Wavelength (nm) yellow orange red (1) Write a function called wavelength that takes two inputs: the first (required) is a string while the second is an integer with a default value of 2. The function will have either one or two outputs depending on the value of the second input. In situations where the function is called with a 1 as the second input, the function should return the average wavelength (in nm) in the range for that color. In situations where the function is called with a 2 as the second input, the function should return two values in a tuple - the minimum wavelength and the maximum wavelength, both in nm. You may assume the user properly gives you a string, but if that string is not one of the three colors above, your function should raise a ValueError that says Unknown color. Here are some example runs: In [1]: wavelength(³yellow ³, 1) Out[1]: In [2]: wavelength(³yellow ³) Out[2]: (560, 590) In [3]: (LowL, HighL) = wavelength(³red ³, 2) In [3]: print(lowl, HighL) In [4]: wavelength(³blue ³) ( system messages) ValueError: Unknown color. (2) Write a function called rainbow.m that will take at least one input argument and returns one output. The first input will be a number representing a wavelength and the second, optional argument will be a value of 0 or 1 which will determine whether the function should print a line of information. Your function must validate the first input argument. If the user gives no input arguments, Python itself will give an error, rainbow() missing 1 required positional argument. If the user gives a first argument that is anything other than an int or a float the program should raise a ValueError: Single numerical value required. And if the user gives a first value that is outside the (inclusive) range of 560 to 700, the program should give an error, Unknown color. The second, optional argument is a print flag - if there is no second argument, the flag should be set to zero. You may assume if the user gives you a second argument they have done so correctly. Assuming the user gives a single appropriate value in the first argument, the program should return a string with the color name as given in the table above. Note: for 590 and 635, you can pick which color to call that. If the user has also given 1 as a second argument, the function should print a line stating the wavelength (as a float displaying the tenths digit) and the color. Here are some examples: In [1]: rainbow(630) Out[1]: ³orange ³ In [2]: rainbow(620, 1) Wavelength denotes orange. Out[2]: ³orange ³ In [3]: rainbow([600, 650]) ( system messages) ValueError: Single numerical value required In [4]: rainbow(1000) ( system messages) ValueError: Unknown color

9 1 def wavelength(color, outs=2): 2 if color == ³yellow ³: 3 minl = maxl = elif color == ³orange ³: 6 minl = maxl = elif color == ³red ³: 9 minl = maxl = else: 12 raise ValueError( ³Unknown color. ³) if outs == 2: 15 return minl, maxl 16 else: 17 return (minl + maxl) / 2 1 def rainbow(wl, p=0): 2 if not isinstance(wl, (int, float)): 3 raise ValueError( ³ Single numerical value required. ³) 4 elif wl<500 or wl>700: 5 raise ValueError( ³ Unknown color ³) 6 7 if wl<590: 8 col_name = ³yellow ³ 9 elif wl<635: 10 col_name = ³orange ³ 11 else: 12 col_name = ³red ³ if p==1: 15 print( ³Wavelength {:0.1f} denotes {:s}. ³.format(wl, col_name)) return col_ name

Skills Quiz - Python Edition Solutions

Skills Quiz - Python Edition Solutions 'XNH8QLYHUVLW\ (GPXQG73UDWW-U6FKRRORI(QJLQHHULQJ EGR 103L Fall 2016 Skills Quiz - Python Edition Solutions Rebecca A. Simmons and & Michael R. Gustafson II Name (please print): NetID (please print): In

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

'XNH8QLYHUVLW\ (GPXQG73UDWW-U6FKRRORI(QJLQHHULQJ. EGR 103L Fall Skills Quiz. Rebecca A. Simmons and & Michael R.

'XNH8QLYHUVLW\ (GPXQG73UDWW-U6FKRRORI(QJLQHHULQJ. EGR 103L Fall Skills Quiz. Rebecca A. Simmons and & Michael R. 'XNH8QLYHUVLW\ (GPXQG73UDWW-U6FKRRORI(QJLQHHULQJ EGR 103L Fall 2014 Skills Quiz Rebecca A. Simmons and & Michael R. Gustafson II NET ID (please print): In keeping with the Community Standard, I have neither

More information

Test 2 - Python Edition

Test 2 - Python Edition 'XNH8QLYHUVLW\ (GPXQG73UDWW-U6FKRRORI(QJLQHHULQJ EGR 13L Spring 218 Test 2 - Python Edition Shaundra B. Daily & Michael R. Gustafson II Name (please print): NetID (please print): In keeping with the Community

More information

'XNH8QLYHUVLW\ (GPXQG73UDWW-U6FKRRORI(QJLQHHULQJ. EGR 53L Fall Test I. Rebecca A. Simmons & W. Neal Simmons Michael R.

'XNH8QLYHUVLW\ (GPXQG73UDWW-U6FKRRORI(QJLQHHULQJ. EGR 53L Fall Test I. Rebecca A. Simmons & W. Neal Simmons Michael R. 'XNH8QLYHUVLW\ (GPXQG73UDWW-U6FKRRORI(QJLQHHULQJ EGR 53L Fall 2007 Test I Rebecca A. Simmons & W. Neal Simmons Michael R. Gustafson II Name (please print) In keeping with the Community Standard, I have

More information

'XNH8QLYHUVLW\ (GPXQG73UDWW-U6FKRRORI(QJLQHHULQJ. EGR 53L Fall Test I. Rebecca A. Simmons & Michael R. Gustafson II

'XNH8QLYHUVLW\ (GPXQG73UDWW-U6FKRRORI(QJLQHHULQJ. EGR 53L Fall Test I. Rebecca A. Simmons & Michael R. Gustafson II 'XNH8QLYHUVLW\ (GPXQG73UDWW-U6FKRRORI(QJLQHHULQJ EGR 53L Fall 2009 Test I Rebecca A. Simmons & Michael R. Gustafson II Name and NET ID (please print) In keeping with the Community Standard, I have neither

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

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

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

CS 111X - Fall Test 1

CS 111X - Fall Test 1 CS 111X - Fall 2016 - Test 1 1/9 Computing ID: CS 111X - Fall 2016 - Test 1 Name: Computing ID: On my honor as a student, I have neither given nor received unauthorized assistance on this exam. Signature:

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

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

: Intro Programming for Scientists and Engineers Final Exam

: Intro Programming for Scientists and Engineers Final Exam Final Exam Page 1 of 6 600.112: Intro Programming for Scientists and Engineers Final Exam Peter H. Fröhlich phf@cs.jhu.edu December 20, 2012 Time: 40 Minutes Start here: Please fill in the following important

More information

MATPLOTLIB. Python for computational science November 2012 CINECA.

MATPLOTLIB. Python for computational science November 2012 CINECA. MATPLOTLIB Python for computational science 19 21 November 2012 CINECA m.cestari@cineca.it Introduction (1) plotting the data gives us visual feedback in the working process Typical workflow: write a python

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

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

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

HW0 v3. October 2, CSE 252A Computer Vision I Fall Assignment 0

HW0 v3. October 2, CSE 252A Computer Vision I Fall Assignment 0 HW0 v3 October 2, 2018 1 CSE 252A Computer Vision I Fall 2018 - Assignment 0 1.0.1 Instructor: David Kriegman 1.0.2 Assignment Published On: Tuesday, October 2, 2018 1.0.3 Due On: Tuesday, October 9, 2018

More information

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY

CS 111X - Fall Test 1 - KEY KEY KEY KEY KEY KEY KEY CS 111X - Fall 2016 - Test 1 1/9 Computing ID: CS 111X - Fall 2016 - Test 1 - KEY KEY KEY KEY KEY KEY KEY Name: Computing ID: On my honor as a student, I have neither given nor received unauthorized assistance

More information

CS150 Sample Final Solution

CS150 Sample Final Solution CS150 Sample Final Solution Name: Section: A / B Date: Start time: End time: Honor Code: Signature: This exam is closed book, closed notes, closed computer, closed calculator, etc. You may only use (1)

More information

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points) EECS 183 Fall 2013 Exam 1 Part 1 (80 points) Closed Book Closed Notes Closed Electronic Devices Closed Neighbor Turn off Your Cell Phones We will confiscate all electronic devices that we see including

More information

CS150 Sample Final. Name: Section: A / B

CS150 Sample Final. Name: Section: A / B CS150 Sample Final Name: Section: A / B Date: Start time: End time: Honor Code: Signature: This exam is closed book, closed notes, closed computer, closed calculator, etc. You may only use (1) the final

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

Session 1 Use test driven development (i.e. write the tests first) to design functions to give the square, cube and an arbitary power N for a number a. In [1]: import unittest def square(a): return a**2

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

Partial Differential Equations II: 2D Laplace Equation on 5x5 grid

Partial Differential Equations II: 2D Laplace Equation on 5x5 grid Partial Differential Equations II: 2D Laplace Equation on 5x5 grid Sam Sinayoko Numerical Methods 5 Contents 1 Learning Outcomes 2 2 Introduction 3 3 Laplace equation in 2D 3 4 Discretisation 3 4.1 Meshing:

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

CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, Good Luck!

CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, Good Luck! CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, 2011 Name: EID: Section Number: Friday discussion time (circle one): 9-10 10-11 11-12 12-1 2-3 Friday discussion TA(circle one): Wei Ashley Answer

More information

CS 111: Digital Image Processing Fall 2016 Midterm Exam: Nov 23, Pledge: I neither received nor gave any help from or to anyone in this exam.

CS 111: Digital Image Processing Fall 2016 Midterm Exam: Nov 23, Pledge: I neither received nor gave any help from or to anyone in this exam. CS 111: Digital Image Processing Fall 2016 Midterm Exam: Nov 23, 2016 Time: 3:30pm-4:50pm Total Points: 80 points Name: Number: Pledge: I neither received nor gave any help from or to anyone in this exam.

More information

Math-2. Lesson 3-1. Equations of Lines

Math-2. Lesson 3-1. Equations of Lines Math-2 Lesson 3-1 Equations of Lines How can an equation make a line? y = x + 1 x -4-3 -2-1 0 1 2 3 Fill in the rest of the table rule x + 1 f(x) -4 + 1-3 -3 + 1-2 -2 + 1-1 -1 + 1 0 0 + 1 1 1 + 1 2 2 +

More information

Chapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1

Chapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1 Chapter 2 (Part 2) MATLAB Basics dr.dcd.h CS 101 /SJC 5th Edition 1 Display Format In the command window, integers are always displayed as integers Characters are always displayed as strings Other values

More information

Programming with Python

Programming with Python Programming with Python EOAS Software Carpentry Workshop September 21st, 2016 https://xkcd.com/353 Getting started For our Python introduction we re going to pretend to be a researcher studying inflammation

More information

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No.

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Instructor: Final Exam Fall Section No. The American University in Cairo Computer Science & Engineering Department CSCE 106 Instructor: Final Exam Fall 2010 Last Name :... ID:... First Name:... Section No.: EXAMINATION INSTRUCTIONS * Do not

More information

CMPSCI 119 Fall 2018 Wednesday, November 14, 2018 Midterm #2 Solution Key Professor William T. Verts

CMPSCI 119 Fall 2018 Wednesday, November 14, 2018 Midterm #2 Solution Key Professor William T. Verts CMPSCI 119 Fall 2018 Wednesday, November 14, 2018 Midterm #2 Solution Key Professor William T. Verts 25 Points What is the value of each expression below? Answer any 25; answer more for extra credit.

More information

The SciPy Stack. Jay Summet

The SciPy Stack. Jay Summet The SciPy Stack Jay Summet May 1, 2014 Outline Numpy - Arrays, Linear Algebra, Vector Ops MatPlotLib - Data Plotting SciPy - Optimization, Scientific functions TITLE OF PRESENTATION 2 What is Numpy? 3rd

More information

Topological Invariants with Z2Pack. Topological Matter School 2016, Donostia

Topological Invariants with Z2Pack. Topological Matter School 2016, Donostia Topological Invariants with Z2Pack Topological Matter School 2016, Donostia Part 1: A Short Introduction to Python Why Python? Title text: I wrote 20 short programs in Python yesterday. It was wonderful.

More information

Bi 1x Spring 2014: Plotting and linear regression

Bi 1x Spring 2014: Plotting and linear regression 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.

More information

CS 1301 Exam 2 Fall 2010

CS 1301 Exam 2 Fall 2010 CS 1301 Exam 2 Fall 2010 Name : Grading TA: Devices: If your cell phone, pager, PDA, beeper, ipod, or similar item goes off during the exam, you will lose 10 points on this exam. Turn all such devices

More information

1. Register an account on: using your Oxford address

1. Register an account on:   using your Oxford  address 1P10a MATLAB 1.1 Introduction MATLAB stands for Matrix Laboratories. It is a tool that provides a graphical interface for numerical and symbolic computation along with a number of data analysis, simulation

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

Python review. 1 Python basics. References. CS 234 Naomi Nishimura

Python review. 1 Python basics. References. CS 234 Naomi Nishimura Python review CS 234 Naomi Nishimura The sections below indicate Python material, the degree to which it will be used in the course, and various resources you can use to review the material. You are not

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

LAB 2: DATA FILTERING AND NOISE REDUCTION

LAB 2: DATA FILTERING AND NOISE REDUCTION NAME: LAB SECTION: LAB 2: DATA FILTERING AND NOISE REDUCTION In this exercise, you will use Microsoft Excel to generate several synthetic data sets based on a simplified model of daily high temperatures

More information

Math 1MP3, final exam

Math 1MP3, final exam Math 1MP3, final exam 23 April 2015 Please write your name and student number on this test and on your answer sheet You have 120 minutes No external aids (calculator, textbook, notes) Please number your

More information

CS 1301 Exam 1 Fall 2010

CS 1301 Exam 1 Fall 2010 CS 1301 Exam 1 Fall 2010 Name : Grading TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking of this exam in

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

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

Introduction to Scientific Computing with Python, part two.

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

More information

LAB 2: DATA FILTERING AND NOISE REDUCTION

LAB 2: DATA FILTERING AND NOISE REDUCTION NAME: LAB TIME: LAB 2: DATA FILTERING AND NOISE REDUCTION In this exercise, you will use Microsoft Excel to generate several synthetic data sets based on a simplified model of daily high temperatures in

More information

Week Two. Arrays, packages, and writing programs

Week Two. Arrays, packages, and writing programs Week Two Arrays, packages, and writing programs Review UNIX is the OS/environment in which we work We store files in directories, and we can use commands in the terminal to navigate around, make and delete

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

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

UNIVERSITETET I OSLO

UNIVERSITETET I OSLO UNIVERSITETET I OSLO Det matematisk-naturvitenskapelige fakultet Examination in: IN1900 Introduction to programming with scientific applications Day of examination: Tuesday, October 10, 2017 Examination

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

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

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

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

Question 1. Part (a) Simple Syntax [1 mark] Circle add_ints(), because it is missing arguments to the function call. Part (b) Simple Syntax [1 mark]

Question 1. Part (a) Simple Syntax [1 mark] Circle add_ints(), because it is missing arguments to the function call. Part (b) Simple Syntax [1 mark] Note to Students: This file contains sample solutions to the term test together with the marking scheme and comments for each question. Please read the solutions and the marking schemes and comments carefully.

More information

Chapter 3: Introduction to MATLAB Programming (4 th ed.)

Chapter 3: Introduction to MATLAB Programming (4 th ed.) Chapter 3: Introduction to MATLAB Programming (4 th ed.) Algorithms MATLAB scripts Input / Output o disp versus fprintf Graphs Read and write variables (.mat files) User-defined Functions o Definition

More information

egrapher Language Reference Manual

egrapher Language Reference Manual egrapher Language Reference Manual Long Long: ll3078@columbia.edu Xinli Jia: xj2191@columbia.edu Jiefu Ying: jy2799@columbia.edu Linnan Wang: lw2645@columbia.edu Darren Chen: dsc2155@columbia.edu 1. Introduction

More information

lof April 23, Improving performance of Local outlier factor with KD-Trees

lof April 23, Improving performance of Local outlier factor with KD-Trees lof April 23, 2014 1 Improving performance of Local outlier factor with KD-Trees Local outlier factor (LOF) is an outlier detection algorithm, that detects outliers based on comparing local density of

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

Lab 1 - Basic ipython Tutorial (EE 126 Fall 2014)

Lab 1 - Basic ipython Tutorial (EE 126 Fall 2014) Lab 1 - Basic ipython Tutorial (EE 126 Fall 2014) modified from Berkeley Python Bootcamp 2013 https://github.com/profjsb/python-bootcamp and Python for Signal Processing http://link.springer.com/book/10.1007%2f978-3-319-01342-8

More information

Search. The Nearest Neighbor Problem

Search. The Nearest Neighbor Problem 3 Nearest Neighbor Search Lab Objective: The nearest neighbor problem is an optimization problem that arises in applications such as computer vision, pattern recognition, internet marketing, and data compression.

More information

PS6-DCT-Soln-correction

PS6-DCT-Soln-correction PS6-DCT-Soln-correction Unknown Author March 18, 2014 Part I DCT: Discrete Cosine Transform DCT is a linear map A R N N such that the N real numbers x 0,..., x N 1 are transformed into the N real numbers

More information

Homework 11 - Debugging

Homework 11 - Debugging 1 of 7 5/28/2018, 1:21 PM Homework 11 - Debugging Instructions: Fix the errors in the following problems. Some of the problems are with the code syntax, causing an error message. Other errors are logical

More information

CS 1110 Prelim 1 March 10, 2015

CS 1110 Prelim 1 March 10, 2015 CS 1110 Prelim 1 March 10, 2015 (Print Last Name) (Print First Name) (Net ID) Circle Your Lab: ACCEL: Tue 12:20 Tue 1:25 Tue 2:30 Tue 3:35 ACCEL : Wed 10:10 Wed 11:15 Wed 12:20 Wed 1:25 Wed 2:30 Wed 3:35

More information

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Dr. Khalil Exam II Fall 2011

Total 100. The American University in Cairo Computer Science & Engineering Department CSCE 106. Dr. Khalil Exam II Fall 2011 The American University in Cairo Computer Science & Engineering Department CSCE 106 Dr. Khalil Exam II Fall 2011 Last Name :... ID:... First Name:... Form I Section No.: ( ) EXAMINATION INSTRUCTIONS *

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

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

Test 2 Version A. On my honor, I have neither given nor received inappropriate or unauthorized information at any time before or during this test.

Test 2 Version A. On my honor, I have neither given nor received inappropriate or unauthorized information at any time before or during this test. Student s Printed Name: Instructor: CUID: Section: Instructions: You are not permitted to use a calculator on any portion of this test. You are not allowed to use any textbook, notes, cell phone, laptop,

More information

MATLAB SUMMARY FOR MATH2070/2970

MATLAB SUMMARY FOR MATH2070/2970 MATLAB SUMMARY FOR MATH2070/2970 DUNCAN SUTHERLAND 1. Introduction The following is inted as a guide containing all relevant Matlab commands and concepts for MATH2070 and 2970. All code fragments should

More information

Types, lists & functions

Types, lists & functions Week 2 Types, lists & functions Data types If you want to write a program that allows the user to input something, you can use the command input: name = input (" What is your name? ") print (" Hello "+

More information

15-780: Problem Set #2

15-780: Problem Set #2 15-780: Problem Set #2 February 19, 2014 1. Constraint satisfaction problem (CSP) [20pts] A common problem at universities is to schedule rooms for exams. The basic structure of this problem is to divide

More information

Spring 2017 CS 1110/1111 Exam 1

Spring 2017 CS 1110/1111 Exam 1 CS 1110/1111 Spring 2017 Exam 1 page 1 of 6 Spring 2017 CS 1110/1111 Exam 1 Bubble in your computing ID in the footer of this page. We use an optical scanner to read it, so fill in the bubbles darkly.

More information

Matplotlib Python Plotting

Matplotlib Python Plotting Matplotlib Python Plotting 1 / 6 2 / 6 3 / 6 Matplotlib Python Plotting Matplotlib is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive

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

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

MATLAB Introduction to MATLAB Programming

MATLAB Introduction to MATLAB Programming MATLAB Introduction to MATLAB Programming MATLAB Scripts So far we have typed all the commands in the Command Window which were executed when we hit Enter. Although every MATLAB command can be executed

More information

CS 1301 Post Exam 3 Practice Spring 2016

CS 1301 Post Exam 3 Practice Spring 2016 CS 1301 Post Exam 3 Practice Spring 2016 Name : Grading TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking

More information

Neatly print first and last names: Exam II. "On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work.

Neatly print first and last names: Exam II. On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work. Fry Texas A&M University! Math 150 Precalculus Fall 2015! 1 Neatly print first and last names: Lecture Time:!! 12:45 PM!!! 2:20 PM!! (Circle one.) Exam II "On my honor, as an Aggie, I have neither given

More information

All written answers are limited to their question boxes. Make sure all answers are easily legible.

All written answers are limited to their question boxes. Make sure all answers are easily legible. All written answers are limited to their question boxes. Make sure all answers are easily legible. 1. (1 point) Print your name and email id. 2. (2 points) What makes functions so important? Ability to

More information

Page 1 of 7 E7 Spring 2009 Midterm I SID: UNIVERSITY OF CALIFORNIA, BERKELEY Department of Civil and Environmental Engineering. Practice Midterm 01

Page 1 of 7 E7 Spring 2009 Midterm I SID: UNIVERSITY OF CALIFORNIA, BERKELEY Department of Civil and Environmental Engineering. Practice Midterm 01 Page 1 of E Spring Midterm I SID: UNIVERSITY OF CALIFORNIA, BERKELEY Practice Midterm 1 minutes pts Question Points Grade 1 4 3 6 4 16 6 1 Total Notes (a) Write your name and your SID on the top right

More information

CS 1301 Exam 1 Fall 2014

CS 1301 Exam 1 Fall 2014 CS 1301 Exam 1 Fall 2014 Name : Grading TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking of this exam in

More information

Episode 8 Matplotlib, SciPy, and Pandas. We will start with Matplotlib. The following code makes a sample plot.

Episode 8 Matplotlib, SciPy, and Pandas. We will start with Matplotlib. The following code makes a sample plot. Episode 8 Matplotlib, SciPy, and Pandas Now that we understand ndarrays, we can start using other packages that utilize them. In particular, we're going to look at Matplotlib, SciPy, and Pandas. Matplotlib

More information

Adapted to TKT4140 Numerical Methods

Adapted to TKT4140 Numerical Methods Adapted to TKT4140 Numerical Methods Hans Petter Langtangen Center for Biomedical Computing, Simula Research Laboratory & Department of Informatics, University of Oslo Leif Rune Hellevik 1,2 Biomechanichs

More information

This is a very quick intro to Python programming. Adapted to TKT4140 Numerical Methods. Mathematical example. A program for evaluating a formula

This is a very quick intro to Python programming. Adapted to TKT4140 Numerical Methods. Mathematical example. A program for evaluating a formula This is a very quick intro to Python programming Adapted to TKT4140 Numerical Methods Hans Petter Langtangen Center for Biomedical Computing, Simula Research Laboratory & Department of Informatics, University

More information

CS 1301 Exam 1 Fall 2010

CS 1301 Exam 1 Fall 2010 CS 1301 Exam 1 Fall 2010 Name : Grading TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking of this exam in

More information

Section 2 0: The Rectangular Coordinate System. The Coordinate System

Section 2 0: The Rectangular Coordinate System. The Coordinate System Section 2 : The Rectangular Coordinate System The rectangular coordinate system is based on two number lines. A horizontal line called the x axis and a vertical line called the y axis. Each axis has marks

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

(the bubble footer is automatically inserted into this space)

(the bubble footer is automatically inserted into this space) CS 1110 Exam 1, Fall 2018 Page 1 of 8 UVa userid: CS 1110 Exam 1 Name Bubble in your computing ID in the footer of this page. We use an optical scanner to read it, so fill in the bubbles darkly. If you

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

Sample Final Exam CSci 127: Introduction to Computer Science Hunter College, City University of New York

Sample Final Exam CSci 127: Introduction to Computer Science Hunter College, City University of New York Sample Final Exam CSci 127: Introduction to Computer Science Hunter College, City University of New York Fall 2017 Exam Rules Show all your work. Your grade will be based on the work shown. The exam is

More information

MAS212 Assignment #1 (2018): Rational approximations

MAS212 Assignment #1 (2018): Rational approximations MAS212 Assignment #1 (2018): Rational approximations Dr Sam Dolan (sdolan@sheffieldacuk) In this assignment you will use Python to find rational approximations to real numbers such as π, 2 and the golden

More information

Lab 6. COMP9021, Session 2, one solution is obtained by selecting 1 and both occurrences of 2 ( = 5);

Lab 6. COMP9021, Session 2, one solution is obtained by selecting 1 and both occurrences of 2 ( = 5); Lab 6 COMP9021, Session 2, 2016 1 R Obtaining a sum from a subsequence of digits Write a program sum_of_digits.py that prompts the user for two numbers, say available_digits and desired_sum, and outputs

More information

Intermediate/Advanced Python. Michael Weinstein (Day 2)

Intermediate/Advanced Python. Michael Weinstein (Day 2) Intermediate/Advanced Python Michael Weinstein (Day 2) Topics Review of basic data structures Accessing and working with objects in python Numpy How python actually stores data in memory Why numpy can

More information

CPSC 217 Midterm (Python 3 version)

CPSC 217 Midterm (Python 3 version) CPSC 217 Midterm (Python 3 version) Duration: 60 minutes 7 March 2011 This exam has 81 questions and 14 pages. This exam is closed book. No notes, books, calculators or electronic devices, or other assistance

More information

Circle inversion fractals are based on the geometric operation of inversion of a point with respect to a circle, shown schematically in Fig. 1.

Circle inversion fractals are based on the geometric operation of inversion of a point with respect to a circle, shown schematically in Fig. 1. MSE 350 Creating a Circle Inversion Fractal Instructor: R.G. Erdmann In this project, you will create a self-inverse fractal using an iterated function system (IFS). 1 Background: Circle Inversion Circle

More information

TMA4320 Tips for Python Coding

TMA4320 Tips for Python Coding TMA420 Tips for Python Coding Jonas Blomberg Ghini Mariusz Eivind Grøtte February 27, 2017 1 Introduction In this document I will try to write out some hints and ideas related to writing good code, about

More information

Fall 2017: Numerical Methods I Assignment 1 (due Sep. 21, 2017)

Fall 2017: Numerical Methods I Assignment 1 (due Sep. 21, 2017) MATH-GA 2010.001/CSCI-GA 2420.001, Georg Stadler (NYU Courant) Fall 2017: Numerical Methods I Assignment 1 (due Sep. 21, 2017) Objectives. This class is for you and you should try to get the most out of

More information