joules 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.md +22 -0
- data/README.md +4 -1
- data/lib/joules/constants.rb +53 -49
- data/lib/joules/conversion.rb +65 -60
- data/lib/joules/density.rb +17 -12
- data/lib/joules/electric_fields.rb +69 -0
- data/lib/joules/electricity.rb +234 -227
- data/lib/joules/energy_work_power.rb +102 -99
- data/lib/joules/forces.rb +60 -55
- data/lib/joules/geometry.rb +117 -112
- data/lib/joules/gravitational_fields.rb +71 -0
- data/lib/joules/kinematics.rb +118 -113
- data/lib/joules/mass_weight.rb +24 -21
- data/lib/joules/momentum_impulse.rb +45 -40
- data/lib/joules/pressure.rb +28 -25
- data/lib/joules/quantum.rb +45 -42
- data/lib/joules/thermodynamics.rb +33 -28
- data/lib/joules/waves.rb +119 -116
- data/lib/joules.rb +3 -1
- metadata +5 -2
data/lib/joules/kinematics.rb
CHANGED
@@ -3,128 +3,133 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing kinematics formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.1 01/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Kinematics module (kinematics.rb)
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
# distance >= 0; distance is in meters
|
14
|
-
# @param time [Int, Float]
|
15
|
-
# time > 0; time is in seconds
|
16
|
-
# @return [Float]
|
17
|
-
# return value >= 0; return value is in meters per second
|
18
|
-
# @example
|
19
|
-
# avg_speed(30, 2.4) #=> 12.5
|
20
|
-
def avg_speed(distance, time)
|
21
|
-
return distance / time.to_f
|
22
|
-
end
|
11
|
+
module Joules
|
12
|
+
module_function
|
23
13
|
|
24
|
-
# Calculates the average
|
25
|
-
# @param
|
26
|
-
#
|
27
|
-
# @param time [Int, Float]
|
28
|
-
# time > 0; time is in seconds
|
29
|
-
# @return [Float]
|
30
|
-
# return value is in meters per second
|
31
|
-
# @example
|
32
|
-
#
|
33
|
-
def
|
34
|
-
|
35
|
-
end
|
14
|
+
# Calculates the average speed given distance and time.
|
15
|
+
# @param distance [Int, Float]
|
16
|
+
# distance >= 0; distance is in meters
|
17
|
+
# @param time [Int, Float]
|
18
|
+
# time > 0; time is in seconds
|
19
|
+
# @return [Float]
|
20
|
+
# return value >= 0; return value is in meters per second
|
21
|
+
# @example
|
22
|
+
# Joules.avg_speed(30, 2.4) #=> 12.5
|
23
|
+
def avg_speed(distance, time)
|
24
|
+
return distance / time.to_f
|
25
|
+
end
|
36
26
|
|
37
|
-
# Calculates the
|
38
|
-
# @param
|
39
|
-
#
|
40
|
-
# @param
|
41
|
-
#
|
42
|
-
# @
|
43
|
-
#
|
44
|
-
# @
|
45
|
-
#
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
return (final_velocity - initial_velocity) / time.to_f
|
50
|
-
end
|
27
|
+
# Calculates the average velocity given displacement and time.
|
28
|
+
# @param displacement [Int, Float]
|
29
|
+
# displacement is in meters
|
30
|
+
# @param time [Int, Float]
|
31
|
+
# time > 0; time is in seconds
|
32
|
+
# @return [Float]
|
33
|
+
# return value is in meters per second
|
34
|
+
# @example
|
35
|
+
# Joules.avg_velocity(180, 4.8) #=> 37.5
|
36
|
+
def avg_velocity(displacement, time)
|
37
|
+
return displacement / time.to_f
|
38
|
+
end
|
51
39
|
|
52
|
-
# Calculates the
|
53
|
-
# @param initial_velocity [Int, Float]
|
54
|
-
# initial_velocity is in meters per second
|
55
|
-
# @param
|
56
|
-
#
|
57
|
-
# @param time [Int, Float]
|
58
|
-
# time
|
59
|
-
# @return [Float]
|
60
|
-
# return value is in meters per second
|
61
|
-
# @example
|
62
|
-
#
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
40
|
+
# Calculates the acceleration given initial velocity, final velocity, and time.
|
41
|
+
# @param initial_velocity [Int, Float]
|
42
|
+
# initial_velocity is in meters per second
|
43
|
+
# @param final_velocity [Int, Float]
|
44
|
+
# final_velocity is in meters per second
|
45
|
+
# @param time [Int, Float]
|
46
|
+
# time > 0; time is in seconds
|
47
|
+
# @return [Float]
|
48
|
+
# return value is in meters per second squared
|
49
|
+
# @example
|
50
|
+
# Joules.acceleration(20, 35, 2.4) #=> 6.25
|
51
|
+
def acceleration(initial_velocity, final_velocity, time)
|
52
|
+
return (final_velocity - initial_velocity) / time.to_f
|
53
|
+
end
|
67
54
|
|
68
|
-
# Calculates the final velocity given initial velocity, acceleration, and
|
69
|
-
# @param initial_velocity [Int, Float]
|
70
|
-
# initial_velocity is in meters per second
|
71
|
-
# @param acceleration [Int, Float]
|
72
|
-
# acceleration is in meters per second squared
|
73
|
-
# @param
|
74
|
-
#
|
75
|
-
# @return [Float]
|
76
|
-
# return value is in meters per second
|
77
|
-
# @example
|
78
|
-
#
|
79
|
-
# @note There is one other method for calculating final velocity.
|
80
|
-
def
|
81
|
-
|
82
|
-
end
|
55
|
+
# Calculates the final velocity given initial velocity, acceleration, and time.
|
56
|
+
# @param initial_velocity [Int, Float]
|
57
|
+
# initial_velocity is in meters per second
|
58
|
+
# @param acceleration [Int, Float]
|
59
|
+
# acceleration is in meters per second squared
|
60
|
+
# @param time [Int, Float]
|
61
|
+
# time >= 0; time is in seconds
|
62
|
+
# @return [Float]
|
63
|
+
# return value is in meters per second
|
64
|
+
# @example
|
65
|
+
# Joules.final_velocity_v1(20, 6.25, 2.4) #=> 35.0
|
66
|
+
# @note There is one other method for calculating final velocity.
|
67
|
+
def final_velocity_v1(initial_velocity, acceleration, time)
|
68
|
+
return initial_velocity + (acceleration * time.to_f)
|
69
|
+
end
|
83
70
|
|
84
|
-
# Calculates the
|
85
|
-
# @param initial_velocity [Int, Float]
|
86
|
-
# initial_velocity is in meters per second
|
87
|
-
# @param
|
88
|
-
#
|
89
|
-
# @param
|
90
|
-
#
|
91
|
-
# @return [Float]
|
92
|
-
# return value is in meters
|
93
|
-
# @example
|
94
|
-
#
|
95
|
-
# @note There
|
96
|
-
def
|
97
|
-
|
98
|
-
end
|
71
|
+
# Calculates the final velocity given initial velocity, acceleration, and displacement.
|
72
|
+
# @param initial_velocity [Int, Float]
|
73
|
+
# initial_velocity is in meters per second
|
74
|
+
# @param acceleration [Int, Float]
|
75
|
+
# acceleration is in meters per second squared
|
76
|
+
# @param displacement [Int, Float]
|
77
|
+
# displacement is in meters
|
78
|
+
# @return [Float]
|
79
|
+
# return value is in meters per second
|
80
|
+
# @example
|
81
|
+
# Joules.final_velocity_v2(20, 6.25, 66) #=> 35.0
|
82
|
+
# @note There is one other method for calculating final velocity.
|
83
|
+
def final_velocity_v2(initial_velocity, acceleration, displacement)
|
84
|
+
return ((initial_velocity ** 2) + (2 * acceleration * displacement)) ** 0.5
|
85
|
+
end
|
99
86
|
|
100
|
-
# Calculates the displacement given initial velocity,
|
101
|
-
# @param initial_velocity [Int, Float]
|
102
|
-
# initial_velocity is in meters per second
|
103
|
-
# @param
|
104
|
-
#
|
105
|
-
# @param time [Int, Float]
|
106
|
-
# time >= 0; time is in seconds
|
107
|
-
# @return [Float]
|
108
|
-
# return value is in meters
|
109
|
-
# @example
|
110
|
-
#
|
111
|
-
# @note There are two other methods for calculating displacement.
|
112
|
-
def
|
113
|
-
|
114
|
-
end
|
87
|
+
# Calculates the displacement given initial velocity, final velocity, and time.
|
88
|
+
# @param initial_velocity [Int, Float]
|
89
|
+
# initial_velocity is in meters per second
|
90
|
+
# @param final_velocity [Int, Float]
|
91
|
+
# final_velocity is in meters per second
|
92
|
+
# @param time [Int, Float]
|
93
|
+
# time >= 0; time is in seconds
|
94
|
+
# @return [Float]
|
95
|
+
# return value is in meters
|
96
|
+
# @example
|
97
|
+
# Joules.displacement_v1(20, 35, 2.4) #=> 66.0
|
98
|
+
# @note There are two other methods for calculating displacement.
|
99
|
+
def displacement_v1(initial_velocity, final_velocity, time)
|
100
|
+
return 0.5 * (initial_velocity + final_velocity) * time
|
101
|
+
end
|
102
|
+
|
103
|
+
# Calculates the displacement given initial velocity, acceleration, and time.
|
104
|
+
# @param initial_velocity [Int, Float]
|
105
|
+
# initial_velocity is in meters per second
|
106
|
+
# @param acceleration [Int, Float]
|
107
|
+
# acceleration is in meters per second squared
|
108
|
+
# @param time [Int, Float]
|
109
|
+
# time >= 0; time is in seconds
|
110
|
+
# @return [Float]
|
111
|
+
# return value is in meters
|
112
|
+
# @example
|
113
|
+
# Joules.displacement_v2(20, 6.25, 2.4) #=> 66.0
|
114
|
+
# @note There are two other methods for calculating displacement.
|
115
|
+
def displacement_v2(initial_velocity, acceleration, time)
|
116
|
+
return (initial_velocity * time) + (0.5 * acceleration * (time ** 2))
|
117
|
+
end
|
118
|
+
|
119
|
+
# Calculates the displacement given final velocity, acceleration, and time.
|
120
|
+
# @param final_velocity [Int, Float]
|
121
|
+
# final_velocity is in meters per second
|
122
|
+
# @param acceleration [Int, Float]
|
123
|
+
# acceleration is in meters per second squared
|
124
|
+
# @param time [Int, Float]
|
125
|
+
# time >= 0; time is in seconds
|
126
|
+
# @return [Float]
|
127
|
+
# return value is in meters
|
128
|
+
# @example
|
129
|
+
# Joules.displacement_v3(35, 6.25, 2.4) #=> 66.0
|
130
|
+
# @note There are two other methods for calculating displacement.
|
131
|
+
def displacement_v3(final_velocity, acceleration, time)
|
132
|
+
return (final_velocity * time) - (0.5 * acceleration * (time ** 2))
|
133
|
+
end
|
115
134
|
|
116
|
-
# Calculates the displacement given final velocity, acceleration, and time.
|
117
|
-
# @param final_velocity [Int, Float]
|
118
|
-
# final_velocity is in meters per second
|
119
|
-
# @param acceleration [Int, Float]
|
120
|
-
# acceleration is in meters per second squared
|
121
|
-
# @param time [Int, Float]
|
122
|
-
# time >= 0; time is in seconds
|
123
|
-
# @return [Float]
|
124
|
-
# return value is in meters
|
125
|
-
# @example
|
126
|
-
# displacement_v3(35, 6.25, 2.4) #=> 66.0
|
127
|
-
# @note There are two other methods for calculating displacement.
|
128
|
-
def displacement_v3(final_velocity, acceleration, time)
|
129
|
-
return (final_velocity * time) - (0.5 * acceleration * (time ** 2))
|
130
135
|
end
|
data/lib/joules/mass_weight.rb
CHANGED
@@ -3,31 +3,34 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing mass and weight formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.1 01/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Mass and weight module (mass_weight.rb)
|
10
10
|
|
11
|
-
|
11
|
+
module Joules
|
12
|
+
module_function
|
12
13
|
|
13
|
-
# Calculates the weight given mass.
|
14
|
-
# @param mass [Int, Float]
|
15
|
-
# mass >= 0; mass is in kilograms
|
16
|
-
# @return [Float]
|
17
|
-
# return value >= 0; return value is in newtons
|
18
|
-
# @example
|
19
|
-
# weight(79.41) #=> 779.0121
|
20
|
-
def weight(mass)
|
21
|
-
|
22
|
-
end
|
14
|
+
# Calculates the weight given mass.
|
15
|
+
# @param mass [Int, Float]
|
16
|
+
# mass >= 0; mass is in kilograms
|
17
|
+
# @return [Float]
|
18
|
+
# return value >= 0; return value is in newtons
|
19
|
+
# @example
|
20
|
+
# Joules.weight(79.41) #=> 779.0121
|
21
|
+
def weight(mass)
|
22
|
+
return mass * FREE_FALL_ACCELERATION
|
23
|
+
end
|
24
|
+
|
25
|
+
# Calculates the mass given weight.
|
26
|
+
# @param weight [Int, Float]
|
27
|
+
# weight >= 0; weight is in newtons
|
28
|
+
# @return [Float]
|
29
|
+
# return value >= 0; return value is in kilograms
|
30
|
+
# @example
|
31
|
+
# Joules.mass(779.0121) #=> 79.41
|
32
|
+
def mass(weight)
|
33
|
+
return weight / FREE_FALL_ACCELERATION
|
34
|
+
end
|
23
35
|
|
24
|
-
# Calculates the mass given weight.
|
25
|
-
# @param weight [Int, Float]
|
26
|
-
# weight >= 0; weight is in newtons
|
27
|
-
# @return [Float]
|
28
|
-
# return value >= 0; return value is in kilograms
|
29
|
-
# @example
|
30
|
-
# mass(779.0121) #=> 79.41
|
31
|
-
def mass(weight)
|
32
|
-
return weight / FREE_FALL_ACCELERATION
|
33
36
|
end
|
@@ -3,50 +3,55 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing momentum and impulse formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.1 01/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Momentum and impulse module (momentum_impulse.rb)
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
# mass >= 0; mass is in kilograms
|
14
|
-
# @param velocity [Int, Float]
|
15
|
-
# velocity is in meters per second
|
16
|
-
# @return [Float]
|
17
|
-
# return value is in newton seconds
|
18
|
-
# @example
|
19
|
-
# momentum(52, 4.7) #=> 244.4
|
20
|
-
def momentum(mass, velocity)
|
21
|
-
return mass * velocity.to_f
|
22
|
-
end
|
11
|
+
module Joules
|
12
|
+
module_function
|
23
13
|
|
24
|
-
# Calculates the
|
25
|
-
# @param
|
26
|
-
#
|
27
|
-
# @param
|
28
|
-
#
|
29
|
-
# @return [Float]
|
30
|
-
# return value is in newton seconds
|
31
|
-
# @example
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
14
|
+
# Calculates the momentum given mass and velocity.
|
15
|
+
# @param mass [Int, Float]
|
16
|
+
# mass >= 0; mass is in kilograms
|
17
|
+
# @param velocity [Int, Float]
|
18
|
+
# velocity is in meters per second
|
19
|
+
# @return [Float]
|
20
|
+
# return value is in newton seconds
|
21
|
+
# @example
|
22
|
+
# Joules.momentum(52, 4.7) #=> 244.4
|
23
|
+
def momentum(mass, velocity)
|
24
|
+
return mass * velocity.to_f
|
25
|
+
end
|
26
|
+
|
27
|
+
# Calculates the impulse given force and time.
|
28
|
+
# @param force [Int, Float]
|
29
|
+
# force is in newtons
|
30
|
+
# @param time [Int, Float]
|
31
|
+
# time >= 0; time is in seconds
|
32
|
+
# @return [Float]
|
33
|
+
# return value is in newton seconds
|
34
|
+
# @example
|
35
|
+
# Joules.impulse_v1(30.8, 9.6) #=> 295.68
|
36
|
+
# @note There is one other method for calculating impulse.
|
37
|
+
def impulse_v1(force, time)
|
38
|
+
return force * time.to_f
|
39
|
+
end
|
40
|
+
|
41
|
+
# Calculates the impulse given initial velocity, final velocity, and mass.
|
42
|
+
# @param initial_velocity [Int, Float]
|
43
|
+
# initial_velocity is in meters per second
|
44
|
+
# @param final_velocity [Int, Float]
|
45
|
+
# final_velocity is in meters per second
|
46
|
+
# @param mass [Int, Float]
|
47
|
+
# mass >= 0; mass is in kilograms
|
48
|
+
# @return [Float]
|
49
|
+
# return value is in newton seconds
|
50
|
+
# @example
|
51
|
+
# Joules.impulse_v2(20, 35, 2.4) #=> 36.0
|
52
|
+
# @note There is one other method for calculating impulse.
|
53
|
+
def impulse_v2(initial_velocity, final_velocity, mass)
|
54
|
+
return (final_velocity - initial_velocity) * mass.to_f
|
55
|
+
end
|
37
56
|
|
38
|
-
# Calculates the impulse given initial velocity, final velocity, and mass.
|
39
|
-
# @param initial_velocity [Int, Float]
|
40
|
-
# initial_velocity is in meters per second
|
41
|
-
# @param final_velocity [Int, Float]
|
42
|
-
# final_velocity is in meters per second
|
43
|
-
# @param mass [Int, Float]
|
44
|
-
# mass >= 0; mass is in kilograms
|
45
|
-
# @return [Float]
|
46
|
-
# return value is in newton seconds
|
47
|
-
# @example
|
48
|
-
# impulse_v2(20, 35, 2.4) #=> 36.0
|
49
|
-
# @note There is one other method for calculating impulse.
|
50
|
-
def impulse_v2(initial_velocity, final_velocity, mass)
|
51
|
-
return (final_velocity - initial_velocity) * mass.to_f
|
52
57
|
end
|
data/lib/joules/pressure.rb
CHANGED
@@ -3,35 +3,38 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing pressure formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.1 01/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Pressure module (pressure.rb)
|
10
10
|
|
11
|
-
|
11
|
+
module Joules
|
12
|
+
module_function
|
12
13
|
|
13
|
-
# Calculates the pressure given force and area.
|
14
|
-
# @param force [Int, Float]
|
15
|
-
# force >= 0; force is in newtons
|
16
|
-
# @param area [Int, Float]
|
17
|
-
# area > 0; area is in meters cubed
|
18
|
-
# @return [Float]
|
19
|
-
# return value >= 0; return value is in pascals
|
20
|
-
# @example
|
21
|
-
# pressure(98, 0.04) #=> 2450.0
|
22
|
-
def pressure(force, area)
|
23
|
-
|
24
|
-
end
|
14
|
+
# Calculates the pressure given force and area.
|
15
|
+
# @param force [Int, Float]
|
16
|
+
# force >= 0; force is in newtons
|
17
|
+
# @param area [Int, Float]
|
18
|
+
# area > 0; area is in meters cubed
|
19
|
+
# @return [Float]
|
20
|
+
# return value >= 0; return value is in pascals
|
21
|
+
# @example
|
22
|
+
# Joules.pressure(98, 0.04) #=> 2450.0
|
23
|
+
def pressure(force, area)
|
24
|
+
return force / area.to_f
|
25
|
+
end
|
26
|
+
|
27
|
+
# Calculates the hydrostatic pressure given density and height.
|
28
|
+
# @param density [Int, Float]
|
29
|
+
# density >= 0; density is in kilograms per meter cubed
|
30
|
+
# @param height [Int, Float]
|
31
|
+
# height >= 0; height is in meters
|
32
|
+
# @return [Float]
|
33
|
+
# return value >= 0; return value is in pascals
|
34
|
+
# @example
|
35
|
+
# Joules.hydrostatic_pressure(1000, 5) #=> 49050.0
|
36
|
+
def hydrostatic_pressure(density, height)
|
37
|
+
return density * FREE_FALL_ACCELERATION * height
|
38
|
+
end
|
25
39
|
|
26
|
-
# Calculates the hydrostatic pressure given density and height.
|
27
|
-
# @param density [Int, Float]
|
28
|
-
# density >= 0; density is in kilograms per meter cubed
|
29
|
-
# @param height [Int, Float]
|
30
|
-
# height >= 0; height is in meters
|
31
|
-
# @return [Float]
|
32
|
-
# return value >= 0; return value is in pascals
|
33
|
-
# @example
|
34
|
-
# hydrostatic_pressure(1000, 5) #=> 49050.0
|
35
|
-
def hydrostatic_pressure(density, height)
|
36
|
-
return density * FREE_FALL_ACCELERATION * height
|
37
40
|
end
|
data/lib/joules/quantum.rb
CHANGED
@@ -3,54 +3,57 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing quantum formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.1 01/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Quantum module (quantum.rb)
|
10
10
|
|
11
|
-
|
11
|
+
module Joules
|
12
|
+
module_function
|
12
13
|
|
13
|
-
# Calculates the photon energy given frequency.
|
14
|
-
# @param frequency [Int, Float]
|
15
|
-
# frequency > 0; frequency is in hertz
|
16
|
-
# @return [Float]
|
17
|
-
# return value > 0; return value is in joules
|
18
|
-
# @example
|
19
|
-
# photon_energy(509337860780984.75) #=> 3.376910016977929e-19
|
20
|
-
def photon_energy(frequency)
|
21
|
-
|
22
|
-
end
|
14
|
+
# Calculates the photon energy given frequency.
|
15
|
+
# @param frequency [Int, Float]
|
16
|
+
# frequency > 0; frequency is in hertz
|
17
|
+
# @return [Float]
|
18
|
+
# return value > 0; return value is in joules
|
19
|
+
# @example
|
20
|
+
# Joules.photon_energy(509337860780984.75) #=> 3.376910016977929e-19
|
21
|
+
def photon_energy(frequency)
|
22
|
+
return PLANCK_CONSTANT * frequency
|
23
|
+
end
|
23
24
|
|
24
|
-
# Calculates the energy given mass.
|
25
|
-
# @param mass [Int, Float]
|
26
|
-
# mass >= 0; mass is in kilograms
|
27
|
-
# @return [Float]
|
28
|
-
# return value >= 0; return value is in joules
|
29
|
-
# @example
|
30
|
-
# energy_v4(60.5) #=> 5.445e+18
|
31
|
-
# @note There are three other methods for calculating energy.
|
32
|
-
def energy_v4(mass)
|
33
|
-
|
34
|
-
end
|
25
|
+
# Calculates the energy given mass.
|
26
|
+
# @param mass [Int, Float]
|
27
|
+
# mass >= 0; mass is in kilograms
|
28
|
+
# @return [Float]
|
29
|
+
# return value >= 0; return value is in joules
|
30
|
+
# @example
|
31
|
+
# Joules.energy_v4(60.5) #=> 5.445e+18
|
32
|
+
# @note There are three other methods for calculating energy.
|
33
|
+
def energy_v4(mass)
|
34
|
+
return mass * (SPEED_OF_LIGHT ** 2)
|
35
|
+
end
|
35
36
|
|
36
|
-
# Calculates the half-life of a decaying quantity given decay constant.
|
37
|
-
# @param decay_constant [Int, Float]
|
38
|
-
# decay_constant != 0; decay_constant is in per second
|
39
|
-
# @return [Float]
|
40
|
-
# return value is in seconds
|
41
|
-
# @example
|
42
|
-
# half_life(7.7e4) #=> 9.001911435843445e-06
|
43
|
-
def half_life(decay_constant)
|
44
|
-
|
45
|
-
end
|
37
|
+
# Calculates the half-life of a decaying quantity given decay constant.
|
38
|
+
# @param decay_constant [Int, Float]
|
39
|
+
# decay_constant != 0; decay_constant is in per second
|
40
|
+
# @return [Float]
|
41
|
+
# return value is in seconds
|
42
|
+
# @example
|
43
|
+
# Joules.half_life(7.7e4) #=> 9.001911435843445e-06
|
44
|
+
def half_life(decay_constant)
|
45
|
+
return Math.log(2) / decay_constant
|
46
|
+
end
|
47
|
+
|
48
|
+
# Calculates the decay constant of a decaying quantity given half-life.
|
49
|
+
# @param half_life [Int, Float]
|
50
|
+
# half_life != 0; half_life is in seconds
|
51
|
+
# @return [Float]
|
52
|
+
# return value is in per second
|
53
|
+
# @example
|
54
|
+
# Joules.decay_constant(9) #=> 0.0770163533955495
|
55
|
+
def decay_constant(half_life)
|
56
|
+
return Math.log(2) / half_life
|
57
|
+
end
|
46
58
|
|
47
|
-
# Calculates the decay constant of a decaying quantity given half-life.
|
48
|
-
# @param half_life [Int, Float]
|
49
|
-
# half_life != 0; half_life is in seconds
|
50
|
-
# @return [Float]
|
51
|
-
# return value is in per second
|
52
|
-
# @example
|
53
|
-
# decay_constant(9) #=> 0.0770163533955495
|
54
|
-
def decay_constant(half_life)
|
55
|
-
return Math.log(2) / half_life
|
56
59
|
end
|
@@ -3,37 +3,42 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing thermodynamics formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.1 01/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Thermodynamics module (thermodynamics.rb)
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
|
24
|
-
|
25
|
-
|
11
|
+
module Joules
|
12
|
+
module_function
|
13
|
+
|
14
|
+
# Calculates the energy given mass, specific heat capacity, and temperature change.
|
15
|
+
# @param mass [Int, Float]
|
16
|
+
# mass >= 0; mass is in kilograms
|
17
|
+
# @param specific_heat_capacity [Int, Float]
|
18
|
+
# specific_heat_capacity >= 0; specific_heat_capacity is in joules per kilogram celcius
|
19
|
+
# @param temperature_change [Int, Float]
|
20
|
+
# temperature_change is in celcius
|
21
|
+
# @return [Float]
|
22
|
+
# return value is in joules
|
23
|
+
# @example
|
24
|
+
# Joules.energy_v1(500, 2.46, 3.6) #=> 4428.0
|
25
|
+
# @note There are two other methods for calculating energy.
|
26
|
+
def energy_v1(mass, specific_heat_capacity, temperature_change)
|
27
|
+
return mass * specific_heat_capacity * temperature_change.to_f
|
28
|
+
end
|
29
|
+
|
30
|
+
# Calculates the energy given mass and specific latent heat.
|
31
|
+
# @param mass [Int, Float]
|
32
|
+
# mass >= 0; mass is in kilograms
|
33
|
+
# @param specific_latent_heat [Int, Float]
|
34
|
+
# specific_latent_heat >= 0; specific_latent_heat is in joules per kilogram
|
35
|
+
# @return [Float]
|
36
|
+
# return value is in joules
|
37
|
+
# @example
|
38
|
+
# Joules.energy_v2(84.3, 72.1) #=> 6078.03
|
39
|
+
# @note There are two other methods for calculating energy.
|
40
|
+
def energy_v2(mass, specific_latent_heat)
|
41
|
+
return mass * specific_latent_heat.to_f
|
42
|
+
end
|
26
43
|
|
27
|
-
# Calculates the energy given mass and specific latent heat.
|
28
|
-
# @param mass [Int, Float]
|
29
|
-
# mass >= 0; mass is in kilograms
|
30
|
-
# @param specific_latent_heat [Int, Float]
|
31
|
-
# specific_latent_heat >= 0; specific_latent_heat is in joules per kilogram
|
32
|
-
# @return [Float]
|
33
|
-
# return value is in joules
|
34
|
-
# @example
|
35
|
-
# energy_v2(84.3, 72.1) #=> 6078.03
|
36
|
-
# @note There are two other methods for calculating energy.
|
37
|
-
def energy_v2(mass, specific_latent_heat)
|
38
|
-
return mass * specific_latent_heat.to_f
|
39
44
|
end
|