File tree 1 file changed +55
-0
lines changed
1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ import scipy .constants as const
2
+ import math
3
+
4
+
5
+ def energy_equivalent_for_stationary_mass (mass_kg ):
6
+ """
7
+ Calculate the energy equivalent for a given mass using E=mc^2.
8
+
9
+ Parameters:
10
+ mass_kg (float): Mass in kilograms.(must be positive)
11
+
12
+ Returns:
13
+ float: Energy equivalent in joules.
14
+
15
+ >>>energy_equivalent_for_stationary_mass(4)
16
+ 3.5950207149472704e+17
17
+
18
+ """
19
+ if mass_kg < 0 :
20
+ ValueError ("mass of object cannot be negative" )
21
+
22
+ speed_of_light = const .speed_of_light # Speed of light in meters/second
23
+ energy_joules = mass_kg * (speed_of_light ** 2 )
24
+ return energy_joules
25
+
26
+
27
+ def energy_equivalent_for_moving_mass (mass_kg , velocity_m_s ):
28
+ """
29
+ Calculate the energy equivalent for a moving mass using relativistic energy-momentum relation(E^2= m^2*c^4 +p^2*c^2).
30
+
31
+ Parameters:
32
+ mass_kg (float): Mass in kilograms.(must be positive)
33
+ velocity_m_s (float): Velocity in meters per second.(can be negative as well as positive)
34
+
35
+ Returns:
36
+ float: Energy equivalent in joules.
37
+
38
+ >>>energy_equivalent_for_moving_mass(1,5675)
39
+ 1701322225868.2546
40
+ """
41
+ if mass_kg < 0 :
42
+ ValueError ("mass of object cannot be negative" )
43
+
44
+ speed_of_light = const .speed_of_light # Speed of light in meters/second
45
+
46
+ # Calculating momentum
47
+ momentum = mass_kg * velocity_m_s / math .sqrt (1 - (velocity_m_s ** 2 / speed_of_light ** 2 ))
48
+
49
+ # Calculating energy using the relativistic energy-momentum relation
50
+ energy_joules = math .sqrt ((mass_kg * speed_of_light )** 2 + (momentum * speed_of_light )** 2 )
51
+ return energy_joules
52
+
53
+ if __name__ == "__main__" :
54
+ import doctest
55
+ doctest .testmod ()
You can’t perform that action at this time.
0 commit comments