Question: You must use only the material covered in the course notes for weeks 1 to 9 to solve the problems in this assignment. In questions






You must use only the material covered in the course notes for weeks 1 to 9 to solve the problems in this assignment. In questions 1, 2 and 3 of this assignment you will solve the same problem, calculating the approximate circumference of an ellipse. To do this sum the lengths of the hypotenuses of very small triangles to compute the approximate circumference of an ellipse. In question 1 you must use lists and in question 2 you must use arrays but not vector arithmetic and in question 3 you must use arrays and vector arithmetic You will use the timeit module to determine how much time each program uses to calculate the circumference of the ellipse for a large number of intervals and compare the times. An ellipse has a major axis and a minor axis, where the length of the major axis is greater than the length of the minor axis. The length of the semi-major axis is one half the length of the major axis and the length of the semi-minor axis is one half the length of the minor axis. An example of an ellipse is shown below where the length of the semi-major axis is 5.0 and the length of the semi-minor axis is 3.0. Ellipse with axes = (5.0,3.0) 2. 0 -2 -4 For each question in this assignment you will use the function named display Termination Message from assignment 2. Question 1 You must use lists in this question. Do not use arrays in this question! The purpose of this question is to write a complete Python program thatcomputes the approximate circumference of an ellipse. The ellipse is defined by the lengths of the semi-major and semi-minor axes. Write a function that begins with the following header: def getPositiveNumber prompt): Call this function to get all input from the user. Valid input is either an int greater than or equal to zero or a float greater than or equal to zero. The function displays the prompt to tell the user what to enter. If the user does not enter valid input display the appropriate error message as described below and display the prompt again asking for more input from the user. Repeat this until the user enters valid input. When the user enters valid input return that input Error situations: If the user presses enter/return without entering anything display the message 'Missing input!" . If the input causes an exception when passed to eval display the value of the input and the message 'is not valid! If the input is neither an int nor a float display the value of the input and the message'is not a number! If the input is less than zero display the value of the input and the message 'is less than zero!' Write a function that begins with the following header: def compute Xcoordinates(a, intervals): Given the value of a, the length of the semi-major axis, and the number of intervals create a list of equally spaced X coordinates from x = 0 to x=a. The first element in the list is 0 and the last element in the list is a The number of X coordinates in the list is intervals + 1. Return the list of x coordinates. Note: You must use list comprehension to create the list of X coordinates. Write a function that begins with the following header: def compute Y coordinates (a, b, xValues): Given the values of a, the length of the semi-major axis, b, the length of the semi- minor axis and a list of X coordinates named xValues this function creates a list of Y coordinates using equation 1. There will be one y coordinate for each X coordinate. Return the listof Y coordinates y=b. 1-equation1 Note: You must use list comprehension to create the listof Y coordinates Write a function that begins with the following header: def calcCircumference(a, b, intervals): Call computeXcoordinates to get the list of X coordinates and then call computercoordinates to get the list of corresponding Y coordinates. Use these two lists to compute the approximate circumference of an ellipse using the method described in dass Display the approximate circumference to 14 decimal places using exponential format. See the sample run of the program for the exact formatof the output This function does not return a value. The main program does the following: Using string replication display a line of dashes. Display a message indicating that zero may be entered after any prompt to terminate the program. In a loop: o call getPositiveNumber to input the value of a, the length of the semi-major axis, as a float, if the value returned by getPositiveNumber is equal to 0 exit from the loop o call getPositiveNumber to input the value of b, the length of the semi-minor axis, as a float, if the value returned by getPositiveNumber is equal to exit from the loop o call get PositiveNumber to input the integer number of intervals, if the value returned by get PositiveNumber is equal to 0 exit from the loop o use the Timer and timeit functions from the timeit module to calculate the time it takes to compute the circumference of the ellipse. o display the time it took to compute circumference of the ellipse to 3 decimal places, see the sample output for the exact format of the output Call display Termination Message to display the termination message. To use the Timer and timeit functions from the timeit module to calculate the time it takes to compute the circumference of the ellipse cut and paste the following statements into your program: t=timeit Timenl'cake Circumference(a, b, intervals), "from_main_import calcCircumference, a, b, interval) computeTime = t.time it(1) print("Compute time using lists is%3f seconds." % computeTime) There are two underscores before and after the word main in the statements given above. To use the Timer and timeit functions import the timelt module. Note: There is NO function named main in this program! A sample run of the program is shown below. To teminate the program enter after any prompt Enter the length of the mi-major axis in cm (>0): Missing input Enter the length of the semi-major acis in cm (>0): sds sds is not valid Enter the length of the semi-major acis in cm >0): True True is not a number Enter the length of the semi-major acis in cm (>0):-1 - is less than zerol Enter the length of the semi major exis in cm (>0): 10.25 Enter the length of the semieninor axis in cm (p>067.75 Enter the number of intervals of 10000000 The apparecimate circumsance of the ellipse is 5.66217058429445+01 cm. using lists is 7.271 Enter the length of the semi-major exis in cm (>0:0 Programmed by Stew Dent Date: Tue Feb 16 13:11:22 2021 End of processing Question 2 Do NOT use vector arithmetic in your solution to question 2. Modify your solution to question 1 to use arrays instead of lists. Add the appropriate import statement Modify the function named computeXcoordinates so that it creates and returns an array of X coordinates. Modify the function named computeYcoordinates so that it converts the list of Y coordinates into an array given an array of X coordinates. Modify a print statement in the main program so that instead of displaying "The compute time using lists is" it displays "The compute time using arrays is". Do not make any other changes to your program as they are not allowed Test your program using the same data used for question 1. Question 3 You must use arrays and vector arithmetic in your solution to question 3. Modify your solution to question 2 to use vector arithmetic on the arrays. Add or modify import statements as necessary. Modify the function named computeYcoordinates so that it uses vector arithmetic to create an array of Y coordinates given an array of X coordinates. Return the array of Y coordinates. There must not be any loops in this function. Modify the function named calcCircumference so that it uses vector arithmetic. There must not be any loops in this function. Modify a print statement in the main program so that instead of displaying "The compute time using arrays is" it displays "The compute time using vector arithmetic is. Do not make any other changes to your program as they are not allowed. Test your program using the same data used for questions 1 and 2. Question 4 Run the three programs that are your solutions to questions 1, 2 and 3 with a=10.25, b=7.75 and for 10 million intervals. Type your answers to the following questions in a.py file and hand in that file. The marker will not run the file. a) How long did it take for your solution to question 1 to compute the circumference of the ellipse? b) How long did it take for your solution to question 2 to compute the circumference of the ellipse? c) How long did it take for your solution to question 3 to compute the circumference of the ellipse? d) Which program ran the slowest? e) Which program ran the fastest? f) What do you conclude from this? Do not simply state whatyou observed. State when it is appropriate to use lists and when it is appropriate to use arrays in the solution of a
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
