Microsoft Word - ENGR102_Python_Project_Fall20_v2.docx
Programming Project v2 – ENGR102 All Kurwitz Sections
Assigned: 10/20/20
Due Sunday 11/22/20 – 11:59 pm
Python Project
Introduction.
This project involves developing Python based code to solve problems of interest to engineers. The
purpose of this project is to assess the student’s ability to utilize programming in the solution to
engineering related problems. This is an individual assignment and, as such, each student is responsible
for their own work.
Project Overview
You are tasked with developing several programs/functions that will allow the instructional team to
evaluate your python program skills. Your code should follow the concepts developed in class and follow
the commenting and variable naming requirements emphasized throughout the semester. Your grade
will be based on the following criteria: (1) Producing the co
ect result 70%; and (2) Commenting and
variable naming (30%).
The project will require functions to be defined to ca
y out the following:
1. Handle Numeric Data
a. Load numeric data
. Plot the data
c. Interpolate
2. Evaluate Functions
a. Load and function from file
. Plot the function
c. Integrate the function
1. Task Description – Handle Numeric Data
For this task, the user will create functions that will load numeric data and perform simple operations
that we have gone over in class. The deliverable will include the function file and a set of test
problems/values and their co
esponding results.
Function 1.a – Load Numeric Data
You are tasked with creating a function to load numeric data. The data will be in column form where
each column is a variable and each row is an observation. Example files are provided but it is the users
esponsibility to generate new files for the deliverable. The data will utilize different delimiters for
separating the variables and contain two header rows where the first row is the variable name and the
second row is the units. Data will either be several variables with the first column co
esponding to the
independent variable and the remaining columns co
esponding to the dependent variables or will be
one column. The function will have the following properties:
• Name – the function name will be engr102_load_data
• Arguments – the function will take multiple arguments
o File name as a string
o Delimiter as a string
• Outputs – the function should return 3 things in a single return statement
Programming Project v2 – ENGR102 All Kurwitz Sections
Assigned: 10/20/20
Due Sunday 11/22/20 – 11:59 pm
o A string indicating whether there is one or several variables returned (either ‘one’ or
’multiple’)
o A single, one dimensional list of strings containing the variable name and the units i.e.
‘Mass (kg)’ returned
o A list of appropriate dimension containing all the numeric data (list of lists where each
sublist contains the numeri data for a variable)
• Deliverable
o The function will be part of a larger file called engr102_project_[last name] _[first
name]_[sec #].py – my submission would be engr102_project_kurwitz_cable_525.py.
Your file should contain a header as described in class.
o Test files – should include files of different number of variables and different delimiters
Function 1.b – Plot Numeric Data
You are tasked with creating a function to plot numeric data. The numeric data files of interest will
either be comma separated variables or tab separated. One can assume that comma separated variable
data uses the .csv suffix and tab separated data uses the .dat suffix. The data will consist of columns
co
esponding to different variables and rows co
esponding to observations. Each data file will have
two header rows that consist of a variable name (row1) and the appropriate units (row2). Sample data
are included as part of the project package but testing will utilize data files of similar format but varying
in size (rows and columns). Use the first column variable name and units as the x-axis label for either
plot.
For a single column a
ay, the function should produce, display, and save a figure that contains a
histogram plot. The variable name and units should be used as the x-axis label and the histogram should
use frequency as the y-axis. The mean and standard deviation should be written on the figure as a text
ox in the upper right corner of the plot area. The plot should be titled ‘ENGR102 Project 1.b Histogram’.
Save the file as a .png file with the same name as title.
For an a
ay with several variables, the first column co
esponds to the independent variable and the
emaining columns co
esponding to the dependent variables. The plot should use markers (not lines) of
different colors co
esponding to each dependent variable. A legend should be included that lists the
variable names. The y-axis should be labeled ‘dependent variables’. The plot should utilize gridlines and
e titled ‘ENGR102 Project 1.b Plot’. Save the file as a .png file with the same name as title.
The function will have the following properties:
• Name – the function name will be engr102_plot_data
• Arguments – the function will take multiple arguments
o A list co
esponding to variable names and units as strings
o A two-dimensional list of numeric floats
• Outputs
o A histogram or scatter plot displayed to screen and saved as a .png file
• Deliverable
o The function will be part of a larger file called engr102_project_[last name] _[first
name]_[sec #].py – my submission would be engr102_project_kurwitz_cable_525.py.
Your file should contain a header as described in class.
Programming Project v2 – ENGR102 All Kurwitz Sections
Assigned: 10/20/20
Due Sunday 11/22/20 – 11:59 pm
o Test files – sample plots based on test files used in 1.a
Function 1.c – Interpolate Numeric Data
You are tasked with creating a function to linearly interpolate numeric data. The data will be in the form
of a two-dimensional list where each column is a variable and each row is an observation. You can
assume that the first column is the independent variable and the user will have to select based on a
menu prompt on which column to use as the dependent variable. The user should then be prompted to
enter a new query for the independent variable and the function should return the resulting value
co
esponding to the dependent variable. The function will have to identify known points closest to the
query value and use those as the known interpolation points by fitting a line between closest points. If
the data has only one column, a warning should be displayed to the screen and nothing returned from
the function (does not throw an e
or).
The function will have the following properties:
• Name – the function name will be engr102_interpolate_data
• Arguments – the function will take multiple arguments
o A list co
esponding to variable names and units as strings
o A two-dimensional list of numeric floats
• Inputs – The user will be prompted for these – do not use them as input arguments
o A selection from a menu displayed of possible independent variables
o A query value for the independent variable
• Outputs
o Returns The resulting dependent variable value co
esponding to the input query
eturned as a float
• Deliverable
o The function will be part of a larger file called engr102_project_[last name] _[first
name]_[sec #].py – my submission would be engr102_project_kurwitz_cable_525.py.
Your file should contain a header as described in class.
o Test file and a test query with the resulting value returned
2. Task Description – Evaluate Functions
For this task, the user will create functions that will load functions as strings from a text file and perform
simple operations of interest to engineering. The deliverable will include the function file and a set of
test problems/values and their co
esponding results.
Function 2.a – Load Equation
You are tasked with creating a function to load an equation in python syntax similar to the one below
from a file:
3*(x**2) - 2*x + 1/2
A file of equations will be provided as part of the project files where each line co
esponds to a different
equation. The functions may use the math or random module.
The function will have the following properties:
Programming Project v2 – ENGR102 All Kurwitz Sections
Assigned: 10/20/20
Due Sunday 11/22/20 – 11:59 pm
• Name – the function name will be engr102_load_function
• Arguments – the function will take a single argument
o File name as a string
• Outputs
o Returns A list of strings co
esponding to each equation returned
o Each equation printed to the screen
• Deliverable
o The function will be part of a larger file called engr102_project_[last name] _[first
name]_[sec #].py – my submission would be engr102_project_kurwitz_cable_525.py.
Your file should contain a header as described in class.
Function 2.b – Plot the Equation
You are tasked with creating a function that will plot each of the equations over a range x = [0,10]. Each
function should include a label shown in the legend co
esponding to the line number i.e. Eq. 1, Eq. 2,
etc. Each equation should be represented by a different color and/or different line style and be a line
(no markers). The plot should include the following items; gridlines, x-axis label (x), y-axis label (y), title
(ENGR102 Project 2b), and the range of the x-axis should be from 0 to 10.
The function will have the following properties:
• Name – the function name will be engr102_plot_function
• Arguments – the function will take a single argument
o A list of strings co
esponding to the equations in python syntax
• Outputs
o A plot displayed to screen and saved as a .png file (use title as prefix)
• Deliverable
o The function will be part of a larger file called engr102_project_[last name] _[first
name]_[sec #].py – my submission would be engr102_project_kurwitz_cable_525.py.
Your file should contain a header as described in class.
Use of the eval() function will be needed. https:
docs.python.org/3/li
ary/functions.html#eval
Function 2.c – Integrate Equation
You tasked with developing a function that will calculate the area under a curve defined by a equation,
f(x). The function will take in four arguments: (1) a list of strings where each element of the list is a
separate equation; (2) a tuple that co
esponds to the limits of integration; (3) an integer that will be
used to determine the number of trapezoids;