Question: HI, CAN YOU PUT EXTRA COMMENTS(METHODS) TO SHOW HOW YOUR GETTING IT WITH EACH STEP CLEARLY I APPRECIATE IT THANK Question 2: [15 marks] The

 HI, CAN YOU PUT EXTRA COMMENTS(METHODS) TO SHOW HOW YOUR GETTING

IT WITH EACH STEP CLEARLY I APPRECIATE IT THANK Question 2: [15

HI, CAN YOU PUT EXTRA COMMENTS(METHODS) TO SHOW HOW YOUR GETTING IT WITH EACH STEP CLEARLY I APPRECIATE IT

THANK

Question 2: [15 marks] The second order differential equation for a damped harmonic oscillator is: mi + ci + kr = F(t) where: m is the mass of the oscillator c is the damping coefficient of the oscillator k is the stiffness of the oscillator F(t) is the applied force r, is the displacement, velocity and acceleration of the mass The period of the oscillator can be computed as: m T = 27 Write a class, named harmonicOscillator to represent and solve harmonic oscillators for different applied forces and initial conditions. The class should contain the following: (a) A constructor, that: . Receives the mass, damping coefficient and stiffness of the oscillator as input arguments. Ensures that the provided values are meaningful by checking their data types are float or int and their signs are positive form and k and nonnegative for c. Creates data attributes, named , c and k for the mass, damping coefficient and stiffness of the oscillator with the provided values. Passes the unit tests included in the provided test coursework.py file (4 marks] (b) A method named period to compute the period of the oscillator based on the provided for- mula. The method should pass the corresponding tests in the provided test_coursework.py file. [2 marks] (c) A method, named provided solve, to solve the equation of the oscillator for user-provided initial conditions and applied forces, using the function from Question 1. This method should: Receive as input a Python function or lambda with the value of the applied force as a function of t and a list with the initial displacement and velocity of the oscillator. Create a lambda with the right hand side of the first order equation corresponding to the equation of the oscillator. Call Rungekutta4 to solve the equation of the oscillator using 1000 evenly distributed points in the interval [0, 10T]. Use pyplot to plot the solution. Return 1D Numpy arrays with the values of t used for the solution and the solution in terms of displacements. Pass the corresponding tests in the provided test_coursework.py file. [7 marks) (d) Docstrings and comments for the class and all its methods. [2 marks] Question 2: [15 marks] The second order differential equation for a damped harmonic oscillator is: mi + ci + kr = F(t) where: m is the mass of the oscillator c is the damping coefficient of the oscillator k is the stiffness of the oscillator F(t) is the applied force r, is the displacement, velocity and acceleration of the mass The period of the oscillator can be computed as: m T = 27 Write a class, named harmonicOscillator to represent and solve harmonic oscillators for different applied forces and initial conditions. The class should contain the following: (a) A constructor, that: . Receives the mass, damping coefficient and stiffness of the oscillator as input arguments. Ensures that the provided values are meaningful by checking their data types are float or int and their signs are positive form and k and nonnegative for c. Creates data attributes, named , c and k for the mass, damping coefficient and stiffness of the oscillator with the provided values. Passes the unit tests included in the provided test coursework.py file (4 marks] (b) A method named period to compute the period of the oscillator based on the provided for- mula. The method should pass the corresponding tests in the provided test_coursework.py file. [2 marks] (c) A method, named provided solve, to solve the equation of the oscillator for user-provided initial conditions and applied forces, using the function from Question 1. This method should: Receive as input a Python function or lambda with the value of the applied force as a function of t and a list with the initial displacement and velocity of the oscillator. Create a lambda with the right hand side of the first order equation corresponding to the equation of the oscillator. Call Rungekutta4 to solve the equation of the oscillator using 1000 evenly distributed points in the interval [0, 10T]. Use pyplot to plot the solution. Return 1D Numpy arrays with the values of t used for the solution and the solution in terms of displacements. Pass the corresponding tests in the provided test_coursework.py file. [7 marks) (d) Docstrings and comments for the class and all its methods. [2 marks]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!