Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hi, This is question I have to work it out python based throught Jupiter notebook Can you work it out with little comments(methods) besides each
Hi, This is question I have to work it out python based throught Jupiter notebook Can you work it out with little comments(methods) besides each step of the work out, label Q2(a), Q2(b), Q2(c), Q2(d) clearly.
Thank you,
Question 2: [15 marks] The second order differential equation for a damped harmonic oscillator is: m + ci + kr =F(0) 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 2, 4, is the displacement, velocity and acceleration of the mass The period of the oscillator can be computed as: T = 2+1 Write a class, named harmonic Oscillator 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 for m and k and nonnegative for c. Creates data attributes, named me and 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. . (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 tont 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 Rungokutta4 to solve the equation of the oscillator using 1000 evenly distributed points in the interval (0, 10T) Use pyplot to plot the solution . Return ID 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: m + ci + kr =F(0) 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 2, 4, is the displacement, velocity and acceleration of the mass The period of the oscillator can be computed as: T = 2+1 Write a class, named harmonic Oscillator 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 for m and k and nonnegative for c. Creates data attributes, named me and 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. . (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 tont 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 Rungokutta4 to solve the equation of the oscillator using 1000 evenly distributed points in the interval (0, 10T) Use pyplot to plot the solution . Return ID 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
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