Question: Part C: Function, for and plotting We did a project in the lecture on calculating the free fall speeds and plotting them on a

Part C: Function, for and plotting We did a project in the lecture on calculating the free fall speeds and

Part C: Function, for and plotting We did a project in the lecture on calculating the free fall speeds and plotting them on a graph. This part is similar to the project. An engineer has derived a relationship between the force applied to a material and the extension in length that the force would cause. The relationship between force fand extension is given by: if 0 f 10 if 10 < f < 20 e = { 5.5 f f - 10f + 55 You are asked to plot a graph showing the relationship between force and extension. You are asked to complete the following tasks: Task 1 Write a Python function which returns the value of e for a given input f. Do not use literals (e.g. 5.5, 10) in the expressions for e in the function. Instead you should define constants and use them. Note that the relationship between e and f depends on whether f is bigger than 10 or not, this means you need a certain Python construction in your function. If you can't think of that, have a look at Part A of Lab03. Task 2 The aim of this task is to specify a list of values which are the values of force f that you will be using for plotting. These values are to be stored in a Python list called force_list. We impose these requirements on force_list: The first entry for force_list is 0. The entries in force_list are all integral multiples of a parameter called step_size. The last entry must be less than or equal to 20, which is the upper limit for the force. The difference between the last entry in force_list and 20 must be strictly less than step_size. This is so that we make full use of the range of f. Based on these requirements, the force_list for a number of different sizes are: If step_size=0.4, then force_list should be [0, 0.4, 0.8, 1.2,...,19.6, 20] which contains 51 values If step_size = 0.5, then force_list should be [0, 0.5, 1.0, 1.5,,19.5, 20] which contains 41 values If step_size = 0.7, then force_list should be [0, 0.7, 1.4, 2.1, 17.5,18.2,18.9,19.6] which contains 29 values If step_size =0.9, then force_list should be [0, 0.9, 1.8, 2.7, 18.0,18.9,19.8] which contains 23 values We want to make the program flexible so that it can automatically generate force_list from a given value of step_size. This flexibility will allow us to try out different values of step size. You may think this is complicated but we want to say that it is doable and we will give you some hints in one moment. We want to use this exercise to show you that with a bit of thinking, you can make your programs flexible. Hints: Step size 0.4 0.5 0.7 0.9 Since the entries in force_list are all integral multiples of step_size, you can use step_size and range() to generate force_list. An important consideration is how many entries you need in the sequence generated by range(). The number of entries that you need can be calculated by a formula which depends on 20 (which is the upper limit) and the step_size. You need to come out with the formula and you can check whether your formula is correct by using the examples above. There are two ways you can do that. You can make a mathematical argument to derive the formula. You can use the table below, observe the pattern and derive the formula. In particular, you want to find a relation between the number of entries in force_list and the value of 20 divided by step size, i.e. columns 3 and 4 in the table below. You may find that you need to fiddle the formula a few times to get it right. There is nothing wrong with that, it is part of learning. You may find the functions math.floor() and math.ceil() from the math library useful If you used //instead of the math functions you might have noticed some odd behavior with the last value in force_list. Check out this link to learn why if you are curious. We will discuss this later in the course. Last value in force list 20 (= 50*0.4) 20 (=40*0.5) 19.6 (=280.7) 19.8 (=22*0.9) The value of 20 divided by step size 50.0 40.0 28.57 22.22 Task 3 Use force_list (which you create in Task 2) and the function that your write in Task 1 to compute the extensions corresponding to those force values in the force_list. Use the two lists to plot extension versus force. Number of entries in force list 51 29 23

Step by Step Solution

3.40 Rating (166 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Task 1 Python functio... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!