module Math
Copyright Freya Dorn <freya.siv.dorn@gmail.com>, 2018 License: GNU APGLv3 (or later) <www.gnu.org/copyleft/gpl.html>
Public Class Methods
bmi(m, h ;)
click to toggle source
# File lib/muflax/math.rb, line 49 def bmi m, h ; mass_index 2.0, m, h ; end
bmi_adj(m, h ;)
click to toggle source
# File lib/muflax/math.rb, line 50 def bmi_adj m, h ; mass_index 2.5, m, h, 1.3 ; end
bmi_adj_at(i, h ;)
click to toggle source
# File lib/muflax/math.rb, line 54 def bmi_adj_at i, h ; mass_index_at 2.5, i, h, 1.3 ; end
bmi_at(i, h ;)
click to toggle source
# File lib/muflax/math.rb, line 53 def bmi_at i, h ; mass_index_at 2.0, i, h ; end
bsi(m, h ;)
click to toggle source
# File lib/muflax/math.rb, line 51 def bsi m, h ; mass_index 3.0, m, h ; end
bsi_at(i, h ;)
click to toggle source
# File lib/muflax/math.rb, line 55 def bsi_at i, h ; mass_index_at 3.0, i, h ; end
choose(k, n)
click to toggle source
# File lib/muflax/math.rb, line 35 def choose k, n Math.factorial(n) / (Math.factorial(k) * Math.factorial(n - k)) end
factorial(n)
click to toggle source
# File lib/muflax/math.rb, line 31 def factorial n (2..n).reduce(1){|f, x| f * x} end
harmonic(n)
click to toggle source
# File lib/muflax/math.rb, line 8 def harmonic n (1..n).reduce(0.0){|s, i| s + (1.0 / i)} end
mass_index(coeff, mass, height, adjustment=1.0)
click to toggle source
# File lib/muflax/math.rb, line 39 def mass_index coeff, mass, height, adjustment=1.0 height /= 100.0 if (50..300).include? height # cm -> m auto-correction adjustment * (mass / (height ** coeff)) end
mass_index_at(coeff, index, height, adjustment=1.0)
click to toggle source
# File lib/muflax/math.rb, line 44 def mass_index_at coeff, index, height, adjustment=1.0 height /= 100.0 if (50..300).include? height # cm -> m auto-correction index * (height ** coeff) / adjustment end
sufficiency(exceptions)
click to toggle source
TODO meh iterative solution
# File lib/muflax/math.rb, line 24 def sufficiency exceptions n = 1 n += 1 while θ(n) < exceptions n end
Also aliased as: sufficient
tolerance(total)
click to toggle source
# File lib/muflax/math.rb, line 16 def tolerance total θ = total / Math.log(total) θ > total ? total : θ.round end
zipf(k, n)
click to toggle source
# File lib/muflax/math.rb, line 12 def zipf k, n 1.0 / (k.to_f * harmonic(n)) end