Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Note: The programming language should be python could you please do that asap Write a program that models the movement of an object with mass

Note: The programming language should be python image text in transcribedcould you please do that asap

Write a program that models the movement of an object with mass m (in this exercise it is set to 1kg) that is attached to an oscillating spring. When a spring is displaced from its equilibrium position by an amount x (meters), Hooke's law states that the restoring force is F =-kx Where k is a constant that depends on the spring (in this exercise it is set to 10 N/m) The approach: Start with an initial displacement x (say 0.5 m) and an initial velocity v (say 0 m/s) and compute the acceleration a using Newton's law ( F = m, a ) and Hooke's law (F =-kx). Then iterate for a certain amount of time t (let say 10s) using an interval dt (let say 0.01s), updating the velocity v that changes by an amount a.dt, and the displacement x that changes by an amount v.dt. After every 10 iterations, save the obtained displacement x in a list called displacements Finally, display on the Spyder console, the contents of the list displacements and plot in a separate window its contents against time, where each pixel in the graph should represent 1 cm. (see Figure.1) Note: 1. The display of the list should be done by a function called displayList() that takes as input parameter the list to be displayed and displays each 10 elements in 1 line The plotting of displacements list against time should be done by a function called displayChart() that accepts the list displacements as input and creates a new list (say vertices) of coordinates (x, y), where x is the index in displacements (1, 2, ...) and y is the related displacement increased by dy 50 to avoid having negative values. The function draws uses the method drawPoly() provided in the ezgraphics library to draw the result. (See section 2.6 in the textbook) 2. You should submit a Python source code that includes at the beginning, as comments, the following items: 3. a. Problem statement (1 sentence) b. Requirements specifications (input, outputs and constraints) c. Pseudocodes for main(), displayList() and displayChart() Write a program that models the movement of an object with mass m (in this exercise it is set to 1kg) that is attached to an oscillating spring. When a spring is displaced from its equilibrium position by an amount x (meters), Hooke's law states that the restoring force is F =-kx Where k is a constant that depends on the spring (in this exercise it is set to 10 N/m) The approach: Start with an initial displacement x (say 0.5 m) and an initial velocity v (say 0 m/s) and compute the acceleration a using Newton's law ( F = m, a ) and Hooke's law (F =-kx). Then iterate for a certain amount of time t (let say 10s) using an interval dt (let say 0.01s), updating the velocity v that changes by an amount a.dt, and the displacement x that changes by an amount v.dt. After every 10 iterations, save the obtained displacement x in a list called displacements Finally, display on the Spyder console, the contents of the list displacements and plot in a separate window its contents against time, where each pixel in the graph should represent 1 cm. (see Figure.1) Note: 1. The display of the list should be done by a function called displayList() that takes as input parameter the list to be displayed and displays each 10 elements in 1 line The plotting of displacements list against time should be done by a function called displayChart() that accepts the list displacements as input and creates a new list (say vertices) of coordinates (x, y), where x is the index in displacements (1, 2, ...) and y is the related displacement increased by dy 50 to avoid having negative values. The function draws uses the method drawPoly() provided in the ezgraphics library to draw the result. (See section 2.6 in the textbook) 2. You should submit a Python source code that includes at the beginning, as comments, the following items: 3. a. Problem statement (1 sentence) b. Requirements specifications (input, outputs and constraints) c. Pseudocodes for main(), displayList() and displayChart()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago