In: Computer Science
I'm looking for a program, written in vPython, that simulates the movement of a spherical mass, suspended from a ceiling, tied to a spring. We are supposed to take the gravitaional force into account but are allowed to ignore the effects of air-resistance (for now).
I am a newbie at vPython so comments within the program to explain what certain parts of the code do would be appreciated!
'''
The motion of a spherical mass will be simple harmonic, given it is
suspended from the ceiling via. spring. Now if an external force,
'F', is exerted on the system the mass starts moving up-down in a
Simple Harmonic Motion.
Let,
the spring constant be 'k'
the mass be 'm'
Now,
F = kx
So, the Time-period, 'T', of the simple harmonic motion is given
by,
T = 2*(pie)*(m/k)1/2,
here,
'pie' is 3.14
For simplicity, we have taken all the units w.r.t. S.I.
units.
At first we have to take inputs from the user of the unknown
parameters:-
'''
#First take input of the value of 'm' and 'k'
m = float(input("Enter the value of the Spherical-mass in kg :
"))
k = float(input("Enter the value of the spring-constant in N/m :
"))
#Store the value of pie=22/7 in a variable 'pie'
pie = 22/7
#Now, compute the time-periord 'T' of the S.H.M.
T = 2 * pie * ((m/k)**(0.5)) #Here, ** symbolizes to the power in
python
print('The given motion is a Simple Harmonic Motion with Time-Periord : ',T)
Fair Copy:-
Python, Source Code without any explanations...
m = float(input("Enter the value of the Spherical-mass in kg :
"))
k = float(input("Enter the value of the spring-constant in N/m :
"))
pie = 22/7
T = 2 * pie * ((m/k)**(0.5)) #Here, ** symbolizes to the power in python
print('The given motion is a Simple Harmonic Motion with Time-Periord : ',T)