Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Using Python) Activity1 You should create a function that will perform linear interpolation from a set of measured data. The function should take as input

(Using Python)

Activity1

You should create a function that will perform linear interpolation from a set of measured data. The function should take as input a list of values at which samples were taken, and then another list giving the measurements (you can assume each measurement is a single value) at those values. It should also take in a query value, and should give the best estimate it can of the value at that query. Be sure to handle values that are outside of the range, by extrapolating.

You should write a program that allows you to test your function by reading the lists from a file where each line of the file is a pair of numbers separated by spaces: the value where the sample was taken, and the measurement at that value. Your program should ask the user for the name of the file and for a query value.

Important: The two lists will correspond to each other: i.e. for the i-th value in the first list, the measurement will be the i-th element of the second list (these are called parallel lists or arrays). But, you should not assume that the input values are in increasing/decreasing order. That is, the values in the first list can be in any random ordering, not necessarily from smallest to largest or largest to smallest. You will have to account for this in your program, and there is more than one way to do so. You should discuss what options you can think of to handle the data arriving in any order like that, and decide what you think the best option for handling it is.

Extend your program from part (a) so that it will handle not just single values but vector data.

Your program should ask a user for a file name, and the number of dimensions, n, of the vector data. It should then read from the file, assuming the values at which measurements are taken are the first entry per line, and then there will be n entries, all space-separated. You may find it easier to store your vector data in numpy arrays.

Your interpolation function should return the vector data either using tuples or using arrays

from the numpy module.

Activity2

Imagine that you have a block of material in which a hole has been drilled:

a)Write a function that will take in the dimensions of the box, length, width, and height, and the radius of the hole, and determine the volume of material remaining. Assume the hole has been drilled along the height direction. Note: first write the function assuming the hole has radius less than min(length/2, width/2) you will still receive a majority of credit (more than 70%) for this result. For full credit, you will need to account for larger radii.

b)Imagine that you have three parallel lists of the same length, one with the names of several production facilities, another with the annual cost to operate each of those facilities, and a third with the value of the products produced at each facility. Return the name and net profitability (profitability is the value of whats produced minus the cost to operate) of the least profitable facility.

c)Write a function that takes as input a persons name, city, state, zip code, and address, where the address is either one string (one line) or two strings (two lines), and prints the persons information like a mailing label. Show that the routine works regardless of whether it is called with one address line or two address lines.

d)Write a function that takes the name of a file with a .csv extension (a comma-separated value file), and writes a new file that is equivalent (same name and same data) but with a .tsv extension (a tab-separated value file: like a CSV but with tabs instead of commas separating the elements of the file). Note: the character used to represent a tab is \t.

e)Write a single function that takes in a list and returns the minimum, mean, and maximum value from the list.

f)Write a function that takes in two parallel lists: a list of times (in increasing order), and a list of distance traveled by that point in time. The function should return a new list giving the average velocity between consecutive time measurements. The new list should have length one less than the original lists.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago