22
33"""
44Finding the gravitational potential energy of an object with reference
5- to the earth,by taking its mass and height above the ground as input
5+ to the earth,by taking its mass and height above the ground as input.
66
7+ Description : Potential energy is stored energy that depends on the
8+ position or configuration of objects within a force field. It can be
9+ released as kinetic energy when the objects move under that force.
710
8- Description : Gravitational energy or gravitational potential energy
9- is the potential energy a massive object has in relation to another
10- massive object due to gravity. It is the potential energy associated
11- with the gravitational field, which is released (converted into
12- kinetic energy) when the objects fall towards each other.
13- Gravitational potential energy increases when two objects
14- are brought further apart .
11+ Gravitational potential energy is the energy an object has because of
12+ its position in a gravitational field. It is the potential energy a
13+ massive object has in relation to another massive object due to gravity.
14+ This energy is associated with the gravitational field and is released
15+ when the objects fall toward each other. Near the Earth's surface this
16+ potential energy is approximately proportional to mass, gravity, and
17+ height, so it is often written as U = mgh for a body close to Earth .
1518
16- For two pairwise interacting point particles, the gravitational
17- potential energy U is given by
19+ Spring potential energy is the stored energy in an elastic spring when
20+ it is compressed or stretched from its rest length. For small deformations,
21+ it is proportional to the square of the displacement from equilibrium.
22+
23+ For two point particles interacting pairwise, the gravitational potential
24+ energy U is given by
1825U=-GMm/R
1926where M and m are the masses of the two particles, R is the distance
2027between them, and G is the gravitational constant.
21- Close to the Earth's surface, the gravitational field is approximately
22- constant, and the gravitational potential energy of an object reduces to
23- U=mgh
24- where m is the object's mass, g=GM/R² is the gravity of Earth, and h is
25- the height of the object's center of mass above a chosen reference level.
2628
2729Reference : "https://en.m.wikipedia.org/wiki/Gravitational_energy"
2830"""
2931
3032
31- def potential_energy (mass : float , height : float ) -> float :
33+ def gravitational_potential_energy (mass : float , height : float ) -> float :
3234 # function will accept mass and height as parameters and return potential energy
3335 """
34- >>> potential_energy (10,10)
36+ >>> gravitational_potential_energy (10,10)
3537 980.665
36- >>> potential_energy (0,5)
38+ >>> gravitational_potential_energy (0,5)
3739 0.0
38- >>> potential_energy (8,0)
40+ >>> gravitational_potential_energy (8,0)
3941 0.0
40- >>> potential_energy (10,5)
42+ >>> gravitational_potential_energy (10,5)
4143 490.3325
42- >>> potential_energy (0,0)
44+ >>> gravitational_potential_energy (0,0)
4345 0.0
44- >>> potential_energy (2,8)
46+ >>> gravitational_potential_energy (2,8)
4547 156.9064
46- >>> potential_energy (20,100)
48+ >>> gravitational_potential_energy (20,100)
4749 19613.3
4850 """
4951 if mass < 0 :
@@ -52,10 +54,27 @@ def potential_energy(mass: float, height: float) -> float:
5254 if height < 0 :
5355 # handling of negative values of height
5456 raise ValueError ("The height above the ground cannot be negative" )
57+
5558 return mass * g * height
5659
60+ def spring_potential_energy (spring_constant : float , displacement : float ):
61+ #Function will except the spring constant and the displacemnt of the spring from equilibrium
62+ """
63+ >>> spring_potential_energy(100,2)
64+ 200
65+ >>> gravitational_potential_energy(10,0.5)
66+ 1.25
67+ >>> spring_potential_energy(8,0)
68+ 0.0
69+ """
70+ if spring_constant < 0 :
71+ raise ValueError ("The values for spring_constant cannot be negative" )
72+
73+ return 0.5 * spring_constant * (displacement ** 2 )
74+
75+
5776
5877if __name__ == "__main__" :
5978 from doctest import testmod
6079
61- testmod (name = "potential_energy " )
80+ testmod (name = "gravitational_potential_energy " )
0 commit comments