joules 0.3.1 → 0.3.2
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/README.md +9 -5
- data/lib/joules/constants.rb +8 -8
- data/lib/joules/conversion.rb +11 -11
- data/lib/joules/density.rb +10 -5
- data/lib/joules/electric_fields.rb +43 -9
- data/lib/joules/electricity.rb +47 -12
- data/lib/joules/energy_work_power.rb +31 -13
- data/lib/joules/forces.rb +13 -8
- data/lib/joules/geometry.rb +9 -9
- data/lib/joules/gravitational_fields.rb +31 -11
- data/lib/joules/kinematics.rb +42 -27
- data/lib/joules/magnetic_fields.rb +78 -0
- data/lib/joules/mass_weight.rb +1 -1
- data/lib/joules/momentum_impulse.rb +4 -4
- data/lib/joules/pressure.rb +10 -5
- data/lib/joules/quantum.rb +13 -3
- data/lib/joules/stress_strain.rb +68 -0
- data/lib/joules/thermodynamics.rb +1 -1
- data/lib/joules/waves.rb +67 -22
- data/lib/joules.rb +3 -1
- metadata +4 -2
data/lib/joules/geometry.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing geometry formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.2 03/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Geometry module (geometry.rb)
|
@@ -17,7 +17,7 @@ module Joules
|
|
17
17
|
# @param width [Int, Float]
|
18
18
|
# width >= 0; width has the same units as length
|
19
19
|
# @return [Float]
|
20
|
-
# return value >= 0; return value has the same units as length
|
20
|
+
# return value >= 0; return value has the same units squared as length
|
21
21
|
# @example
|
22
22
|
# Joules.rectangle_area(2, 3.4) #=> 6.8
|
23
23
|
def rectangle_area(length, width)
|
@@ -52,7 +52,7 @@ module Joules
|
|
52
52
|
# @param radius [Int, Float]
|
53
53
|
# radius >= 0; radius is in a unit of length
|
54
54
|
# @return [Float]
|
55
|
-
# return value >= 0; return value has the same units as radius
|
55
|
+
# return value >= 0; return value has the same units squared as radius
|
56
56
|
# @example
|
57
57
|
# Joules.circle_area(12) #=> 452.38934211693
|
58
58
|
def circle_area(radius)
|
@@ -63,7 +63,7 @@ module Joules
|
|
63
63
|
# @param radius [Int, Float]
|
64
64
|
# radius >= 0; radius is in a unit of length
|
65
65
|
# @return [Float]
|
66
|
-
# return value >= 0; return value has the same units as radius
|
66
|
+
# return value >= 0; return value has the same units squared as radius
|
67
67
|
# @example
|
68
68
|
# Joules.sphere_surface_area(12) #=> 1809.5573684677208
|
69
69
|
def sphere_surface_area(radius)
|
@@ -74,7 +74,7 @@ module Joules
|
|
74
74
|
# @param radius [Int, Float]
|
75
75
|
# radius >= 0; radius is in a unit of length
|
76
76
|
# @return [Float]
|
77
|
-
# return value >= 0; return value has the same units as radius
|
77
|
+
# return value >= 0; return value has the same units cubed as radius
|
78
78
|
# @example
|
79
79
|
# Joules.sphere_volume(12) #=> 7238.229473870883
|
80
80
|
def sphere_volume(radius)
|
@@ -87,7 +87,7 @@ module Joules
|
|
87
87
|
# @param slant_height [Int, Float]
|
88
88
|
# slant_height >= 0; slant_height has the same units as radius
|
89
89
|
# @return [Float]
|
90
|
-
# return value >= 0; return value has the same units as radius
|
90
|
+
# return value >= 0; return value has the same units squared as radius
|
91
91
|
# @example
|
92
92
|
# Joules.cone_surface_area(3, 5.83) #=> 83.22078939359362
|
93
93
|
def cone_surface_area(radius, slant_height)
|
@@ -100,7 +100,7 @@ module Joules
|
|
100
100
|
# @param height [Int, Float]
|
101
101
|
# height >= 0; height has the same units as radius
|
102
102
|
# @return [Float]
|
103
|
-
# return value >= 0; return value has the same units as radius
|
103
|
+
# return value >= 0; return value has the same units cubed as radius
|
104
104
|
# @example
|
105
105
|
# Joules.cone_volume(6.5, 3) #=> 132.73228961416876
|
106
106
|
def cone_volume(radius, height)
|
@@ -113,7 +113,7 @@ module Joules
|
|
113
113
|
# @param height [Int, Float]
|
114
114
|
# height >= 0; height has the same units as radius
|
115
115
|
# @return [Float]
|
116
|
-
# return value >= 0; return value has the same units as radius
|
116
|
+
# return value >= 0; return value has the same units squared as radius
|
117
117
|
# @example
|
118
118
|
# Joules.cylinder_surface_area(6.5, 3) #=> 122.522113490002
|
119
119
|
def cylinder_surface_area(radius, height)
|
@@ -126,7 +126,7 @@ module Joules
|
|
126
126
|
# @param height [Int, Float]
|
127
127
|
# height >= 0; height has the same units as radius
|
128
128
|
# @return [Float]
|
129
|
-
# return value >= 0; return value has the same units as radius
|
129
|
+
# return value >= 0; return value has the same units cubed as radius
|
130
130
|
# @example
|
131
131
|
# Joules.cylinder_volume(6.5, 3) #=> 398.196868842506
|
132
132
|
def cylinder_volume(radius, height)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing gravitational fields formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.2 03/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Gravitational fields module (gravitational_fields.rb)
|
@@ -17,14 +17,19 @@ module Joules
|
|
17
17
|
# @param object_mass2 [Int, Float]
|
18
18
|
# object_mass2 >= 0; object_mass2 is in kilograms
|
19
19
|
# @param distance [Int, Float]
|
20
|
-
# distance > 0; distance is in
|
20
|
+
# distance > 0; distance is in metres
|
21
21
|
# @return [Float]
|
22
22
|
# return value >= 0; return value is in newtons
|
23
|
+
# @raise [ZeroDivisionError] if distance = 0
|
23
24
|
# @example
|
24
25
|
# Joules.gravitational_force(2e30, 1.9e27, 7.8e11) #=> 4.166009204470743e+23
|
25
26
|
def gravitational_force(object_mass1, object_mass2, distance)
|
26
|
-
|
27
|
-
|
27
|
+
if distance.zero?
|
28
|
+
raise ZeroDivisionError.new('divided by 0')
|
29
|
+
else
|
30
|
+
return (GRAVITATIONAL_CONSTANT * object_mass1 * object_mass2) /
|
31
|
+
(distance ** 2)
|
32
|
+
end
|
28
33
|
end
|
29
34
|
|
30
35
|
# Calculates the gravitational field strength given force and mass.
|
@@ -33,39 +38,54 @@ module Joules
|
|
33
38
|
# @param mass [Int, Float]
|
34
39
|
# mass > 0; mass is in kilograms
|
35
40
|
# @return [Float]
|
36
|
-
# return value is in
|
41
|
+
# return value is in metres per second squared
|
42
|
+
# @raise [ZeroDivisionError] if mass = 0
|
37
43
|
# @example
|
38
44
|
# Joules.gravitational_field_strength_v1(20, 0.5) #=> 40.0
|
39
45
|
# @note There is one other method for calculating gravitational field strength.
|
40
46
|
def gravitational_field_strength_v1(force, mass)
|
41
|
-
|
47
|
+
if mass.zero?
|
48
|
+
raise ZeroDivisionError.new('divided by 0')
|
49
|
+
else
|
50
|
+
return force / mass.to_f
|
51
|
+
end
|
42
52
|
end
|
43
53
|
|
44
54
|
# Calculates the gravitational field strength given mass and distance.
|
45
55
|
# @param mass [Int, Float]
|
46
56
|
# mass >= 0; mass is in kilograms
|
47
57
|
# @param distance [Int, Float]
|
48
|
-
# distance > 0; distance is in
|
58
|
+
# distance > 0; distance is in metres
|
49
59
|
# @return [Float]
|
50
|
-
# return value >= 0; return value is in
|
60
|
+
# return value >= 0; return value is in metres per second squared
|
61
|
+
# @raise [ZeroDivisionError] if distance = 0
|
51
62
|
# @example
|
52
63
|
# Joules.gravitational_field_strength_v2(34.7, 9.3) #=> 2.6760203491733148e-11
|
53
64
|
# @note There is one other method for calculating gravitational field strength.
|
54
65
|
def gravitational_field_strength_v2(mass, distance)
|
55
|
-
|
66
|
+
if distance.zero?
|
67
|
+
raise ZeroDivisionError.new('divided by 0')
|
68
|
+
else
|
69
|
+
return (GRAVITATIONAL_CONSTANT * mass) / (distance ** 2)
|
70
|
+
end
|
56
71
|
end
|
57
72
|
|
58
73
|
# Calculates the gravitational potential given mass and distance.
|
59
74
|
# @param mass [Int, Float]
|
60
75
|
# mass >= 0; mass is in kilograms
|
61
76
|
# @param distance [Int, Float]
|
62
|
-
# distance > 0; distance is in
|
77
|
+
# distance > 0; distance is in metres
|
63
78
|
# @return [Float]
|
64
79
|
# return value <= 0; return value is in joules per kilogram
|
80
|
+
# @raise [ZeroDivisionError] if distance = 0
|
65
81
|
# @example
|
66
82
|
# Joules.gravitational_potential(6e24, 6.4e6) #=> -62531250.0
|
67
83
|
def gravitational_potential(mass, distance)
|
68
|
-
|
84
|
+
if distance.zero?
|
85
|
+
raise ZeroDivisionError.new('divided by 0')
|
86
|
+
else
|
87
|
+
return (-GRAVITATIONAL_CONSTANT * mass) / distance
|
88
|
+
end
|
69
89
|
end
|
70
90
|
|
71
91
|
end
|
data/lib/joules/kinematics.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing kinematics formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.2 03/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Kinematics module (kinematics.rb)
|
@@ -13,54 +13,69 @@ module Joules
|
|
13
13
|
|
14
14
|
# Calculates the average speed given distance and time.
|
15
15
|
# @param distance [Int, Float]
|
16
|
-
# distance >= 0; distance is in
|
16
|
+
# distance >= 0; distance is in metres
|
17
17
|
# @param time [Int, Float]
|
18
18
|
# time > 0; time is in seconds
|
19
19
|
# @return [Float]
|
20
|
-
# return value >= 0; return value is in
|
20
|
+
# return value >= 0; return value is in metres per second
|
21
|
+
# @raise [ZeroDivisionError] if time = 0
|
21
22
|
# @example
|
22
23
|
# Joules.avg_speed(30, 2.4) #=> 12.5
|
23
24
|
def avg_speed(distance, time)
|
24
|
-
|
25
|
+
if time.zero?
|
26
|
+
raise ZeroDivisionError.new('divided by 0')
|
27
|
+
else
|
28
|
+
return distance / time.to_f
|
29
|
+
end
|
25
30
|
end
|
26
31
|
|
27
32
|
# Calculates the average velocity given displacement and time.
|
28
33
|
# @param displacement [Int, Float]
|
29
|
-
# displacement is in
|
34
|
+
# displacement is in metres
|
30
35
|
# @param time [Int, Float]
|
31
36
|
# time > 0; time is in seconds
|
32
37
|
# @return [Float]
|
33
|
-
# return value is in
|
38
|
+
# return value is in metres per second
|
39
|
+
# @raise [ZeroDivisionError] if time = 0
|
34
40
|
# @example
|
35
41
|
# Joules.avg_velocity(180, 4.8) #=> 37.5
|
36
42
|
def avg_velocity(displacement, time)
|
37
|
-
|
43
|
+
if time.zero?
|
44
|
+
raise ZeroDivisionError.new('divided by 0')
|
45
|
+
else
|
46
|
+
return displacement / time.to_f
|
47
|
+
end
|
38
48
|
end
|
39
49
|
|
40
50
|
# Calculates the acceleration given initial velocity, final velocity, and time.
|
41
51
|
# @param initial_velocity [Int, Float]
|
42
|
-
# initial_velocity is in
|
52
|
+
# initial_velocity is in metres per second
|
43
53
|
# @param final_velocity [Int, Float]
|
44
|
-
# final_velocity is in
|
54
|
+
# final_velocity is in metres per second
|
45
55
|
# @param time [Int, Float]
|
46
56
|
# time > 0; time is in seconds
|
47
57
|
# @return [Float]
|
48
|
-
# return value is in
|
58
|
+
# return value is in metres per second squared
|
59
|
+
# @raise [ZeroDivisionError] if time = 0
|
49
60
|
# @example
|
50
61
|
# Joules.acceleration(20, 35, 2.4) #=> 6.25
|
51
62
|
def acceleration(initial_velocity, final_velocity, time)
|
52
|
-
|
63
|
+
if time.zero?
|
64
|
+
raise ZeroDivisionError.new('divided by 0')
|
65
|
+
else
|
66
|
+
return (final_velocity - initial_velocity) / time.to_f
|
67
|
+
end
|
53
68
|
end
|
54
69
|
|
55
70
|
# Calculates the final velocity given initial velocity, acceleration, and time.
|
56
71
|
# @param initial_velocity [Int, Float]
|
57
|
-
# initial_velocity is in
|
72
|
+
# initial_velocity is in metres per second
|
58
73
|
# @param acceleration [Int, Float]
|
59
|
-
# acceleration is in
|
74
|
+
# acceleration is in metres per second squared
|
60
75
|
# @param time [Int, Float]
|
61
76
|
# time >= 0; time is in seconds
|
62
77
|
# @return [Float]
|
63
|
-
# return value is in
|
78
|
+
# return value is in metres per second
|
64
79
|
# @example
|
65
80
|
# Joules.final_velocity_v1(20, 6.25, 2.4) #=> 35.0
|
66
81
|
# @note There is one other method for calculating final velocity.
|
@@ -70,13 +85,13 @@ module Joules
|
|
70
85
|
|
71
86
|
# Calculates the final velocity given initial velocity, acceleration, and displacement.
|
72
87
|
# @param initial_velocity [Int, Float]
|
73
|
-
# initial_velocity is in
|
88
|
+
# initial_velocity is in metres per second
|
74
89
|
# @param acceleration [Int, Float]
|
75
|
-
# acceleration is in
|
90
|
+
# acceleration is in metres per second squared
|
76
91
|
# @param displacement [Int, Float]
|
77
|
-
# displacement is in
|
92
|
+
# displacement is in metres
|
78
93
|
# @return [Float]
|
79
|
-
# return value is in
|
94
|
+
# return value is in metres per second
|
80
95
|
# @example
|
81
96
|
# Joules.final_velocity_v2(20, 6.25, 66) #=> 35.0
|
82
97
|
# @note There is one other method for calculating final velocity.
|
@@ -86,13 +101,13 @@ module Joules
|
|
86
101
|
|
87
102
|
# Calculates the displacement given initial velocity, final velocity, and time.
|
88
103
|
# @param initial_velocity [Int, Float]
|
89
|
-
# initial_velocity is in
|
104
|
+
# initial_velocity is in metres per second
|
90
105
|
# @param final_velocity [Int, Float]
|
91
|
-
# final_velocity is in
|
106
|
+
# final_velocity is in metres per second
|
92
107
|
# @param time [Int, Float]
|
93
108
|
# time >= 0; time is in seconds
|
94
109
|
# @return [Float]
|
95
|
-
# return value is in
|
110
|
+
# return value is in metres
|
96
111
|
# @example
|
97
112
|
# Joules.displacement_v1(20, 35, 2.4) #=> 66.0
|
98
113
|
# @note There are two other methods for calculating displacement.
|
@@ -102,13 +117,13 @@ module Joules
|
|
102
117
|
|
103
118
|
# Calculates the displacement given initial velocity, acceleration, and time.
|
104
119
|
# @param initial_velocity [Int, Float]
|
105
|
-
# initial_velocity is in
|
120
|
+
# initial_velocity is in metres per second
|
106
121
|
# @param acceleration [Int, Float]
|
107
|
-
# acceleration is in
|
122
|
+
# acceleration is in metres per second squared
|
108
123
|
# @param time [Int, Float]
|
109
124
|
# time >= 0; time is in seconds
|
110
125
|
# @return [Float]
|
111
|
-
# return value is in
|
126
|
+
# return value is in metres
|
112
127
|
# @example
|
113
128
|
# Joules.displacement_v2(20, 6.25, 2.4) #=> 66.0
|
114
129
|
# @note There are two other methods for calculating displacement.
|
@@ -118,13 +133,13 @@ module Joules
|
|
118
133
|
|
119
134
|
# Calculates the displacement given final velocity, acceleration, and time.
|
120
135
|
# @param final_velocity [Int, Float]
|
121
|
-
# final_velocity is in
|
136
|
+
# final_velocity is in metres per second
|
122
137
|
# @param acceleration [Int, Float]
|
123
|
-
# acceleration is in
|
138
|
+
# acceleration is in metres per second squared
|
124
139
|
# @param time [Int, Float]
|
125
140
|
# time >= 0; time is in seconds
|
126
141
|
# @return [Float]
|
127
|
-
# return value is in
|
142
|
+
# return value is in metres
|
128
143
|
# @example
|
129
144
|
# Joules.displacement_v3(35, 6.25, 2.4) #=> 66.0
|
130
145
|
# @note There are two other methods for calculating displacement.
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#==============================================================================
|
2
|
+
# Joules
|
3
|
+
#
|
4
|
+
# @description: Module for providing magnetic fields formulas
|
5
|
+
# @author: Elisha Lai
|
6
|
+
# @version: 0.3.2 03/06/2015
|
7
|
+
#==============================================================================
|
8
|
+
|
9
|
+
# Magnetic fields module (magnetic_fields.rb)
|
10
|
+
|
11
|
+
module Joules
|
12
|
+
module_function
|
13
|
+
|
14
|
+
# Calculates the magnetic force on a current given flux density, current, and conductor length.
|
15
|
+
# @param flux_density [Int, Float]
|
16
|
+
# flux_density is in teslas
|
17
|
+
# @param current [Int, Float]
|
18
|
+
# current is in amperes
|
19
|
+
# @param conductor_length [Int, Float]
|
20
|
+
# conductor_length >= 0; conductor_length is in metres
|
21
|
+
# @param angle [Int, Float]
|
22
|
+
# angle is in degrees
|
23
|
+
# @return [Float]
|
24
|
+
# return value is in newtons
|
25
|
+
# @example
|
26
|
+
# Joules.magnetic_force_v1(0.06, 20, 4.5) #=> 5.3999999999999995
|
27
|
+
# @note There is one other method for calculating magnetic force.
|
28
|
+
def magnetic_force_v1(flux_density, current, conductor_length, angle = 90)
|
29
|
+
return flux_density * current * conductor_length * Math.sin(to_radians(angle))
|
30
|
+
end
|
31
|
+
|
32
|
+
# Calculates the magnetic force on a moving charge given flux density, charge, and velocity.
|
33
|
+
# @param flux_density [Int, Float]
|
34
|
+
# flux_density is in teslas
|
35
|
+
# @param charge [Int, Float]
|
36
|
+
# charge is in coulombs
|
37
|
+
# @param velocity [Int, Float]
|
38
|
+
# velocity is in metres per second
|
39
|
+
# @param angle [Int, Float]
|
40
|
+
# angle is in degrees
|
41
|
+
# @return [Float]
|
42
|
+
# return value is in newtons
|
43
|
+
# @example
|
44
|
+
# Joules.magnetic_force_v2(0.06, 34, 60) #=> 122.4
|
45
|
+
# @note There is one other method for calculating magnetic force.
|
46
|
+
def magnetic_force_v2(flux_density, charge, velocity, angle = 90)
|
47
|
+
return flux_density * charge * velocity * Math.sin(to_radians(angle))
|
48
|
+
end
|
49
|
+
|
50
|
+
# Calculates the magnetic flux given flux density and area.
|
51
|
+
# @param flux_density [Int, Float]
|
52
|
+
# flux_density is in teslas
|
53
|
+
# @param area [Int, Float]
|
54
|
+
# area >= 0; area is in metres squared
|
55
|
+
# @param angle [Int, Float]
|
56
|
+
# angle is in degrees
|
57
|
+
# @return [Float]
|
58
|
+
# return value is in webers
|
59
|
+
# @example
|
60
|
+
# Joules.magnetic_flux(0.945, 9e-4) #=> 0.0008504999999999999
|
61
|
+
def magnetic_flux(flux_density, area, angle = 0)
|
62
|
+
return flux_density * area * Math.cos(to_radians(angle))
|
63
|
+
end
|
64
|
+
|
65
|
+
# Calculates the magnetic flux linkage given magnetic flux and number of coils in the wire.
|
66
|
+
# @param magnetic_flux [Int, Float]
|
67
|
+
# magnetic_flux is in webers
|
68
|
+
# @param number_of_coils [Int, Float]
|
69
|
+
# number_of_coils >= 0
|
70
|
+
# @return [Float]
|
71
|
+
# return value is in webers
|
72
|
+
# @example
|
73
|
+
# Joules.magnetic_flux_linkage(9.4, 10) #=> 94.0
|
74
|
+
def magnetic_flux_linkage(magnetic_flux, number_of_coils)
|
75
|
+
return magnetic_flux * number_of_coils.to_f
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
data/lib/joules/mass_weight.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
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.2 03/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Mass and weight module (mass_weight.rb)
|
@@ -3,7 +3,7 @@
|
|
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.2 03/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Momentum and impulse module (momentum_impulse.rb)
|
@@ -15,7 +15,7 @@ module Joules
|
|
15
15
|
# @param mass [Int, Float]
|
16
16
|
# mass >= 0; mass is in kilograms
|
17
17
|
# @param velocity [Int, Float]
|
18
|
-
# velocity is in
|
18
|
+
# velocity is in metres per second
|
19
19
|
# @return [Float]
|
20
20
|
# return value is in newton seconds
|
21
21
|
# @example
|
@@ -40,9 +40,9 @@ module Joules
|
|
40
40
|
|
41
41
|
# Calculates the impulse given initial velocity, final velocity, and mass.
|
42
42
|
# @param initial_velocity [Int, Float]
|
43
|
-
# initial_velocity is in
|
43
|
+
# initial_velocity is in metres per second
|
44
44
|
# @param final_velocity [Int, Float]
|
45
|
-
# final_velocity is in
|
45
|
+
# final_velocity is in metres per second
|
46
46
|
# @param mass [Int, Float]
|
47
47
|
# mass >= 0; mass is in kilograms
|
48
48
|
# @return [Float]
|
data/lib/joules/pressure.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing pressure formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.2 03/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Pressure module (pressure.rb)
|
@@ -15,20 +15,25 @@ module Joules
|
|
15
15
|
# @param force [Int, Float]
|
16
16
|
# force >= 0; force is in newtons
|
17
17
|
# @param area [Int, Float]
|
18
|
-
# area > 0; area is in
|
18
|
+
# area > 0; area is in metres squared
|
19
19
|
# @return [Float]
|
20
20
|
# return value >= 0; return value is in pascals
|
21
|
+
# @raise [ZeroDivisionError] if area = 0
|
21
22
|
# @example
|
22
23
|
# Joules.pressure(98, 0.04) #=> 2450.0
|
23
24
|
def pressure(force, area)
|
24
|
-
|
25
|
+
if area.zero?
|
26
|
+
raise ZeroDivisionError.new('divided by 0')
|
27
|
+
else
|
28
|
+
return force / area.to_f
|
29
|
+
end
|
25
30
|
end
|
26
31
|
|
27
32
|
# Calculates the hydrostatic pressure given density and height.
|
28
33
|
# @param density [Int, Float]
|
29
|
-
# density >= 0; density is in kilograms per
|
34
|
+
# density >= 0; density is in kilograms per metre cubed
|
30
35
|
# @param height [Int, Float]
|
31
|
-
# height >= 0; height is in
|
36
|
+
# height >= 0; height is in metres
|
32
37
|
# @return [Float]
|
33
38
|
# return value >= 0; return value is in pascals
|
34
39
|
# @example
|
data/lib/joules/quantum.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing quantum formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.2 03/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Quantum module (quantum.rb)
|
@@ -39,10 +39,15 @@ module Joules
|
|
39
39
|
# decay_constant != 0; decay_constant is in per second
|
40
40
|
# @return [Float]
|
41
41
|
# return value is in seconds
|
42
|
+
# @raise [ZeroDivisionError] if decay_constant = 0
|
42
43
|
# @example
|
43
44
|
# Joules.half_life(7.7e4) #=> 9.001911435843445e-06
|
44
45
|
def half_life(decay_constant)
|
45
|
-
|
46
|
+
if decay_constant.zero?
|
47
|
+
raise ZeroDivisionError.new('divided by 0')
|
48
|
+
else
|
49
|
+
return Math.log(2) / decay_constant
|
50
|
+
end
|
46
51
|
end
|
47
52
|
|
48
53
|
# Calculates the decay constant of a decaying quantity given half-life.
|
@@ -50,10 +55,15 @@ module Joules
|
|
50
55
|
# half_life != 0; half_life is in seconds
|
51
56
|
# @return [Float]
|
52
57
|
# return value is in per second
|
58
|
+
# @raise [ZeroDivisionError] if half_life = 0
|
53
59
|
# @example
|
54
60
|
# Joules.decay_constant(9) #=> 0.0770163533955495
|
55
61
|
def decay_constant(half_life)
|
56
|
-
|
62
|
+
if half_life.zero?
|
63
|
+
raise ZeroDivisionError.new('divided by 0')
|
64
|
+
else
|
65
|
+
return Math.log(2) / half_life
|
66
|
+
end
|
57
67
|
end
|
58
68
|
|
59
69
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#==============================================================================
|
2
|
+
# Joules
|
3
|
+
#
|
4
|
+
# @description: Module for providing stress and strain formulas
|
5
|
+
# @author: Elisha Lai
|
6
|
+
# @version: 0.3.2 03/06/2015
|
7
|
+
#==============================================================================
|
8
|
+
|
9
|
+
# Stress and strain module (stress_strain.rb)
|
10
|
+
|
11
|
+
module Joules
|
12
|
+
module_function
|
13
|
+
|
14
|
+
# Calculates the tensile stress 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 metres squared
|
19
|
+
# @return [Float]
|
20
|
+
# return value >= 0; return value is in pascals
|
21
|
+
# @raise [ZeroDivisionError] if area = 0
|
22
|
+
# @example
|
23
|
+
# Joules.tensile_stress(98, 0.04) #=> 2450.0
|
24
|
+
def tensile_stress(force, area)
|
25
|
+
if area.zero?
|
26
|
+
raise ZeroDivisionError.new('divided by 0')
|
27
|
+
else
|
28
|
+
return force / area.to_f
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Calculates the tensile strain given extension and length.
|
33
|
+
# @param extension [Int, Float]
|
34
|
+
# extension >= 0; extension is in metres
|
35
|
+
# @param length [Int, Float]
|
36
|
+
# length > 0; length is in metres
|
37
|
+
# @return [Float]
|
38
|
+
# return value >= 0
|
39
|
+
# @raise [ZeroDivisionError] if length = 0
|
40
|
+
# @example
|
41
|
+
# Joules.tensile_strain(2, 10) #=> 0.2
|
42
|
+
def tensile_strain(extension, length)
|
43
|
+
if length.zero?
|
44
|
+
raise ZeroDivisionError.new('divided by 0')
|
45
|
+
else
|
46
|
+
return extension / length.to_f
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Calculates the Young modulus given tensile stress and tensile strain.
|
51
|
+
# @param tensile_stress [Int, Float]
|
52
|
+
# tensile_stress >= 0; tensile_stress is in pascals
|
53
|
+
# @param tensile_strain [Int, Float]
|
54
|
+
# tensile_strain > 0
|
55
|
+
# @return [Float]
|
56
|
+
# return value >= 0; return value is in pascals
|
57
|
+
# @raise [ZeroDivisionError] if tensile_strain = 0
|
58
|
+
# @example
|
59
|
+
# Joules.young_modulus(2450, 0.2) #=> 12250.0
|
60
|
+
def young_modulus(tensile_stress, tensile_strain)
|
61
|
+
if tensile_strain.zero?
|
62
|
+
raise ZeroDivisionError.new('divided by 0')
|
63
|
+
else
|
64
|
+
return tensile_stress / tensile_strain.to_f
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing thermodynamics formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.2 03/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Thermodynamics module (thermodynamics.rb)
|