Module: Math

Defined in:
lib/muflax/math.rb

Overview

Copyright Steffie Dorn <[email protected]>, 2018 License: GNU APGLv3 (or later) <www.gnu.org/copyleft/gpl.html>

Class Method Summary collapse

Class Method Details

.bmi(m, h) ⇒ Object



49
# File 'lib/muflax/math.rb', line 49

def bmi    	m, h	; mass_index 2.0, m, h     	; end

.bmi_adj(m, h) ⇒ Object



50
# 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) ⇒ Object



54
# 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) ⇒ Object



53
# File 'lib/muflax/math.rb', line 53

def bmi_at    	i, h	; mass_index_at 2.0, i, h     	; end

.bsi(m, h) ⇒ Object



51
# File 'lib/muflax/math.rb', line 51

def bsi    	m, h	; mass_index 3.0, m, h     	; end

.bsi_at(i, h) ⇒ Object



55
# File 'lib/muflax/math.rb', line 55

def bsi_at    	i, h	; mass_index_at 3.0, i, h     	; end

.choose(k, n) ⇒ Object



35
36
37
# File 'lib/muflax/math.rb', line 35

def choose k, n
  Math.factorial(n) / (Math.factorial(k) * Math.factorial(n - k))
end

.factorial(n) ⇒ Object



31
32
33
# File 'lib/muflax/math.rb', line 31

def factorial n
  (2..n).reduce(1){|f, x| f * x}
end

.harmonic(n) ⇒ Object



8
9
10
# 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) ⇒ Object



39
40
41
42
# 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) ⇒ Object



44
45
46
47
# 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) ⇒ Object Also known as: sufficient

TODO meh iterative solution



24
25
26
27
28
# File 'lib/muflax/math.rb', line 24

def sufficiency exceptions
  n = 1
  n += 1 while θ(n) < exceptions
  n
end

.tolerance(total) ⇒ Object Also known as: tolerate, θ



16
17
18
19
# File 'lib/muflax/math.rb', line 16

def tolerance total
  θ = total / Math.log(total)
  θ > total ? total : θ.round
end

.zipf(k, n) ⇒ Object



12
13
14
# File 'lib/muflax/math.rb', line 12

def zipf k, n
  1.0 / (k.to_f * harmonic(n))
end