public class FunctionOps extends Object
| Modifier and Type | Method and Description |
|---|---|
static double |
combination(int n,
int k)
Compute the combination function or binomial coefficient.
|
static double |
dotProduct(double[] x1,
double[] x2)
\(x_1 \cdot x_2\)
This operation is called inner product when used in the context of vector space.
|
static long |
dotProduct(long[] x1,
long[] x2)
\(x_1 \cdot x_2\)
This operation is called inner product when used in the context of vector space.
|
static double |
factorial(int n)
n!
|
static int |
gcd(int a,
int b)
Calculates the greatest common divisor of integer a and integer b.
|
static int |
lcm(int a,
int b)
Calculates the least common multiple of integer a and integer b.
|
static double |
linearInterpolate(double x,
double x0,
double y0,
double x1,
double y1)
Linear interpolation between two points.
|
static long |
mod(long x,
long m)
Compute the positive modulus of a number.
|
static long |
modpow(long base,
long exponent,
long modulus)
be mod m
|
static double |
permutation(int n,
int k)
Compute the permutation function.
|
public static long modpow(long base,
long exponent,
long modulus)
be mod mWe use the fact that
(a * b) mod m = ((a mod m) * (b mod m)) mod mThis code may fail without being noticed for very large numbers because overflow in integer operations does not throw any exception in the JVM.
base - positive integer bexponent - positive integer emodulus - positive integer mIllegalArgumentException - if not all inputs are positive integerspublic static long mod(long x,
long m)
-1 mod 5 = 4
x - an integerm - the moduluspublic static long dotProduct(long[] x1,
long[] x2)
x1 - a long arrayx2 - a long arraypublic static double dotProduct(double[] x1,
double[] x2)
x1 - a double arrayx2 - a double arraypublic static double factorial(int n)
n - an integerpublic static double combination(int n,
int k)
n - the size of the full setk - the size of a combinationpublic static double permutation(int n,
int k)
k-permutations from a larger set of n elements.n - the size of the full setk - the size of a permutationpublic static double linearInterpolate(double x,
double x0,
double y0,
double x1,
double y1)
x - xx0 - x0y0 - y0x1 - x1y1 - y1public static int gcd(int a,
int b)
a - an integerb - an integerpublic static int lcm(int a,
int b)
a - an integerb - an integerCopyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.