Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON 3 PLEASE AND THANK YOU 2. A simple spring test rig measures weights hung from a spring and the static displacement at each weight.

image text in transcribedimage text in transcribedimage text in transcribed

PYTHON 3 PLEASE AND THANK YOU

2. A simple spring test rig measures weights hung from a spring and the static displacement at each weight. The springs are supposed to be linear, following the relation F=k8, where F is the force applied to the spring, k is the spring constant, and is the displacement in the spring. We can see, when given values of force and displacement, we can find k = F/8. The data collected from one run of this rig is given in the file HW05_02_SpringData.txt, which is available on CatCourses. Look over that file to see how the headers are set up and note the numerical formats. The last line is F = mg blank. Note that the file could have any number of data rows in it, not just the 10 shown. Your program should accommodate different sizes of data files without changing the code for data file. You may assume that there will be 4 header lines before the first data line: A comment, the column titles, the column units, and a blank line. You should read the header lines to know what to write to the output file's headers. Write a Python program that reads in the headers and data from that file. The program should be able to accommodate any size of file. For each data point in the file, calculate a spring constant k for the given weight and displacement. This should be in N/m (not N/mm). Keep track of these values. For output, create a file called HW05 02 out.txt. It should have The same comment as the input file. Three columns, the first two are the weight and displacement from the input file. The third column is the spring constant calculated for each row, with the column header title "stiffness" and header units "(N/m)". A header line following the units should consist of dashes for each header, as wide as the header title for that column. the output file 20 characters wide. The format specification for all floats should use a 20 character wide field and show 3 digits to the right of the decimal place. See the example output below to be sure how this should look. It is very strongly suggested that reading the data and calculating stiffness correctly is done first. Getting the format output correct will take some time and some fine-tuning. Remember that the code should work for an input data file with any number of data rows without adjustment to the code. As an example, a data file with 5 data lines is shown below (and available as HW05 ExampleSpringData.txt on CatCourses). Spring Test Data, February, 2020 weight displacement (N) (mm) 0.968 2.022 2.997 3.965 4.984 0.6520 1.3066 2.0459 2.5755 3.4614 And the resulting output file (available as HW05_ExampleSpringData_out.txt): Spring Test Data, February, 2020 displacement (mm) weight (N) stiffness (N/m) 0.968 2.022 2.997 3.965 4.984 0.652 1.307 2.046 2.575 3.461 1484.663 1547.528 1464.881 1539.507 1439.880 Spring Test Data, February, 2020 weight displacement (N) (mm) 1.028 1.992 2.959 3.977 4.965 5.978 6.994 8.003 8.996 10.038 0.7000 1.4000 2.0000 2.8000 3.2000 4.1000 4.6000 5.4000 6.1000 6.4000 2. A simple spring test rig measures weights hung from a spring and the static displacement at each weight. The springs are supposed to be linear, following the relation F=k8, where F is the force applied to the spring, k is the spring constant, and is the displacement in the spring. We can see, when given values of force and displacement, we can find k = F/8. The data collected from one run of this rig is given in the file HW05_02_SpringData.txt, which is available on CatCourses. Look over that file to see how the headers are set up and note the numerical formats. The last line is F = mg blank. Note that the file could have any number of data rows in it, not just the 10 shown. Your program should accommodate different sizes of data files without changing the code for data file. You may assume that there will be 4 header lines before the first data line: A comment, the column titles, the column units, and a blank line. You should read the header lines to know what to write to the output file's headers. Write a Python program that reads in the headers and data from that file. The program should be able to accommodate any size of file. For each data point in the file, calculate a spring constant k for the given weight and displacement. This should be in N/m (not N/mm). Keep track of these values. For output, create a file called HW05 02 out.txt. It should have The same comment as the input file. Three columns, the first two are the weight and displacement from the input file. The third column is the spring constant calculated for each row, with the column header title "stiffness" and header units "(N/m)". A header line following the units should consist of dashes for each header, as wide as the header title for that column. the output file 20 characters wide. The format specification for all floats should use a 20 character wide field and show 3 digits to the right of the decimal place. See the example output below to be sure how this should look. It is very strongly suggested that reading the data and calculating stiffness correctly is done first. Getting the format output correct will take some time and some fine-tuning. Remember that the code should work for an input data file with any number of data rows without adjustment to the code. As an example, a data file with 5 data lines is shown below (and available as HW05 ExampleSpringData.txt on CatCourses). Spring Test Data, February, 2020 weight displacement (N) (mm) 0.968 2.022 2.997 3.965 4.984 0.6520 1.3066 2.0459 2.5755 3.4614 And the resulting output file (available as HW05_ExampleSpringData_out.txt): Spring Test Data, February, 2020 displacement (mm) weight (N) stiffness (N/m) 0.968 2.022 2.997 3.965 4.984 0.652 1.307 2.046 2.575 3.461 1484.663 1547.528 1464.881 1539.507 1439.880 Spring Test Data, February, 2020 weight displacement (N) (mm) 1.028 1.992 2.959 3.977 4.965 5.978 6.994 8.003 8.996 10.038 0.7000 1.4000 2.0000 2.8000 3.2000 4.1000 4.6000 5.4000 6.1000 6.4000

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

Deductive And Object Oriented Databases Second International Conference Dood 91 Munich Germany December 18 1991 Proceedings Lncs 566

Authors: Claude Delobel ,Michael Kifer ,Yoshifumi Masunaga

1st Edition

3540550151, 978-3540550150

More Books

Students also viewed these Databases questions

Question

How effectively does your company engage in double-loop learning?

Answered: 1 week ago

Question

Have I incorporated my research into my outline effectively?

Answered: 1 week ago