utilities
Class Binomial

java.lang.Object
  |
  +--utilities.Binomial

public class Binomial
extends java.lang.Object

A class to compute a binomial function. There are two options with this class. First, you might just call longBinom as a static function, which will calculate the binomial you seek on the spot. If you will be doing alot of similar calculations a better option is to initialize the function with a largest N, this stores all the binomials in memory which (although big) has the advantage of saving a lot of time. Since it takes up so much memory, it is worth getting rid of as quickly as possible (i.e. make it with very small scope)!

Author:
Kevin Zollman

Constructor Summary
Binomial()
          Constructor that does nothing
Binomial(int N)
          Constructor that builds a class for speedy multiple callse
 
Method Summary
 java.math.BigDecimal binom(int N, int K)
          Determines a binomial function N choose K.
static java.math.BigDecimal longBinom(int N, int K)
          Determines the binomial function.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Binomial

public Binomial()
Constructor that does nothing


Binomial

public Binomial(int N)
Constructor that builds a class for speedy multiple callse

Parameters:
N - Biggest N for future use
Method Detail

longBinom

public static java.math.BigDecimal longBinom(int N,
                                             int K)
Determines the binomial function. This does everything locally, it is used if a binomial is called without being initialized first.

Parameters:
N - n of the binomial function
Returns:
n choose k

binom

public java.math.BigDecimal binom(int N,
                                  int K)
Determines a binomial function N choose K. It checks to see if the result is in the calculated range first, if it is this function returns the value. Otherwise it calls longBinom() and calculates it on the spot.

Parameters:
N - n
K - k
Returns:
N choose K