Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use Jupyter Notebook The University of Texas at Austin CE 311K Introduction to Computer Methods Homework #5 While Loops and Sorting Algorithms Due Date: In
Use Jupyter Notebook
The University of Texas at Austin CE 311K Introduction to Computer Methods Homework #5 While Loops and Sorting Algorithms Due Date: In Lab, 12/13 March 2019 (depending on your lab) Introduction The purpose of this assignment is to gain experience using while loops, as well as to implementing a sorting algorithm Homework Problems 1. The Taylor series expansion for cos(x) is: (-1)" 2n (2n)! cos(x) = 1--+ +-.. = 2! 4!6! where x is an angle in radians. Write a Python program that determines cos(x) using the Taylor series expansion. The program must ask the user to type a value for an angle in degrees. The program then uses a loop for adding the terms of the Taylor series until a certain relative error (E) between terms is achieved. If an is the nth term of the series, then the sum Sn of the n terms is Sn- Sn-1 an In each pass, calculate the E relative to the previous pass using: Stop adding when E 0.000001. The program then displays the actual value of E (which will be less than the value noted above), the number of terms required to achieve this error, and the value determined for the cos(x) using the following format: The relative error achieved after XX terms was X. XXXXXXXX The cosine of XXX degrees is X.XXXXXXxx Use your program to calculate and display the output for: a) cos(35) b) cos(90) c) cos(200) Compare these values with those obtained using the numpy cosine function and compute the truc percent error The University of Texas at Austin CE 311K Introduction to Computer Methods 2. Studying previous earthquakes is critical to our understanding of earthquake effects. Typically, after an earthquake occurs it is given a name, based on where it occurred, and it:s date is recorded. The size of the earthquake is characterized by its magnitude, MM You have been asked to write a program that takes a list of earthquake names, dates, and magnitudes and sorts the list in a manner specified by the user. The user may specify date, magnitude, or alphabetic sorting by the name. The input is provided in a formatted text file (eq.txt) with information about each earthquake listed in a semicolon separated row. The name of the earthquake is listed first, followed by the magnitude, and then the year The sorted list should be placed in an array and should include all three pieces of information for each earthquake (i.e., name, magnitude, and year). However, the list should be sorted according to the specification of the user, with the first column in the list corresponding to the parameter by which the list is being sorted (e.g. if sorted by year, the first column in the list should be year; if sorted by name, the first column of the list should be the name, etc.). The sorted list should be output to a formatted text file named sort-eq.txt. Use the Selection Sort algorithm in your sorting program. Be sure to make the program general, such that different lengths of lists can be used, and pass the appropriate information to the program The University of Texas at Austin CE 311K Introduction to Computer Methods Homework #5 While Loops and Sorting Algorithms Due Date: In Lab, 12/13 March 2019 (depending on your lab) Introduction The purpose of this assignment is to gain experience using while loops, as well as to implementing a sorting algorithm Homework Problems 1. The Taylor series expansion for cos(x) is: (-1)" 2n (2n)! cos(x) = 1--+ +-.. = 2! 4!6! where x is an angle in radians. Write a Python program that determines cos(x) using the Taylor series expansion. The program must ask the user to type a value for an angle in degrees. The program then uses a loop for adding the terms of the Taylor series until a certain relative error (E) between terms is achieved. If an is the nth term of the series, then the sum Sn of the n terms is Sn- Sn-1 an In each pass, calculate the E relative to the previous pass using: Stop adding when E 0.000001. The program then displays the actual value of E (which will be less than the value noted above), the number of terms required to achieve this error, and the value determined for the cos(x) using the following format: The relative error achieved after XX terms was X. XXXXXXXX The cosine of XXX degrees is X.XXXXXXxx Use your program to calculate and display the output for: a) cos(35) b) cos(90) c) cos(200) Compare these values with those obtained using the numpy cosine function and compute the truc percent error The University of Texas at Austin CE 311K Introduction to Computer Methods 2. Studying previous earthquakes is critical to our understanding of earthquake effects. Typically, after an earthquake occurs it is given a name, based on where it occurred, and it:s date is recorded. The size of the earthquake is characterized by its magnitude, MM You have been asked to write a program that takes a list of earthquake names, dates, and magnitudes and sorts the list in a manner specified by the user. The user may specify date, magnitude, or alphabetic sorting by the name. The input is provided in a formatted text file (eq.txt) with information about each earthquake listed in a semicolon separated row. The name of the earthquake is listed first, followed by the magnitude, and then the year The sorted list should be placed in an array and should include all three pieces of information for each earthquake (i.e., name, magnitude, and year). However, the list should be sorted according to the specification of the user, with the first column in the list corresponding to the parameter by which the list is being sorted (e.g. if sorted by year, the first column in the list should be year; if sorted by name, the first column of the list should be the name, etc.). The sorted list should be output to a formatted text file named sort-eq.txt. Use the Selection Sort algorithm in your sorting program. Be sure to make the program general, such that different lengths of lists can be used, and pass the appropriate information to the programStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started