All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nfunk.jep.function.Binomial Maven / Gradle / Ivy

Go to download

JEP is a Java library for parsing and evaluating mathematical expressions. Use groupId org.fudaa to deploy it in maven central

The newest version!
/* @author rich
 * Created on 13-Feb-2005
 *
 * See LICENSE.txt for license information.
 */
package org.nfunk.jep.function;

import java.util.Stack;

import org.nfunk.jep.ParseException;

/**
 * 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 */ public class Binomial extends PostfixMathCommand { static final int initN = 20; static int[][] coeffs = new int[initN+1][]; /** Static initialiser for binomial coeffs */ { coeffs[0] = new int[1]; coeffs[0][0] = 1; coeffs[1] = new int[2]; coeffs[1][0] = 1; coeffs[1][1] = 1; for(int n=2;n<=initN;++n) { coeffs[n] = new int[n+1]; coeffs[n][0] = 1; coeffs[n][n] = 1; for(int j=1;j nInt) throw new ParseException("Binomial: illegal values for arguments 0





© 2015 - 2024 Weber Informatics LLC | Privacy Policy