joules 0.0.3 → 0.1.0
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/lib/joules/constants.rb +39 -27
- data/lib/joules/density.rb +10 -12
- data/lib/joules/energy_work_power.rb +64 -70
- data/lib/joules/forces.rb +44 -41
- data/lib/joules/kinematics.rb +90 -84
- data/lib/joules/mass_weight.rb +15 -17
- data/lib/joules/momentum_impulse.rb +32 -29
- data/lib/joules/pressure.rb +19 -23
- data/lib/joules/thermodynamics.rb +39 -0
- data/lib/joules/waves.rb +72 -0
- data/lib/joules.rb +3 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 309af22d22628f2fecec4180108382f0edc324a9
|
4
|
+
data.tar.gz: 0729618e8e982c76cdecb3b9f30939c1e422e788
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93f6ca64737cfe6099ebf0fd9f8593591187f14b3e0ced850c2e152fab903044e66a587aa3a20a96a34cf43242ff4371272de7a595d6996b1d9b8c43a36f9d44
|
7
|
+
data.tar.gz: bb671926e1b41cb3e8d8e7678152b7fcc8ee9673f6a458c4af7ac1e8c97117368b79f224e0e4f99be662481039254ecfb442625d32f263e6262b45e95c4a756f
|
data/lib/joules/constants.rb
CHANGED
@@ -3,59 +3,71 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing constants
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.0
|
6
|
+
# @version: 0.1.0 23/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Constants module (constants.rb)
|
10
10
|
|
11
|
-
# Speed of light in free space
|
12
|
-
#
|
11
|
+
# Speed of light in free space.
|
12
|
+
# @note This quantity is in meters per second.
|
13
13
|
SPEED_OF_LIGHT = 3.00e8
|
14
14
|
|
15
|
-
# Permeability of free space
|
16
|
-
#
|
15
|
+
# Permeability of free space.
|
16
|
+
# @note This quantity is in henries per meter.
|
17
17
|
FREE_SPACE_PERMEABILITY = 4 * Math::PI * 1e-7
|
18
18
|
|
19
|
-
# Permittivity of free space
|
20
|
-
#
|
19
|
+
# Permittivity of free space.
|
20
|
+
# @note This quantity is in farads per meter.
|
21
21
|
FREE_SPACE_PERMITTIVITY = 8.85e-12
|
22
22
|
|
23
|
-
# Elementary charge
|
24
|
-
#
|
23
|
+
# Elementary charge.
|
24
|
+
# @note This quantity is in coulombs.
|
25
25
|
ELEMENTARY_CHARGE = 1.6e-19
|
26
26
|
|
27
|
-
# Planck constant
|
28
|
-
#
|
27
|
+
# Planck constant.
|
28
|
+
# @note This quantity is in joule seconds.
|
29
29
|
PLANCK_CONSTANT = 6.63e-34
|
30
30
|
|
31
|
-
# Unified atomic mass unit
|
32
|
-
#
|
31
|
+
# Unified atomic mass unit.
|
32
|
+
# @note This quantiy is in kilograms.
|
33
33
|
UNIFIED_ATOMIC_MASS_UNIT = 1.66e-27
|
34
34
|
|
35
|
-
# Rest mass of electron
|
36
|
-
#
|
35
|
+
# Rest mass of electron.
|
36
|
+
# @note This quantity is in kilograms.
|
37
37
|
ELECTRON_MASS = 9.11e-31
|
38
38
|
|
39
|
-
# Rest mass of proton
|
40
|
-
#
|
39
|
+
# Rest mass of proton.
|
40
|
+
# @note This quantity is in kilograms.
|
41
41
|
PROTON_MASS = 1.67e-27
|
42
42
|
|
43
|
-
#
|
44
|
-
#
|
43
|
+
# Rest mass of neutron.
|
44
|
+
# @note This quantity is in kilograms.
|
45
|
+
NEUTRON_MASS = 1.67e-27
|
46
|
+
|
47
|
+
# Molar gas constant.
|
48
|
+
# @note This quantity is in joules per kelvin mole.
|
45
49
|
MOLAR_GAS_CONSTANT = 8.31
|
46
50
|
|
47
|
-
# Avogadro constant
|
48
|
-
#
|
51
|
+
# Avogadro constant.
|
52
|
+
# @note This quantity is in per mole.
|
49
53
|
AVOGADRO_CONSTANT = 6.02e23
|
50
54
|
|
51
|
-
# Boltzmann constant
|
52
|
-
#
|
55
|
+
# Boltzmann constant.
|
56
|
+
# @note This quantity is in joules per kelvin.
|
53
57
|
BOLTZMANN_CONSTANT = 1.38e-23
|
54
58
|
|
55
|
-
#
|
56
|
-
#
|
59
|
+
# Stefan constant.
|
60
|
+
# @note This quantity is in watts per meter squared kelvin to the fourth power.
|
61
|
+
STEFAN_CONSTANT = 5.67e-8
|
62
|
+
|
63
|
+
# Wien constant.
|
64
|
+
# @note This quantity is in meter kelvins.
|
65
|
+
WIEN_CONSTANT = 2.9e-3
|
66
|
+
|
67
|
+
# Gravitational constant.
|
68
|
+
# @note This quantity is in newton metres squared per kilogram squared.
|
57
69
|
GRAVITATIONAL_CONSTANT = 6.67e-11
|
58
70
|
|
59
|
-
# Acceleration of free fall
|
60
|
-
#
|
71
|
+
# Acceleration of free fall.
|
72
|
+
# @note This quantity is in meters per second squared.
|
61
73
|
FREE_FALL_ACCELERATION = 9.81
|
data/lib/joules/density.rb
CHANGED
@@ -3,22 +3,20 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing density formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.0
|
6
|
+
# @version: 0.1.0 23/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Density module (density.rb)
|
10
10
|
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
# Purpose: Consumes two numbers, mass and volume. Returns the
|
21
|
-
# calculated density.
|
11
|
+
# Calculates the density given mass and volume.
|
12
|
+
# @param mass [Int, Float]
|
13
|
+
# mass >= 0; mass is in kilograms
|
14
|
+
# @param volume [Int, Float]
|
15
|
+
# volume > 0; volume is in meters cubed
|
16
|
+
# @return [Float]
|
17
|
+
# returned value >= 0; returned value is in kilograms per meter cubed
|
18
|
+
# @example
|
19
|
+
# density(8.96, 0.002) #=> 4480.0
|
22
20
|
def density(mass, volume)
|
23
21
|
return mass / volume.to_f
|
24
22
|
end
|
@@ -3,106 +3,100 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing energy, work, and power formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.0
|
6
|
+
# @version: 0.1.0 23/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Energy, work, and power module (energy_work_power.rb)
|
10
10
|
|
11
11
|
require_relative 'constants'
|
12
12
|
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
# returned value is in joules.
|
23
|
-
# Purpose: Consumes two numbers, mass and height. Returns the calculated
|
24
|
-
# gravitational potential energy.
|
13
|
+
# Calculates the gravitational potential energy given mass and height.
|
14
|
+
# @param mass [Int, Float]
|
15
|
+
# mass >= 0; mass is in kilograms
|
16
|
+
# @param height [Int, Float]
|
17
|
+
# height >= 0; height is in meters
|
18
|
+
# @return [Float]
|
19
|
+
# returned value >= 0; returned value is in joules
|
20
|
+
# @example
|
21
|
+
# gravitational_potential_energy(0.5, 6) #=> 29.43
|
25
22
|
def gravitational_potential_energy(mass, height)
|
26
23
|
return mass * FREE_FALL_ACCELERATION * height
|
27
24
|
end
|
28
25
|
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
# Purpose: Consumes two numbers, spring_constant and extension. Returns
|
39
|
-
# the calculated elastic potential energy.
|
26
|
+
# Calculates the elastic potential energy given spring constant and extension.
|
27
|
+
# @param spring_constant [Int, Float]
|
28
|
+
# spring_constant >= 0; spring_constant is in newtons per meter
|
29
|
+
# @param extension [Int, Float]
|
30
|
+
# extension >= 0; extension is in meters
|
31
|
+
# @return [Float]
|
32
|
+
# returned value is in joules
|
33
|
+
# @example
|
34
|
+
# elastic_potential_energy(81.75, 2.4) #=> 235.44
|
40
35
|
def elastic_potential_energy(spring_constant, extension)
|
41
36
|
return 0.5 * spring_constant * (extension ** 2)
|
42
37
|
end
|
43
38
|
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
# kinetic energy.
|
39
|
+
# Calculates the kinetic energy given mass and velocity.
|
40
|
+
# @param mass [Int, Float]
|
41
|
+
# mass >= 0; mass is in kilograms
|
42
|
+
# @param velocity [Int, Float]
|
43
|
+
# velocity is in meters per second
|
44
|
+
# @return [Float]
|
45
|
+
# returned value >= 0; returned value is in joules
|
46
|
+
# @example
|
47
|
+
# kinetic_energy(500, 22) #=> 121000.0
|
54
48
|
def kinetic_energy(mass, velocity)
|
55
49
|
return 0.5 * mass * (velocity ** 2)
|
56
50
|
end
|
57
51
|
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
52
|
+
# Calculates the work done given force and distance.
|
53
|
+
# @param force [Int, Float]
|
54
|
+
# force is in newtons
|
55
|
+
# @param distance [Int, Float]
|
56
|
+
# distance >= 0; distance is in meters
|
57
|
+
# @return [Float]
|
58
|
+
# returned value is in joules
|
59
|
+
# @example
|
60
|
+
# work_done(40, 2.34) #=> 93.6
|
67
61
|
def work_done(force, distance)
|
68
62
|
return force * distance.to_f
|
69
63
|
end
|
70
64
|
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
65
|
+
# Calculates the power given work done and time.
|
66
|
+
# @param work_done [Int, Float]
|
67
|
+
# work_done is in joules
|
68
|
+
# @param time [Int, Float]
|
69
|
+
# time > 0; time is in seconds
|
70
|
+
# @return [Float]
|
71
|
+
# returned value is in watts
|
72
|
+
# @example
|
73
|
+
# power(28, 7) #=> 4.0
|
80
74
|
def power(work_done, time)
|
81
75
|
return work_done / time.to_f
|
82
76
|
end
|
83
77
|
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
78
|
+
# Calculates the energy efficiency given useful energy output and energy input.
|
79
|
+
# @param useful_energy_output [Int, Float]
|
80
|
+
# 0 <= useful_energy_output <= energy_input; useful_energy_output is in joules
|
81
|
+
# @param energy_input [Int, Float]
|
82
|
+
# energy_input > 0; energy_input is in joules
|
83
|
+
# @return [Float]
|
84
|
+
# returned value >= 0
|
85
|
+
# @example
|
86
|
+
# energy_efficiency(16, 20) #=> 80.0
|
93
87
|
def energy_efficiency(useful_energy_output, energy_input)
|
94
88
|
return (useful_energy_output / energy_input.to_f) * 100
|
95
89
|
end
|
96
90
|
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
#
|
102
|
-
#
|
103
|
-
#
|
104
|
-
#
|
105
|
-
#
|
91
|
+
# Calculates the power efficiency given useful power output and power input.
|
92
|
+
# @param useful_power_output [Int, Float]
|
93
|
+
# 0 <= useful_power_output <= power_input; useful_power_output is in watts
|
94
|
+
# @param power_input [Int, Float]
|
95
|
+
# power_input > 0; power_input is in watts
|
96
|
+
# @return [Float]
|
97
|
+
# returned value >= 0
|
98
|
+
# @example
|
99
|
+
# power_efficiency(26, 40) #=> 65.0
|
106
100
|
def power_efficiency(useful_power_output, power_input)
|
107
101
|
return (useful_power_output / power_input.to_f) * 100
|
108
102
|
end
|
data/lib/joules/forces.rb
CHANGED
@@ -3,63 +3,66 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing forces formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.0
|
6
|
+
# @version: 0.1.0 23/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Forces module (forces.rb)
|
10
10
|
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
11
|
+
# Calculates the force given mass and acceleration.
|
12
|
+
# @param mass [Int, Float]
|
13
|
+
# mass >= 0; mass is in kilograms
|
14
|
+
# @param acceleration [Int, Float]
|
15
|
+
# acceleration is in meters per second squared
|
16
|
+
# @return [Float]
|
17
|
+
# returned value is in newtons
|
18
|
+
# @example
|
19
|
+
# force_v1(120, 2.67) #=> 320.4
|
20
|
+
# @note There are two other methods for calculating force.
|
20
21
|
def force_v1(mass, acceleration)
|
21
22
|
return mass * acceleration.to_f
|
22
23
|
end
|
23
24
|
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
# calculated force.
|
25
|
+
# Calculates the force given spring constant and extension.
|
26
|
+
# @param spring_constant [Int, Float]
|
27
|
+
# spring_constant >= 0; spring_constant is in newtons per meter
|
28
|
+
# @param extension [Int, Float]
|
29
|
+
# extension >= 0; extension is in meters
|
30
|
+
# @return [Float]
|
31
|
+
# returned value >= 0; returned value is in newtons
|
32
|
+
# @example
|
33
|
+
# force_v2(81.75, 2.4) #=> 196.2
|
34
|
+
# @note There are two other methods for calculating force.
|
35
35
|
def force_v2(spring_constant, extension)
|
36
36
|
return spring_constant * extension.to_f
|
37
37
|
end
|
38
38
|
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
39
|
+
# Calculates the force given initial velocity, final velocity, mass, and time.
|
40
|
+
# @param initial_velocity [Int, Float]
|
41
|
+
# initial_velocity is in meters per second
|
42
|
+
# @param final_velocity [Int, Float]
|
43
|
+
# final_velocity is in meters per second
|
44
|
+
# @param mass [Int, Float]
|
45
|
+
# mass >= 0; mass is in kilograms
|
46
|
+
# @param time [Int, Float]
|
47
|
+
# time > 0; time is in seconds
|
48
|
+
# @return [Float]
|
49
|
+
# returned value is in newtons
|
50
|
+
# @example
|
51
|
+
# force_v3(20, 35, 50, 2.4) #=> 312.5
|
52
|
+
# @note There are two other methods for calculating force.
|
50
53
|
def force_v3(initial_velocity, final_velocity, mass, time)
|
51
54
|
return ((final_velocity - initial_velocity) * mass) / time.to_f
|
52
55
|
end
|
53
56
|
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
57
|
+
# Calculates the moment given force and distance.
|
58
|
+
# @param force [Int, Float]
|
59
|
+
# force is in newtons
|
60
|
+
# @param distance [Int, Float]
|
61
|
+
# distance >= 0; distance is in meters
|
62
|
+
# @return [Float]
|
63
|
+
# returned value is in newton metres
|
64
|
+
# @example
|
65
|
+
# moment(23, 4.5) #=> 103.5
|
63
66
|
def moment(force, distance)
|
64
67
|
return force * distance.to_f
|
65
68
|
end
|
data/lib/joules/kinematics.rb
CHANGED
@@ -3,122 +3,128 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing kinematics formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.0
|
6
|
+
# @version: 0.1.0 23/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Kinematics module (kinematics.rb)
|
10
10
|
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
# Purpose: Consumes two numbers, distance and time. Returns the
|
21
|
-
# calculated average speed.
|
11
|
+
# Calculates the average speed given distance and time.
|
12
|
+
# @param distance [Int, Float]
|
13
|
+
# distance >= 0; distance is in meters
|
14
|
+
# @param time [Int, Float]
|
15
|
+
# time > 0; time is in seconds
|
16
|
+
# @return [Float]
|
17
|
+
# returned value >= 0; returned value is in meters per second
|
18
|
+
# @example
|
19
|
+
# avg_speed(30, 2.4) #=> 12.5
|
22
20
|
def avg_speed(distance, time)
|
23
21
|
return distance / time.to_f
|
24
22
|
end
|
25
23
|
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
24
|
+
# Calculates the average velocity given displacement and time.
|
25
|
+
# @param displacement [Int, Float]
|
26
|
+
# displacement is in meters
|
27
|
+
# @param time [Int, Float]
|
28
|
+
# time > 0; time is in seconds
|
29
|
+
# @return [Float]
|
30
|
+
# returned value is in meters per second
|
31
|
+
# @example
|
32
|
+
# avg_velocity(180, 4.8) #=> 37.5
|
35
33
|
def avg_velocity(displacement, time)
|
36
34
|
return displacement / time.to_f
|
37
35
|
end
|
38
36
|
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
37
|
+
# Calculates the acceleration given initial velocity, final velocity, and time.
|
38
|
+
# @param initial_velocity [Int, Float]
|
39
|
+
# initial_velocity is in meters per second
|
40
|
+
# @param final_velocity [Int, Float]
|
41
|
+
# final_velocity is in meters per second
|
42
|
+
# @param time [Int, Float]
|
43
|
+
# time > 0; time is in seconds
|
44
|
+
# @return [Float]
|
45
|
+
# returned value is in meters per second squared
|
46
|
+
# @example
|
47
|
+
# acceleration(20, 35, 2.4) #=> 6.25
|
49
48
|
def acceleration(initial_velocity, final_velocity, time)
|
50
49
|
return (final_velocity - initial_velocity) / time.to_f
|
51
50
|
end
|
52
51
|
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
52
|
+
# Calculates the final velocity given initial velocity, acceleration, and time.
|
53
|
+
# @param initial_velocity [Int, Float]
|
54
|
+
# initial_velocity is in meters per second
|
55
|
+
# @param acceleration [Int, Float]
|
56
|
+
# acceleration is in meters per second squared
|
57
|
+
# @param time [Int, Float]
|
58
|
+
# time >= 0; time is in seconds
|
59
|
+
# @return [Float]
|
60
|
+
# returned value is in meters per second
|
61
|
+
# @example
|
62
|
+
# final_velocity_v1(20, 6.25, 2.4) #=> 35.0
|
63
|
+
# @note There is one other method for calculating final velocity.
|
64
64
|
def final_velocity_v1(initial_velocity, acceleration, time)
|
65
65
|
return initial_velocity + (acceleration * time.to_f)
|
66
66
|
end
|
67
67
|
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
68
|
+
# Calculates the final velocity given initial velocity, acceleration, and displacement.
|
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 displacement [Int, Float]
|
74
|
+
# displacement is in meters
|
75
|
+
# @return [Float]
|
76
|
+
# returned value is in meters per second
|
77
|
+
# @example
|
78
|
+
# final_velocity_v2(20, 6.25, 66) #=> 35.0
|
79
|
+
# @note There is one other method for calculating final velocity.
|
78
80
|
def final_velocity_v2(initial_velocity, acceleration, displacement)
|
79
81
|
return ((initial_velocity ** 2) + (2 * acceleration * displacement)) ** 0.5
|
80
82
|
end
|
81
83
|
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
91
|
-
#
|
84
|
+
# Calculates the displacement given initial velocity, final velocity, and time.
|
85
|
+
# @param initial_velocity [Int, Float]
|
86
|
+
# initial_velocity is in meters per second
|
87
|
+
# @param final_velocity [Int, Float]
|
88
|
+
# final_velocity is in meters per second
|
89
|
+
# @param time [Int, Float]
|
90
|
+
# time >= 0; time is in seconds
|
91
|
+
# @return [Float]
|
92
|
+
# returned value is in meters
|
93
|
+
# @example
|
94
|
+
# displacement_v1(20, 35, 2.4) #=> 66.0
|
95
|
+
# @note There are two other methods for calculating displacement.
|
92
96
|
def displacement_v1(initial_velocity, final_velocity, time)
|
93
97
|
return 0.5 * (initial_velocity + final_velocity) * time
|
94
98
|
end
|
95
99
|
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
#
|
102
|
-
#
|
103
|
-
#
|
104
|
-
#
|
105
|
-
#
|
106
|
-
#
|
100
|
+
# Calculates the displacement given initial velocity, acceleration, and time.
|
101
|
+
# @param initial_velocity [Int, Float]
|
102
|
+
# initial_velocity is in meters per second
|
103
|
+
# @param acceleration [Int, Float]
|
104
|
+
# acceleration is in meters per second squared
|
105
|
+
# @param time [Int, Float]
|
106
|
+
# time >= 0; time is in seconds
|
107
|
+
# @return [Float]
|
108
|
+
# returned value is in meters
|
109
|
+
# @example
|
110
|
+
# displacement_v2(20, 6.25, 2.4) #=> 66.0
|
111
|
+
# @note There are two other methods for calculating displacement.
|
107
112
|
def displacement_v2(initial_velocity, acceleration, time)
|
108
113
|
return (initial_velocity * time) + (0.5 * acceleration * (time ** 2))
|
109
114
|
end
|
110
115
|
|
111
|
-
#
|
112
|
-
#
|
113
|
-
#
|
114
|
-
#
|
115
|
-
#
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
#
|
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
|
+
# returned 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.
|
122
128
|
def displacement_v3(final_velocity, acceleration, time)
|
123
129
|
return (final_velocity * time) - (0.5 * acceleration * (time ** 2))
|
124
130
|
end
|
data/lib/joules/mass_weight.rb
CHANGED
@@ -3,33 +3,31 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing mass and weight formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.0
|
6
|
+
# @version: 0.1.0 23/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Mass and weight module (mass_weight.rb)
|
10
10
|
|
11
11
|
require_relative 'constants'
|
12
12
|
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
# Purpose: Consumes a number, mass, and returns the calculated weight.
|
13
|
+
# Calculates the weight given mass.
|
14
|
+
# @param mass [Int, Float]
|
15
|
+
# mass >= 0; mass is in kilograms
|
16
|
+
# @return [Float]
|
17
|
+
# returned value >= 0; returned value is in newtons
|
18
|
+
# @example
|
19
|
+
# weight(79.41) #=> 779.0121
|
21
20
|
def weight(mass)
|
22
21
|
return mass * FREE_FALL_ACCELERATION
|
23
22
|
end
|
24
23
|
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
# Purpose: Consumes a numberm weight, and returns the calculated mass.
|
24
|
+
# Calculates the mass given weight.
|
25
|
+
# @param weight [Int, Float]
|
26
|
+
# weight >= 0; weight is in newtons
|
27
|
+
# @return [Float]
|
28
|
+
# returned value >= 0; returned value is in kilograms
|
29
|
+
# @example
|
30
|
+
# mass(779.0121) #=> 79.41
|
33
31
|
def mass(weight)
|
34
32
|
return weight / FREE_FALL_ACCELERATION
|
35
33
|
end
|
@@ -3,47 +3,50 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing momentum and impulse formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.0
|
6
|
+
# @version: 0.1.0 23/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Momentum and impulse module (momentum_impulse.rb)
|
10
10
|
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
11
|
+
# Calculates the momentum given mass and velocity.
|
12
|
+
# @param mass [Int, Float]
|
13
|
+
# mass >= 0; mass is in kilograms
|
14
|
+
# @param velocity [Int, Float]
|
15
|
+
# velocity is in meters per second
|
16
|
+
# @return [Float]
|
17
|
+
# returned value is in newton seconds
|
18
|
+
# @example
|
19
|
+
# momentum(52, 4.7) #=> 244.4
|
20
20
|
def momentum(mass, velocity)
|
21
21
|
return mass * velocity.to_f
|
22
22
|
end
|
23
23
|
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
24
|
+
# Calculates the impulse given force and time.
|
25
|
+
# @param force [Int, Float]
|
26
|
+
# force is in newtons
|
27
|
+
# @param time [Int, Float]
|
28
|
+
# time >= 0; time is in seconds
|
29
|
+
# @return [Float]
|
30
|
+
# returned value is in newton seconds
|
31
|
+
# @example
|
32
|
+
# impulse_v1(30.8, 9.6) #=> 295.68
|
33
|
+
# @note There is one other method for calculating impulse.
|
33
34
|
def impulse_v1(force, time)
|
34
35
|
return force * time.to_f
|
35
36
|
end
|
36
37
|
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
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
|
+
# returned 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.
|
47
50
|
def impulse_v2(initial_velocity, final_velocity, mass)
|
48
51
|
return (final_velocity - initial_velocity) * mass.to_f
|
49
52
|
end
|
data/lib/joules/pressure.rb
CHANGED
@@ -3,39 +3,35 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing pressure formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.0
|
6
|
+
# @version: 0.1.0 23/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Pressure module (pressure.rb)
|
10
10
|
|
11
11
|
require_relative 'constants'
|
12
12
|
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
# Purpose: Consumes two numbers, force and area. Returns the calculated
|
23
|
-
# pressure.
|
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
|
+
# returned value >= 0; returned value is in pascals
|
20
|
+
# @example
|
21
|
+
# pressure(98, 0.04) #=> 2450.0
|
24
22
|
def pressure(force, area)
|
25
23
|
return force / area.to_f
|
26
24
|
end
|
27
25
|
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# Purpose: Consumes two numbers, density and height. Returns the calculated
|
38
|
-
# hydrostatic pressure.
|
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
|
+
# returned value >= 0; returned value is in pascals
|
33
|
+
# @example
|
34
|
+
# hydrostatic_pressure(1000, 5) #=> 49050.0
|
39
35
|
def hydrostatic_pressure(density, height)
|
40
36
|
return density * FREE_FALL_ACCELERATION * height
|
41
37
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#==============================================================================
|
2
|
+
# Joules
|
3
|
+
#
|
4
|
+
# @description: Module for providing thermodynamics formulas
|
5
|
+
# @author: Elisha Lai
|
6
|
+
# @version: 0.1.0 23/05/2015
|
7
|
+
#==============================================================================
|
8
|
+
|
9
|
+
# Thermodynamics module (thermodynamics.rb)
|
10
|
+
|
11
|
+
# Calculates the energy given mass, specific heat capacity, and temperature change.
|
12
|
+
# @param mass [Int, Float]
|
13
|
+
# mass >= 0; mass is in kilograms
|
14
|
+
# @param specific_heat_capacity [Int, Float]
|
15
|
+
# specific_heat_capacity >= 0; specific_heat_capacity is in joules per kilogram celcius
|
16
|
+
# @param temperature_change [Int, Float]
|
17
|
+
# temperature_change is in celcius
|
18
|
+
# @return [Float]
|
19
|
+
# returned value is in joules
|
20
|
+
# @example
|
21
|
+
# energy_v1(500, 2.46, 3.6) #=> 4428.0
|
22
|
+
# @note There is one other method for calculating energy.
|
23
|
+
def energy_v1(mass, specific_heat_capacity, temperature_change)
|
24
|
+
return mass * specific_heat_capacity * temperature_change.to_f
|
25
|
+
end
|
26
|
+
|
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
|
+
# returned value is in joules
|
34
|
+
# @example
|
35
|
+
# energy_v2(84.3, 72.1) #=> 6078.03
|
36
|
+
# @note There is one other method for calculating energy.
|
37
|
+
def energy_v2(mass, specific_latent_heat)
|
38
|
+
return mass * specific_latent_heat.to_f
|
39
|
+
end
|
data/lib/joules/waves.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
#==============================================================================
|
2
|
+
# Joules
|
3
|
+
#
|
4
|
+
# @description: Module for providing waves formulas
|
5
|
+
# @author: Elisha Lai
|
6
|
+
# @version: 0.1.0 23/05/2015
|
7
|
+
#==============================================================================
|
8
|
+
|
9
|
+
# Waves module (waves.rb)
|
10
|
+
|
11
|
+
# Calculates the wave speed given frequency and wavelength.
|
12
|
+
# @param frequency [Int, Float]
|
13
|
+
# frequency > 0; frequency is in hertz
|
14
|
+
# @param wavelength [Int, Float]
|
15
|
+
# wavelength >= 0; wavelength is in meters
|
16
|
+
# @return [Float]
|
17
|
+
# returned value >= 0; returned value is in meters per second
|
18
|
+
# @example
|
19
|
+
# wave_speed(3250, 0.1) #=> 325.0
|
20
|
+
def wave_speed(frequency, wavelength)
|
21
|
+
return frequency * wavelength.to_f
|
22
|
+
end
|
23
|
+
|
24
|
+
# Calculates the wavelength given wave speed and frequency.
|
25
|
+
# @param wave_speed [Int, Float]
|
26
|
+
# wave_speed >= 0; wave_speed is in meters per second
|
27
|
+
# @param frequency [Int, Float]
|
28
|
+
# frequency > 0; frequency is in hertz
|
29
|
+
# @return [Float]
|
30
|
+
# returned value is in meters
|
31
|
+
# @example
|
32
|
+
# wavelength(325, 3250) #=> 0.1
|
33
|
+
def wavelength(wave_speed, frequency)
|
34
|
+
return wave_speed / frequency.to_f
|
35
|
+
end
|
36
|
+
|
37
|
+
# Calculates the frequency given wave speed and wavelength.
|
38
|
+
# @param wave_speed [Int, Float]
|
39
|
+
# wave_speed >= 0; wave_speed is in meters per second
|
40
|
+
# @param wavelength [Int, Float]
|
41
|
+
# wavelength > 0; wavelength is in meters
|
42
|
+
# @return [Float]
|
43
|
+
# returned value is in hertz
|
44
|
+
# @example
|
45
|
+
# frequency_v1(325, 0.1) #=> 3250.0
|
46
|
+
# @note There is one other method for calculating frequency.
|
47
|
+
def frequency_v1(wave_speed, wavelength)
|
48
|
+
return wave_speed / wavelength.to_f
|
49
|
+
end
|
50
|
+
|
51
|
+
# Calculates the frequency given time period.
|
52
|
+
# @param time_period [Int, Float]
|
53
|
+
# time_period > 0; time_period is in seconds
|
54
|
+
# @return [Float]
|
55
|
+
# returned value > 0; returned value is in hertz
|
56
|
+
# @example
|
57
|
+
# frequency_v2(12.5) #=> 0.08
|
58
|
+
# @note There is one other method for calculating frequency.
|
59
|
+
def frequency_v2(time_period)
|
60
|
+
return 1.0 / time_period
|
61
|
+
end
|
62
|
+
|
63
|
+
# Calculates the time period given frequency.
|
64
|
+
# @param frequency [Int, Float]
|
65
|
+
# frequency > 0; frequency is in hertz
|
66
|
+
# @return [Float]
|
67
|
+
# returned value > 0; returned value is in hertz
|
68
|
+
# @example
|
69
|
+
# time_period(0.08) #=> 12.5
|
70
|
+
def time_period(frequency)
|
71
|
+
return 1.0 / frequency
|
72
|
+
end
|
data/lib/joules.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing Physics formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.0
|
6
|
+
# @version: 0.1.0 23/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Joules module (joules.rb)
|
@@ -16,3 +16,5 @@ require 'joules/forces'
|
|
16
16
|
require 'joules/momentum_impulse'
|
17
17
|
require 'joules/energy_work_power'
|
18
18
|
require 'joules/pressure'
|
19
|
+
require 'joules/thermodynamics'
|
20
|
+
require 'joules/waves'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joules
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elisha Lai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " Joules is a library (gem) for providing simple Physics formulas\n
|
14
14
|
\ in kinematics, forces, waves, electricity, and so much more. A\n selection
|
@@ -27,6 +27,8 @@ files:
|
|
27
27
|
- lib/joules/mass_weight.rb
|
28
28
|
- lib/joules/momentum_impulse.rb
|
29
29
|
- lib/joules/pressure.rb
|
30
|
+
- lib/joules/thermodynamics.rb
|
31
|
+
- lib/joules/waves.rb
|
30
32
|
homepage: http://elailai94.github.io/Joules
|
31
33
|
licenses:
|
32
34
|
- MIT
|