joules 0.2.0 → 0.3.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: fe0112745ba13a5455d979a35367768cdaa2f382
4
- data.tar.gz: eca09701308ea046cf92d8a6b2777af12d4011b0
3
+ metadata.gz: b7a405f59eae561b636acb954b03228a898fe036
4
+ data.tar.gz: fbc765fa0f3a42672c49068e9db10ab840899f04
5
5
  SHA512:
6
- metadata.gz: bc5a94a2b8b9c9674d971c556335fb1ab4ccd116f2e95fe29c56f501d6b7daf89c7157a5cb1d38406d24c5cd71c1a359e9da3cdb6ec006283d99d73b6312520a
7
- data.tar.gz: dea84c2a922ef20939c23216253bdaf0370e4b693609fb838f12c7f4260adc7517a594772134c74fcd9a66fb59d1abe916d6d00bea06c56d16964e83a843d32b
6
+ metadata.gz: f3301f33a9aab8819c5e5d86c53840ae9304e723f45da88c1c0f5921543bd3168baacb80b6c6b6aa2c5d377eb956a2df3f58a1e50626a194fafa74623098ac77
7
+ data.tar.gz: 1bea761dbed0cffff0e120e67131dcd2d37b44f06020ef539683e70f8033fcb433df670126a01baba0ad252707baae1e3301a2f7a342939055484f20e869fd90
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ ![Joules Logo](https://cloud.githubusercontent.com/assets/7763904/7764836/ef617b0a-0024-11e5-8044-3cf354a4a306.png)
2
+
3
+ [![forthebadge](http://forthebadge.com/images/badges/built-with-ruby.svg)](http://forthebadge.com)
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/joules.svg)](http://badge.fury.io/rb/joules)
6
+
7
+ ### About
8
+ Joules is a library (gem) for providing simple Physics formulas in kinematics, forces, waves, electricity, and so much more. A selection of fundamental constants are also provided. It is written entirely in Ruby.
9
+ > Note: For library download, please visit [https://www.rubygems.org/gems/joules](https://www.rubygems.org/gems/joules).
10
+
11
+ ### Library Compilation
12
+ ```Bash
13
+ gem build joules.gemspec
14
+ ```
15
+
16
+ ### Library Installation
17
+ ```Bash
18
+ gem install joules-0.3.0.gem
19
+ ```
20
+
21
+ ### Library Import
22
+ ```Ruby
23
+ require 'joules'
24
+ ```
25
+
26
+ ### Usage
27
+ #### Simple Method Call
28
+ ```Ruby
29
+ gravitational_potential_energy(0.5, 6)
30
+ ```
31
+ This would return 29.43.
32
+ #### Method Composition
33
+ ```Ruby
34
+ power(work_done(40, 2.34), 4)
35
+ ```
36
+ This would return 23.4.
37
+ > Note: For documentation on methods and constants, please visit [http://www.rubydoc.info/gems/joules/](http://www.rubydoc.info/gems/joules/).
38
+
39
+ ### Change Log
40
+ #### Version 0.0.1
41
+ * Added Physics formulas in kinematics, mass, weight, density, forces, momentum, impulse, energy, work, power, and pressure
42
+ * Added the following Physics constants: speed of light in free space and acceleration of free fall
43
+
44
+ #### Version 0.0.2
45
+ * Fixed publishing date in gem specification
46
+
47
+ #### Version 0.0.3
48
+ * Added the following Physics constants: permeability of free space, permittivity of free space, elementary charge, Planck constant, unified atomic mass unit, rest mass of electron, rest mass of proton, molar gas constant, avogadro constant, Boltzmann constant, and gravitational constant
49
+
50
+ #### Version 0.1.0
51
+ * Added Physics formulas in waves and thermodynamics
52
+ * Added the following Physics constants: rest mass of neutron, Stefan constant, and Wien constant
53
+ * Updated existing documentation style to YARD documentation style
54
+
55
+ #### Version 0.2.0
56
+ * Added Physics formulas in electricity
57
+ * Added geometric and conversion formulas commonly used in Physics
58
+
59
+ #### Version 0.3.0
60
+ * Added Physics formulas in quantum
61
+ * Added more geometric and conversion formulas commonly used in Physics
62
+
63
+ ### Contribution
64
+ Please feel free to submit any ideas, questions, or problems by reporting an issue.
65
+
66
+ ### License
67
+ * Joules is licensed under the [MIT license](https://github.com/elailai94/Joules/blob/master/LICENSE.md).
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing constants
5
5
  # @author: Elisha Lai
6
- # @version: 0.2.0 25/05/2015
6
+ # @version: 0.3.0 29/05/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Constants module (constants.rb)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing conversion formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.2.0 25/05/2015
6
+ # @version: 0.3.0 29/05/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Conversion module (conversion.rb)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing density formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.2.0 25/05/2015
6
+ # @version: 0.3.0 29/05/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Density module (density.rb)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing electricity formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.2.0 25/05/2015
6
+ # @version: 0.3.0 29/05/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Electricity module (electricity.rb)
@@ -91,10 +91,54 @@ end
91
91
  # voltage != 0; voltage is in volts
92
92
  # @return [Float]
93
93
  # return value is in farads
94
+ # @example
95
+ # capacitance(2e-3, 100) #=> 2.0e-05
94
96
  def capacitance(charge, voltage)
95
97
  return charge / voltage.to_f
96
98
  end
97
99
 
100
+ # Calculates the capacitor potential energy given charge and voltage.
101
+ # @param charge [Int, Float]
102
+ # charge is in coulombs
103
+ # @param voltage [Int, Float]
104
+ # voltage is in volts
105
+ # @return [Float]
106
+ # return value is in joules
107
+ # @example
108
+ # capacitor_potential_energy_v1(1.5, 30) #=> 22.5
109
+ # @note There are two other methods for calculating capacitor potential energy.
110
+ def capacitor_potential_energy_v1(charge, voltage)
111
+ return 0.5 * charge * voltage
112
+ end
113
+
114
+ # Calculates the capacitor potential energy given capacitance and voltage.
115
+ # @param capacitance [Int, Float]
116
+ # capacitance is in farads
117
+ # @param voltage [Int, Float]
118
+ # voltage is in volts
119
+ # @return [Float]
120
+ # return value is in joules
121
+ # @example
122
+ # capacitor_potential_energy_v2(10e-6, 20) #=> 0.002
123
+ # @note There are two other methods for calculating capacitor potential energy.
124
+ def capacitor_potential_energy_v2(capacitance, voltage)
125
+ return 0.5 * capacitance * (voltage ** 2)
126
+ end
127
+
128
+ # Calculates the capacitor potential energy given charge and capacitance.
129
+ # @param charge [Int, Float]
130
+ # charge is in coulombs
131
+ # @param capacitance [Int, Float]
132
+ # capacitance is in farads
133
+ # @return [Float]
134
+ # return value is in joules
135
+ # @example
136
+ # capacitor_potential_energy_v3(25, 50) #=> 6.25
137
+ # @note There are two other methods for calculating capacitor potential energy.
138
+ def capacitor_potential_energy_v3(charge, capacitance)
139
+ return (0.5 * (charge ** 2)) / capacitance
140
+ end
141
+
98
142
  # Calculates the total capacitance of capacitors in series.
99
143
  # @param capacitances [Array<Int, Float>]
100
144
  # each capacitance in resistances != 0; each capacitance in capacitances is in farads
@@ -164,9 +208,9 @@ end
164
208
  # @return [Float]
165
209
  # return value is in watts
166
210
  # @example
167
- # power_v2(1.8, 0.6) #=> 1.08
168
- # @note There are three other methods for calculating power.
169
- def power_v2(voltage, current)
211
+ # power_v3(1.8, 0.6) #=> 1.08
212
+ # @note There are four other methods for calculating power.
213
+ def power_v3(voltage, current)
170
214
  return voltage * current.to_f
171
215
  end
172
216
 
@@ -178,9 +222,9 @@ end
178
222
  # @return [Float]
179
223
  # return value is in watts
180
224
  # @example
181
- # power_v3(0.6, 3) #=> 1.08
182
- # @note There are three other methods for calculating power.
183
- def power_v3(current, resistance)
225
+ # power_v4(0.6, 3) #=> 1.08
226
+ # @note There are four other methods for calculating power.
227
+ def power_v4(current, resistance)
184
228
  return (current ** 2.0) * resistance
185
229
  end
186
230
 
@@ -192,9 +236,9 @@ end
192
236
  # @return [Float]
193
237
  # return value is in watts
194
238
  # @example
195
- # power_v4(1.8, 3) #=> 1.08
196
- # @note There are three other methods for calculating power.
197
- def power_v4(voltage, resistance)
239
+ # power_v5(1.8, 3) #=> 1.08
240
+ # @note There are four other methods for calculating power.
241
+ def power_v5(voltage, resistance)
198
242
  return (voltage ** 2.0) / resistance
199
243
  end
200
244
 
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing energy, work, and power formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.2.0 25/05/2015
6
+ # @version: 0.3.0 29/05/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Energy, work, and power module (energy_work_power.rb)
@@ -49,17 +49,17 @@ def kinetic_energy(mass, velocity)
49
49
  return 0.5 * mass * (velocity ** 2)
50
50
  end
51
51
 
52
- # Calculates the work done given force and distance.
52
+ # Calculates the work done given force and displacement.
53
53
  # @param force [Int, Float]
54
54
  # force is in newtons
55
- # @param distance [Int, Float]
56
- # distance >= 0; distance is in meters
55
+ # @param displacement [Int, Float]
56
+ # displacement is in meters
57
57
  # @return [Float]
58
58
  # return value is in joules
59
59
  # @example
60
60
  # work_done(40, 2.34) #=> 93.6
61
- def work_done(force, distance)
62
- return force * distance.to_f
61
+ def work_done(force, displacement)
62
+ return force * displacement.to_f
63
63
  end
64
64
 
65
65
  # Calculates the power given work done and time.
@@ -71,11 +71,25 @@ end
71
71
  # return value is in watts
72
72
  # @example
73
73
  # power_v1(28, 7) #=> 4.0
74
- # @note There are three other methods for calculating power.
74
+ # @note There are four other methods for calculating power.
75
75
  def power_v1(work_done, time)
76
76
  return work_done / time.to_f
77
77
  end
78
78
 
79
+ # Calculates the power given force and velocity.
80
+ # @param force [Int, Float]
81
+ # force is in newtons
82
+ # @param velocity [Int, Float]
83
+ # velocity is in meters per second
84
+ # @return [Float]
85
+ # return value is in watts
86
+ # @example
87
+ # power_v2(42, 2.3) #=> 96.6
88
+ # @note There are four other methods for calculating power.
89
+ def power_v2(force, velocity)
90
+ return force * velocity.to_f
91
+ end
92
+
79
93
  # Calculates the energy efficiency given useful energy output and energy input.
80
94
  # @param useful_energy_output [Int, Float]
81
95
  # 0 <= useful_energy_output <= energy_input; useful_energy_output is in joules
data/lib/joules/forces.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing forces formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.2.0 25/05/2015
6
+ # @version: 0.3.0 29/05/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Forces module (forces.rb)
@@ -3,11 +3,24 @@
3
3
  #
4
4
  # @description: Module for providing geometry formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.2.0 25/05/2015
6
+ # @version: 0.3.0 29/05/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Geometry module (geometry.rb)
10
10
 
11
+ # Calculates the area of a rectangle given length and width.
12
+ # @param length [Int, Float]
13
+ # length >= 0; length is in a unit of length
14
+ # @param width [Int, Float]
15
+ # width >= 0; width has the same units as length
16
+ # @return [Float]
17
+ # return value >= 0; return value has the same units as length
18
+ # @example
19
+ # rectangle_area(2, 3.4) #=> 6.8
20
+ def rectangle_area(length, width)
21
+ return length * width.to_f
22
+ end
23
+
11
24
  # Calculates the arc length of a circle given radius and central angle.
12
25
  # @param radius [Int, Float]
13
26
  # radius >= 0; radius is in a unit of length
@@ -49,9 +62,9 @@ end
49
62
  # @return [Float]
50
63
  # return value >= 0; return value has the same units as radius
51
64
  # @example
52
- # sphere_surface_area(12) #=> 1809.55736846772
65
+ # sphere_surface_area(12) #=> 1809.5573684677208
53
66
  def sphere_surface_area(radius)
54
- return 4 * Math::PI * (radius ** 2)
67
+ return 4 * circle_area(radius)
55
68
  end
56
69
 
57
70
  # Calculates the volume of a sphere given radius.
@@ -60,9 +73,35 @@ end
60
73
  # @return [Float]
61
74
  # return value >= 0; return value has the same units as radius
62
75
  # @example
63
- # sphere_volume(12) #=> 7238.22947387088
76
+ # sphere_volume(12) #=> 7238.229473870883
64
77
  def sphere_volume(radius)
65
- return (4 * Math::PI * (radius ** 3)) / 3
78
+ return (4 * circle_area(radius) * radius) / 3
79
+ end
80
+
81
+ # Calculates the surface area of a cone given radius and slant height.
82
+ # @param radius [Int, Float]
83
+ # radius >= 0; radius is in a unit of length
84
+ # @param slant_height [Int, Float]
85
+ # slant_height >= 0; slant_height has the same units as radius
86
+ # @return [Float]
87
+ # return value >= 0; return value has the same units as radius
88
+ # @example
89
+ # cone_surface_area(3, 5.83) #=> 83.22078939359362
90
+ def cone_surface_area(radius, slant_height)
91
+ return circle_area(radius) + (Math::PI * radius * slant_height)
92
+ end
93
+
94
+ # Calculates the volume of a cone given radius and height.
95
+ # @param radius [Int, Float]
96
+ # radius >= 0; radius is in a unit of length
97
+ # @param height [Int, Float]
98
+ # height >= 0; height has the same units as radius
99
+ # @return [Float]
100
+ # return value >= 0; return value has the same units as radius
101
+ # @example
102
+ # cone_volume(6.5, 3) #=> 132.73228961416876
103
+ def cone_volume(radius, height)
104
+ return (circle_area(radius) * height) / 3
66
105
  end
67
106
 
68
107
  # Calulates the surface area of a cylinder given radius and height.
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing kinematics formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.2.0 25/05/2015
6
+ # @version: 0.3.0 29/05/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Kinematics module (kinematics.rb)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing mass and weight formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.2.0 25/05/2015
6
+ # @version: 0.3.0 29/05/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.2.0 25/05/2015
6
+ # @version: 0.3.0 29/05/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Momentum and impulse module (momentum_impulse.rb)
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing pressure formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.2.0 25/05/2015
6
+ # @version: 0.3.0 29/05/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Pressure module (pressure.rb)
@@ -0,0 +1,56 @@
1
+ #==============================================================================
2
+ # Joules
3
+ #
4
+ # @description: Module for providing quantum formulas
5
+ # @author: Elisha Lai
6
+ # @version: 0.3.0 29/05/2015
7
+ #==============================================================================
8
+
9
+ # Quantum module (quantum.rb)
10
+
11
+ require_relative 'constants'
12
+
13
+ # Calculates the photon energy given frequency.
14
+ # @param frequency [Int, Float]
15
+ # frequency > 0; frequency is in hertz
16
+ # @return [Float]
17
+ # return value > 0; return value is in joules
18
+ # @example
19
+ # photon_energy(509337860780984.75) #=> 3.376910016977929e-19
20
+ def photon_energy(frequency)
21
+ return PLANCK_CONSTANT * frequency
22
+ end
23
+
24
+ # Calculates the energy given mass.
25
+ # @param mass [Int, Float]
26
+ # mass >= 0; mass is in kilograms
27
+ # @return [Float]
28
+ # return value >= 0; return value is in joules
29
+ # @example
30
+ # energy_v4(60.5) #=> 5.445e+18
31
+ # @note There are three other methods for calculating energy.
32
+ def energy_v4(mass)
33
+ return mass * (SPEED_OF_LIGHT ** 2)
34
+ end
35
+
36
+ # Calculates the half-life of a decaying quantity given decay constant.
37
+ # @param decay_constant [Int, Float]
38
+ # decay_constant != 0; decay_constant is in per second
39
+ # @return [Float]
40
+ # return value is in seconds
41
+ # @example
42
+ # half_life(7.7e4) #=> 9.001911435843445e-06
43
+ def half_life(decay_constant)
44
+ return Math.log(2) / decay_constant
45
+ end
46
+
47
+ # Calculates the decay constant of a decaying quantity given half-life.
48
+ # @param half_life [Int, Float]
49
+ # half_life != 0; half_life is in seconds
50
+ # @return [Float]
51
+ # return value is in per second
52
+ # @example
53
+ # decay_constant(9) #=> 0.0770163533955495
54
+ def decay_constant(half_life)
55
+ return Math.log(2) / half_life
56
+ end
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing thermodynamics formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.2.0 25/05/2015
6
+ # @version: 0.3.0 29/05/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Thermodynamics module (thermodynamics.rb)
data/lib/joules/waves.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  #
4
4
  # @description: Module for providing waves formulas
5
5
  # @author: Elisha Lai
6
- # @version: 0.2.0 25/05/2015
6
+ # @version: 0.3.0 29/05/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Waves module (waves.rb)
@@ -97,3 +97,40 @@ end
97
97
  def refractive_index_v2(critical_angle)
98
98
  return 1.0 / Math.sin(to_radians(critical_angle))
99
99
  end
100
+
101
+ # Calculates the magnification given image_height and object_height.
102
+ # @param image_height [Int, Float]
103
+ # image_height >= 0; image_height is in a unit of length
104
+ # @param object_height [Int, Float]
105
+ # object_height > 0; object_height has the same units as image_height
106
+ # @return [Float]
107
+ # return value >= 0
108
+ # @example
109
+ # magnification(10, 5) #=> 2.0
110
+ def magnification(image_height, object_height)
111
+ return image_height / object_height.to_f
112
+ end
113
+
114
+ # Calculates the focal length of a lens given object distance and image distance.
115
+ # @param object_distance [Int, Float]
116
+ # object_distance > 0; object_distance is in meters
117
+ # @param image_distance [Int, Float]
118
+ # image_distance > 0; image_distance is in meters
119
+ # @return [Float]
120
+ # return value >= 0; return value is in meters
121
+ # @example
122
+ # focal_length(45.7, 22.8) #=> 15.21109489051095
123
+ def focal_length(object_distance, image_distance)
124
+ return 1 / ((1.0 / object_distance) + (1.0 / image_distance))
125
+ end
126
+
127
+ # Calculates the power of a lens given focal length.
128
+ # @param focal_length [Int, Float]
129
+ # focal_length > 0; focal_length is in meters
130
+ # @return [Float]
131
+ # return value > 0; return value is in dioptres
132
+ # @example
133
+ # power_of_lens(2) #=> 0.5
134
+ def power_of_lens(focal_length)
135
+ return 1.0 / focal_length
136
+ 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.2.0 25/05/2015
6
+ # @version: 0.3.0 29/05/2015
7
7
  #==============================================================================
8
8
 
9
9
  # Joules module (joules.rb)
@@ -19,5 +19,6 @@ require 'joules/pressure'
19
19
  require 'joules/thermodynamics'
20
20
  require 'joules/waves'
21
21
  require 'joules/electricity'
22
+ require 'joules/quantum'
22
23
  require 'joules/geometry'
23
24
  require 'joules/conversion'
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.2.0
4
+ version: 0.3.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-25 00:00:00.000000000 Z
11
+ date: 2015-05-29 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
@@ -18,6 +18,7 @@ executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - README.md
21
22
  - lib/joules.rb
22
23
  - lib/joules/constants.rb
23
24
  - lib/joules/conversion.rb
@@ -30,6 +31,7 @@ files:
30
31
  - lib/joules/mass_weight.rb
31
32
  - lib/joules/momentum_impulse.rb
32
33
  - lib/joules/pressure.rb
34
+ - lib/joules/quantum.rb
33
35
  - lib/joules/thermodynamics.rb
34
36
  - lib/joules/waves.rb
35
37
  homepage: http://elailai94.github.io/Joules