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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7adc9f03a5ed56c45511fb95a55cd7501f4d7f31
4
- data.tar.gz: 39a51410782c1e97170195ebaa9ff34f01e8246d
3
+ metadata.gz: 309af22d22628f2fecec4180108382f0edc324a9
4
+ data.tar.gz: 0729618e8e982c76cdecb3b9f30939c1e422e788
5
5
  SHA512:
6
- metadata.gz: e7af5c6449cd3fefb2727aeb2f08bc3756f6348e3d395e63407581128b026ce6f8c385f83e108b95ec661657d08b833ae7c140a41339a2ca621a99a2f48a324a
7
- data.tar.gz: 15dd96b54231c1bf7a9eecc213766eab174839e3766a22b4abc42f35b205a6e67d86ce3971a38d97cf897a40e877674ad5231ed2cbfe0bba1745da39735a9545
6
+ metadata.gz: 93f6ca64737cfe6099ebf0fd9f8593591187f14b3e0ced850c2e152fab903044e66a587aa3a20a96a34cf43242ff4371272de7a595d6996b1d9b8c43a36f9d44
7
+ data.tar.gz: bb671926e1b41cb3e8d8e7678152b7fcc8ee9673f6a458c4af7ac1e8c97117368b79f224e0e4f99be662481039254ecfb442625d32f263e6262b45e95c4a756f
@@ -3,59 +3,71 @@
3
3
  #
4
4
  # @description: Module for providing constants
5
5
  # @author: Elisha Lai
6
- # @version: 0.0.3 16/05/2015
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
- # Note: This quantity is in meters per second.
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
- # Note: This quantity is in henries per meter.
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
- # Note: This quantity is in farads per meter.
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
- # Note: This quantity is in coulombs.
23
+ # Elementary charge.
24
+ # @note This quantity is in coulombs.
25
25
  ELEMENTARY_CHARGE = 1.6e-19
26
26
 
27
- # Planck constant
28
- # Note: This quantity is in joule seconds.
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
- # Note: This quantiy is in kilograms.
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
- # Note: This quantity is in kilograms.
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
- # Note: This quantity is in kilograms.
39
+ # Rest mass of proton.
40
+ # @note This quantity is in kilograms.
41
41
  PROTON_MASS = 1.67e-27
42
42
 
43
- # Molar gas constant
44
- # Note: This quantity is in joules per kelvin mole.
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
- # Note: This quantity is in per mole.
51
+ # Avogadro constant.
52
+ # @note This quantity is in per mole.
49
53
  AVOGADRO_CONSTANT = 6.02e23
50
54
 
51
- # Boltzmann constant
52
- # Note: This quantity is in joules per kelvin.
55
+ # Boltzmann constant.
56
+ # @note This quantity is in joules per kelvin.
53
57
  BOLTZMANN_CONSTANT = 1.38e-23
54
58
 
55
- # Gravitational constant
56
- # Note: This quantity is in newton metres squared per kilogram squared.
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
- # Note: This quantity is in meters per second squared.
71
+ # Acceleration of free fall.
72
+ # @note This quantity is in meters per second squared.
61
73
  FREE_FALL_ACCELERATION = 9.81
@@ -3,22 +3,20 @@
3
3
  #
4
4
  # @description: Module for providing density formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.0.3 16/05/2015
6
+ # @version: 0.1.0 23/05/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Density module (density.rb)
10
10
 
11
- # density: (union Int Float) (union Int Float) -> Float
12
- # Conditions:
13
- # PRE: mass >= 0
14
- # mass is in kilograms.
15
- # volume > 0
16
- # volume is in meters cubed.
17
- # POST: Returns a Float.
18
- # returned value >= 0
19
- # returned value is in kilograms per meter cubed.
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.3 16/05/2015
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
- # gravitational_potential_energy: (union Int Float) (union Int Float)
14
- # -> Float
15
- # Conditions:
16
- # PRE: mass >= 0
17
- # mass is in kilograms.
18
- # height >= 0
19
- # height is in meters.
20
- # POST: Returns a Float.
21
- # returned value >= 0
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
- # elastic_potential_energy: (union Int Float) (union Int Float) -> Float
30
- # Conditions:
31
- # PRE: spring_constant >= 0
32
- # spring constant is in newtons per meter.
33
- # extension >= 0
34
- # extension is in meters.
35
- # POST: Returns a Float.
36
- # returned value >= 0
37
- # returned value is in joules.
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
- # kinetic_energy: (union Int Float) (union Int Float) -> Float
45
- # Conditions:
46
- # PRE: mass >= 0
47
- # mass is in kilograms.
48
- # velocity is in meters per second.
49
- # POST: Returns a Float.
50
- # returned value >= 0
51
- # returned value is in joules.
52
- # Purpose: Consumes two numbers, mass and velocity. Returns the calculated
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
- # work_done: (union Int Float) (union Int Float) -> Float
59
- # Conditions:
60
- # PRE: force is in newtons.
61
- # distance >= 0
62
- # distance is in meters.
63
- # POST: Returns a Float.
64
- # returned value is in joules.
65
- # Purpose: Consumes two numbers, force and distance. Returns the
66
- # calculated work done.
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
- # power: (union Int Float) (union Int Float) -> Float
72
- # Condition:
73
- # PRE: work_done is in joules.
74
- # time > 0
75
- # time is in seconds.
76
- # POST: Returns a Float.
77
- # returned value is in watts.
78
- # Purpose: Consumes two numbers, work done and time. Returns the
79
- # calculated power.
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
- # energy_efficiency: (union Int Float) (union Int Float) -> Float
85
- # Conditions:
86
- # PRE: energy_input > 0
87
- # 0 <= useful_energy_output <= energy_input
88
- # useful_energy_output and energy_input are in joules.
89
- # POST: Returns a Float.
90
- # returned value >= 0
91
- # Purpose: Consumes two numbers, useful_energy_output and energy_input.
92
- # Returns the calculated energy efficiency.
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
- # power_efficiency: (union Int Float) (union Int Float) -> Float
98
- # Conditions:
99
- # PRE: power_input > 0
100
- # 0 <= useful_power_output <= power_input
101
- # useful_power_output and power_input are in joules.
102
- # POST: Returns a Float.
103
- # returned value >= 0
104
- # Purpose: Consumes two numbers, useful_power_output and power_input.
105
- # Returns the calculated power efficiency.
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.3 16/05/2015
6
+ # @version: 0.1.0 23/05/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Forces module (forces.rb)
10
10
 
11
- # force_v1: (union Int Float) (union Int Float) -> Float
12
- # Conditions:
13
- # PRE: mass >= 0
14
- # mass is in kilograms.
15
- # acceleration is in meters per second squared.
16
- # POST: Returns a Float.
17
- # returned value is in newtons.
18
- # Purpose: Consumes two numbers, mass and acceleration. Returns the
19
- # calculated force.
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
- # force_v2: (union Int Float) (union Int Float) -> Float
25
- # Conditions:
26
- # PRE: spring_constant >= 0
27
- # spring constant is in newtons per meter.
28
- # extension >= 0
29
- # extension is in meters.
30
- # POST: Returns a Float.
31
- # returned value >= 0
32
- # returned value is in newtons.
33
- # Purpose: Consumes two numbers, spring_constant and extension. Returns the
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
- # force_v3: (union Int Float) (union Int Float) -> Float
40
- # Conditions:
41
- # PRE: initial_velocity and final_velocity are in meters per second.
42
- # mass >= 0
43
- # mass is in kilograms.
44
- # time > 0
45
- # time is in seconds.
46
- # POST: Returns a Float.
47
- # returned value is in newtons.
48
- # Purpose: Consumes four numbers, initial_velocity, final_velocity, mass,
49
- # and time. Returns the calculated force.
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
- # moment: (union Int Float) (union Int Float) -> Float
55
- # Conditions:
56
- # PRE: force is in newtons.
57
- # distance >= 0
58
- # distance is in meters.
59
- # POST: Returns a Float.
60
- # returned value is in newton metres.
61
- # Purpose: Consumes two numbers, force and distance. Returns the
62
- # calculated moment.
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
@@ -3,122 +3,128 @@
3
3
  #
4
4
  # @description: Module for providing kinematics formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.0.3 16/05/2015
6
+ # @version: 0.1.0 23/05/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Kinematics module (kinematics.rb)
10
10
 
11
- # avg_speed: (union Int Float) (union Int Float) -> Float
12
- # Conditions:
13
- # PRE: distance >= 0
14
- # distance is in meters.
15
- # time > 0
16
- # time is in seconds.
17
- # POST: Returns a Float.
18
- # returned value >= 0
19
- # returned value is in meters per second.
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
- # avg_velocity: (union Int Float) (union Int Float) -> Float
27
- # Conditions:
28
- # PRE: displacement is in meters.
29
- # time > 0
30
- # time is in seconds.
31
- # POST: Returns a Float.
32
- # returned value is in meters per second.
33
- # Purpose: Consumes two numbers, displacement and time. Returns the
34
- # calculated average velocity.
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
- # acceleration: (union Int Float) (union Int Float) (union Int Float)
40
- # -> Float
41
- # Conditions:
42
- # PRE: initial_velocity and final_velocity are in meters per second.
43
- # time > 0
44
- # time is in seconds.
45
- # POST: Returns a Float.
46
- # returned value is in meters per second squared.
47
- # Purpose: Consumes three numbers: initial_velocity, final_velocity,
48
- # and time. Returns the calculated acceleration.
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
- # final_velocity_v1: (union Int Float) (union Int Float) (union Int Float)
54
- # -> Float
55
- # Conditions:
56
- # PRE: initial_velocity is in meters per second.
57
- # acceleration is in meters per second squared.
58
- # time >= 0
59
- # time is in seconds.
60
- # POST: Returns a Float.
61
- # returned value is in meters per second.
62
- # Purpose: Consumes three numbers: initial_velocity, acceleration, and
63
- # time. Returns the calculated final velocity.
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
- # final_velocity_v2: (union Int Float) (union Int Float) (union Int Float)
69
- # -> Float
70
- # Conditions:
71
- # PRE: initial_velocity is in meters per second.
72
- # acceleration is in meters per second squared.
73
- # displacement is in meters.
74
- # POST: Returns a Float.
75
- # returned value is in meters per second.
76
- # Purpose: Consumes three numbers: initial_velocity, acceleration, and
77
- # displacement. Returns the calculated final velocity.
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
- # displacement_v1: (union Int Float) (union Int Float) (union Int Float)
83
- # -> Float
84
- # Conditions:
85
- # PRE: initial_velocity and final_velocity are in meters per second.
86
- # time >= 0
87
- # time is in seconds.
88
- # POST: Returns a Float.
89
- # returned value is in meters.
90
- # Purpose: Consumes three numbers: initial_velocity, final_velocity, and
91
- # time. Returns the calculated displacement.
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
- # displacement_v2: (union Int Float) (union Int Float) (union Int Float)
97
- # -> Float
98
- # Conditions:
99
- # PRE: initial_velocity is in meters per second.
100
- # acceleration is in meters per second squared.
101
- # time >= 0
102
- # time is in seconds.
103
- # POST: Returns a Float.
104
- # returned value is in meters.
105
- # Purpose: Consumes three numbers: initial_velocity, acceleration, and
106
- # time. Returns the calculated displacement.
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
- # displacement_v3: (union Int Float) (union Int Float) (union Int Float)
112
- # -> Float
113
- # Conditions:
114
- # PRE: final_velocity is in meters per second.
115
- # acceleration is in meters per second squared.
116
- # time >= 0
117
- # time is in seconds.
118
- # POST: Returns a Float.
119
- # returned value is in meters.
120
- # Purpose: Consumes three numbers: final_velocity, acceleration, and
121
- # time. Returns the calculated displacement.
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
@@ -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.3 16/05/2015
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
- # weight: (union Int Float) -> Float
14
- # Conditions:
15
- # PRE: mass >= 0
16
- # mass is in kilograms.
17
- # POST: Returns a Float.
18
- # returned value >= 0
19
- # returned value is in newtons.
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
- # mass: (union Int Float) -> Float
26
- # Conditions:
27
- # PRE: weight >= 0
28
- # weight is in newtons.
29
- # POST: Returns a Float.
30
- # returned value >= 0
31
- # returned value is in kilograms.
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.3 16/05/2015
6
+ # @version: 0.1.0 23/05/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Momentum and impulse module (momentum_impulse.rb)
10
10
 
11
- # momentum: (union Int Float) (union Int Float) -> Float
12
- # Conditions:
13
- # PRE: mass >= 0
14
- # mass is in kilograms.
15
- # velocity is in meters per second.
16
- # POST: Returns a Float.
17
- # returned value is in newton seconds.
18
- # Purpose: Consumes two numbers, mass and velocity. Returns the calculated
19
- # momentum.
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
- # impulse_v1: (union Int Float) (union Int Float) -> Float
25
- # Conditions:
26
- # PRE: force is in newtons.
27
- # time >= 0
28
- # time is in seconds.
29
- # POST: Returns a Float.
30
- # returned value is in newton seconds.
31
- # Purpose: Consumes two numbers, force and time. Returns the calculated
32
- # impulse.
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
- # impulse_v2: (union Int Float) (union Int Float) (union Int Float)
38
- # -> Float
39
- # Condition:
40
- # PRE: initial_velocity and final_velocity are in meters per second.
41
- # mass >= 0
42
- # mass is in kilograms.
43
- # POST: Returns a Float.
44
- # returned value is in newton seconds.
45
- # Purpose: Consumes three numbers, initial_velocity, final_velocity, and
46
- # mass. Returns the calculated impulse.
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
@@ -3,39 +3,35 @@
3
3
  #
4
4
  # @description: Module for providing pressure formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.0.3 16/05/2015
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
- # pressure: (union Int Float) (union Int Float) -> Float
14
- # Conditions:
15
- # PRE: force >= 0
16
- # force is in newtons.
17
- # area > 0
18
- # area is in meters cubed.
19
- # POST: Returns a Float.
20
- # returned value >= 0
21
- # returned value is in pascals.
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
- # hydrostatic_pressure: (union Int Float) (union Int Float) -> Float
29
- # Conditions:
30
- # PRE: density >= 0
31
- # density is in kilograms per meter cubed.
32
- # height >= 0
33
- # height is in meters.
34
- # POST: Returns a Float.
35
- # returned value >= 0
36
- # returned value is in pascals.
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
@@ -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.3 16/05/2015
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.3
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-22 00:00:00.000000000 Z
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