exmath v0.2.5 Exmath

Summary

Functions

Get the average growth between two points in a graph

Calculates the n-th bell number. A bell number is how many ways you can partition n elements

Factorial will multiply n with n-1 until n <= 1

Hypergeometric distribution without replacement

Combinations formula. A formula for the number of possible combinations of r elements from a set of n elements. In combinations order doesn’t matter

Permutations formula. A formula for the number of possible permutations of r elements from a set of n elements

Prints row r of Pascal’s triangle. Calculated using the previously implemented nCr formula. Be aware; Pascal’s triangle starts with 0 both column- and row-wise

Calculates the hypothenus using the pythagoras theorem

Computes the stirling number of the second kind. This is how many ways you can partition n elements into k groups

Functions

acos(x)

See :math.acos/1.

acosh(x)

See :math.acosh/1.

asin(x)

See :math.asin/1.

asinh(x)

See :math.asinh/1.

atan(x)

See :math.atan/1.

atan2(x, y)

See :math.atan2/2.

atanh(x)

See :math.atanh/1.

average_growth(p1, p1)
average_growth({number, number}, {number, number}) :: float

Get the average growth between two points in a graph.

Example

Imagine we have the two points (1, 1) and (10, 10). The mathematical formula for calculating this is delta-y/delta-x.

iex> Exmath.average_growth({1, 1}, {10, 10})
1.0
bell_number(n)
bell_number(number) :: float

Calculates the n-th bell number. A bell number is how many ways you can partition n elements.

Example

If you have a set of 10 images, how many different ways can you group them?

iex> Exmath.bell_number(10)
115_975.0
cos(x)

See :math.cos/1.

cosh(x)

See :math.cosh/1.

exp(x)

See :math.exp/1.

factorial(n)
factorial(number) :: integer

Factorial will multiply n with n-1 until n <= 1.

Example

iex> Exmath.factorial(4)
24
hypergeometric_distribution(k, nn, kk, n)
hypergeometric_distribution(number, number, number, number) :: float

Hypergeometric distribution without replacement

Parameters

  • k -> how many wins
  • nn -> total pool
  • kk -> target total (wins + losses)
  • n -> how many to draw

Example

Imagine we have an urn of 50 marbles. 5 green ones and 45 red ones. Blindly we will take 10 marbles from the urn. What is the likelihood that we will draw 4 green and 6 red marbles.

This means we will have k=4, n=10, N=50, K=5.

iex> Float.round Exmath.hypergeometric_distribution(4, 50, 5, 10), 5
0.00396
log(x)

See :math.log/1.

log10(x)

See :math.log10/1.

log2(x)

See :math.log2/1.

nCr(n, r)
nCr(number, number) :: float

Combinations formula. A formula for the number of possible combinations of r elements from a set of n elements. In combinations order doesn’t matter.

Example

We have 5 balls, in how many ways can we select 3 of them?

iex> Exmath.nCr(5, 3)
10.0
nPr(n, r)
nPr(number, number) :: float

Permutations formula. A formula for the number of possible permutations of r elements from a set of n elements.

Example

How many ways can 4 students from a group of 15 be lined up for a photograph?

iex> Exmath.nPr(15, 4)
32760.0
pascals_triangle_row(r)
pascals_triangle_row(number) :: [float]

Prints row r of Pascal’s triangle. Calculated using the previously implemented nCr formula. Be aware; Pascal’s triangle starts with 0 both column- and row-wise.

Example

What is the 4th row of pascals triangle.

iex> Exmath.pascals_triangle_row(3)
[1.0, 3.0, 3.0, 1.0]
pow(x, y)

See :math.pow/2.

pythagoras(x, y)
pythagoras(number, number) :: float

Calculates the hypothenus using the pythagoras theorem

Example

iex> Exmath.pythagoras(4, 3) 5.0

sin(x)

See :math.sin/1.

sinh(x)

See :math.sinh/1.

sqrt(x)

See :math.sqrt/1.

stirlings2(n, n)
stirlings2(number, number) :: float

Computes the stirling number of the second kind. This is how many ways you can partition n elements into k groups.

Example

Let’s say you have 10 images, how many ways can you partition those images into 3 groups?

iex> Exmath.stirlings2(10, 3)
9330.0
tan(x)

See :math.tan/1.

tanh(x)

See :math.tanh/1.