Skip to content

Commit 6eb3556

Browse files
committed
Added the algorithm to compute the time period of a simple pendulum
1 parent 0b44028 commit 6eb3556

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

Diff for: physics/time_period_simple_pendulum.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
Title : Computing the time period of a simple pendulum
3+
4+
A simple pendulum is a mechanical arrangement that demonstrates
5+
periodic motion. The simple pendulum comprises of a small bob of mass 'm'
6+
suspended by a thin string secured to a platform at its upper end of
7+
length L.
8+
9+
The simple pendulum is a mechanical system that sways or moves in an
10+
oscillatory motion. This motion occurs in a vertical plane and is mainly
11+
driven by gravitational force. Interestingly, the bob that is suspended at
12+
the end of a thread is very light; somewhat, we can say it is even
13+
massless. The period of a simple pendulum can be made extended by
14+
increasing the length string while taking the measurements from the point
15+
of suspension to the middle of the bob. However, it should be noted that if
16+
the mass of the bob is changed, the period will remain unchanged. The
17+
period is influenced mainly by the position of the pendulum in relation to
18+
Earth, as the strength of the gravitational field is not uniform everywhere.
19+
20+
The Time Period of a simple pendulum is given by :
21+
22+
T = 2 * π * (l/g)^0.5
23+
24+
where :
25+
26+
T = Time period of the simple pendulum (in s)
27+
π = Mathematical constant (value taken : 3.14159)
28+
l = length of string from which the bob is hanging (in m)
29+
g = Acceleration due to gravity (value taken : 9.8 m/s^2)
30+
31+
Reference : https://byjus.com/jee/simple-pendulum/
32+
"""
33+
34+
35+
def time_period_simple_pendulum(length: float) -> float:
36+
"""
37+
>>> time_period_simple_pendulum(1.23)
38+
2.2259685262423705
39+
>>> time_period_simple_pendulum(2.37)
40+
3.089873051721361
41+
>>> time_period_simple_pendulum(5.63)
42+
4.762342885477521
43+
>>> time_period_simple_pendulum(-12)
44+
Traceback (most recent call last):
45+
...
46+
ValueError: The length should be non-negative
47+
>>> time_period_simple_pendulum(0)
48+
0.0
49+
"""
50+
if length < 0:
51+
raise ValueError("The length should be non-negative")
52+
return (2 * 3.14159) * (length / 9.8) ** 0.5
53+
54+
55+
if __name__ == "__main__":
56+
import doctest
57+
58+
doctest.testmod()

0 commit comments

Comments
 (0)