|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.unibi.techfak.misc.MathTools
public class MathTools
Class for holding methods with mathmatical background, such as matrix operations, list sorting, and so on.
| Field Summary | |
|---|---|
private static long |
serialVersionUID
The seriel version number of this class. |
| Constructor Summary | |
|---|---|
MathTools()
|
|
| Method Summary | |
|---|---|
static double[][] |
array2matrix(double[] arr,
int rows,
int cols)
Creates a matrix of cols columns and rows
rows and fills it with the given array. |
static double[] |
arraycpy(double[] dest,
double[] src)
Copies the 'src' array into 'dest'. |
static int[] |
arraycpy(int[] dest,
int[] src)
Copies the 'src' array into 'dest'. |
static int |
dist(int one,
int two)
Calculates and returnes the distance between the two int values. |
static int[] |
extendArray(int before,
int[] array,
int after)
The given array is changed in its size. |
static double[][] |
matrixadd(double[][] dest,
double[][] add)
Adds two double matrices, the first matrix is overwritten (addition is in-place) and returned. |
static double[][] |
matrixclone(double[][] m)
Clones a matrix of doubles deeply. |
static double[][] |
matrixclr(double[][] m)
The matrix entries are set to zero. |
static double[][] |
matrixcpy(double[][] dest,
double[][] src)
Copies the 'src' matrix into 'dest'. |
static int[][] |
matrixcpy(int[][] dest,
int[][] src)
Copies the 'src' matrix into 'dest'. |
static java.lang.Double[][] |
matrixCut(java.lang.Double[][] d,
int rows,
int cols)
A matrix of Doubles is cutted or pumped up to the
new Dimension. |
static double |
matrixdiff(double[][] m1,
double[][] m2)
The distances between two values of the same coordinates are summed-up. |
static java.lang.Double[][] |
matrixNew(double[][] d,
double nullV)
Creates a new matrix of Doubles from a matrix of
doubles. |
static double[][] |
matrixNew(java.lang.Double[][] D,
double nullV,
boolean ignoreNullRows)
Creates a new matrix of doubles from a matrix of
Doubles. |
static void |
matrixprint(double[][] m,
java.io.PrintStream out)
Prints a matrix 'm' to a given PrintStream. |
static double[][] |
matrixset(double[][] m,
double value)
All entries of the matrix 'm' are set to 'value'. |
static java.util.LinkedList |
mergeLists(java.util.LinkedList[] al,
boolean destroy,
boolean storeOrigin,
boolean permitDouble)
Merges all lists in the array to one linked list. |
static double |
round(double nr,
int fig)
Rounds a given number with the number of figures after the decimal point. |
static double |
round2(double nr,
int fig)
Rounds a given number with the number of significant figures. |
static int |
signum(int n)
Tests and returns the signum of an integer value. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final long serialVersionUID
| Constructor Detail |
|---|
public MathTools()
| Method Detail |
|---|
public static double[][] matrixclone(double[][] m)
m - The matrix to be cloned.
public static double[][] matrixadd(double[][] dest,
double[][] add)
dest - The destination matrix to get overwritten.add - The matrix to be added to the destination matrix.
public static double[][] matrixset(double[][] m,
double value)
m - The matrix to get overwritten.value - The value to overwrite every matrix entry.
public static double[][] matrixclr(double[][] m)
m - The matrix to get cleared.
matrixset(double[][], double)
public static double[][] matrixcpy(double[][] dest,
double[][] src)
dest - The destination matrix to be overwritten.src - The source matrix.
null in case of error.
public static int[][] matrixcpy(int[][] dest,
int[][] src)
dest - The destination matrix to be overwritten.src - The source matrix.
null in case of error.
public static double matrixdiff(double[][] m1,
double[][] m2)
m1 - The first matrix.m2 - The second matrix.
public static void matrixprint(double[][] m,
java.io.PrintStream out)
m - The matrix to be printed.out - The PrintStream to write to.
public static java.util.LinkedList mergeLists(java.util.LinkedList[] al,
boolean destroy,
boolean storeOrigin,
boolean permitDouble)
throws java.lang.ClassCastException
destroy = true the given lists are destroyed and
are empty after merging, otherwise the lists are untouched. Note, that
in either case the objects are not cloned, what means that unless the
source list is not destroyed both lists refer to the same elements.storeOrigin = true the result list holds
befor every value an Integer in range
[0, l.length-1] which specifys the list where the value
comes from. Setting permitDouble = true let the method
copy only the first of repeatedly occuring values regardless whether
they occur in the same list or in different lists. null
or empty. null values in the lists will not copied to
the result list. After merging with destroy = true
the lists consists of only null-entries.
al - An array of LinkedLists to merge.destroy - Whether or not to clear the original lists.storeOrigin - Whether or not storing the origin of the value.permitDouble - Whether or not permitting the same values.
LinkedList with the
elements of the given lists.
java.lang.ClassCastException - - if one element is not comparable to
the other ones. The source lists might be changed in that case.
public static double[][] matrixNew(java.lang.Double[][] D,
double nullV,
boolean ignoreNullRows)
doubles from a matrix of
Doubles. Entries of null are translated
to nullV, e.g. Double.NaN.
D - The matrix of Doubles.nullV - The double representative of
null.ignoreNullRows - Ignores complete rows with only
null values.
public static java.lang.Double[][] matrixNew(double[][] d,
double nullV)
Doubles from a matrix of
doubles. Entries, that are equal to nullV
are translated to null.
d - The matrix of doubles.nullV - The double representative of
null.
public static java.lang.Double[][] matrixCut(java.lang.Double[][] d,
int rows,
int cols)
Doubles is cutted or pumped up to the
new Dimension. A new matrix of Doubles is always
generated.
d - The matrix of Doubles.rows - The new number of rows.cols - The new number of cols.
public static double[] arraycpy(double[] dest,
double[] src)
dest - The destination array to be overwritten.src - The source array.
null in case of error.
public static int[] arraycpy(int[] dest,
int[] src)
dest - The destination array to be overwritten.src - The source array.
null in case of error.
public static double round(double nr,
int fig)
round(1.4156, 3) yields
1.416. If the double number is Infinity or
NaN or zero it is not changed at all.
nr - The number to be rounded.fig - The precision of the rounding.
double representing the rounded number.
public static double round2(double nr,
int fig)
round2(1.4156e-14, 3) yields
1.42e-14. If the double number is Infinity or
NaN or zero it is not changed at all.
nr - The number to be rounded.fig - The number of significant figures.
double representing the rounded number.
public static int[] extendArray(int before,
int[] array,
int after)
before - The number of integers to preced the array with.array - The array to be extended.after - The number of integers appent to the array.
null returned, if the array is
null or less then one position in length.public static int signum(int n)
Math.
n - The integer to process the signum function on.
-1, iff n is negative, zero,
iff n is zero, in all other cases 1.
public static double[][] array2matrix(double[] arr,
int rows,
int cols)
cols columns and rows
rows and fills it with the given array. E.g. arr={1,2,3} cols=2 and
rows=3 would yield ( 1 2 ) ( 3 0 ) ( 0 0 ).
arr - The array to fill the matrix with.rows - The number of rows in the new matrix.cols - The number of columns in the new matrix.
null if rows
or cols are less than 1.
public static int dist(int one,
int two)
Integer.MAX_VALUE
this value is returned.
one - The first value for distance calculation.two - The second value for distance calculation.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||