org.nfunk.jep.function
Class Binomial

java.lang.Object
  extended by org.nfunk.jep.function.PostfixMathCommand
      extended by org.nfunk.jep.function.Binomial
All Implemented Interfaces:
PostfixMathCommandI

public class Binomial
extends PostfixMathCommand

Binomial coeficients: binom(n,i). Requires n,i integers >=0. Often written nCi or column vector (n,i). (n,0) = 1, (n,1) = n, (n,n-1) = n, (n,n) = 1
(n,i) = n! / ( i! (n-i)! )
Pascals triangle rule: (n,i) = (n-1,i-1) + (n-1,i)
Binomial theorem: (a+b)^n = sum (n,i) a^i b^(n-i), i=0..n.

For efficiency the binomial coefficients are stored in a static array.

Author:
Rich Morris Created on 13-Feb-2005

Field Summary
 
Fields inherited from class org.nfunk.jep.function.PostfixMathCommand
curNumberOfParameters, numberOfParameters
 
Constructor Summary
Binomial()
           
 
Method Summary
static int binom(int n, int i)
          Returns the binomial coefficients.
 void run(java.util.Stack s)
          Throws an exception because this method should never be called under normal circumstances.
 
Methods inherited from class org.nfunk.jep.function.PostfixMathCommand
checkNumberOfParameters, checkStack, getNumberOfParameters, setCurNumberOfParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Binomial

public Binomial()
Method Detail

run

public void run(java.util.Stack s)
         throws ParseException
Description copied from class: PostfixMathCommand
Throws an exception because this method should never be called under normal circumstances. Each function should use it's own run() method for evaluating the function. This includes popping off the parameters from the stack, and pushing the result back on the stack.

Specified by:
run in interface PostfixMathCommandI
Overrides:
run in class PostfixMathCommand
Throws:
ParseException

binom

public static int binom(int n,
                        int i)
                 throws java.lang.ArrayIndexOutOfBoundsException
Returns the binomial coefficients.

Throws:
java.lang.ArrayIndexOutOfBoundsException - if n<0, i<0 or i>n


http://www.singularsys.com/jep Copyright © 2007 Singular Systems