public class DoubleArray extends Object
Constructor and Description |
---|
DoubleArray() |
Modifier and Type | Method and Description |
---|---|
static double[][] |
add(double[][] M,
double a)
Adds a single value to a matrix, e.g.
|
static double[][] |
add(double[][] M1,
double[][] M2)
Adds a matrix to another matrix, which should be of the same dimension.
|
static double[][] |
buildXY(double[] X,
double[] Y)
Join two arrays into a matrix.
|
static double[][] |
buildXY(double Xmin,
double Xmax,
double[] Y)
Generate a two column matrix.
|
static void |
checkColumnDimension(double[][] M,
int n)
Checks to make sure each row of a matrix is of a specified dimension.
|
static void |
checkLength(double[] M,
int n)
Checks to make sure an array is of a specified length.
|
static void |
checkRowDimension(double[][] M,
int m)
Checks to make sure each column of a matrix is of a specified dimension.
|
static double[][] |
columnVector(double[] x)
Converts an n element array into an n x 1 matrix.
|
static double[] |
copy(double[] M)
Generate a copy of an array
|
static double[][] |
copy(double[][] M)
Generate a copy of a matrix
|
static double[] |
cumProduct(double[] v)
Calculates cumulative product of the values in an array.
|
static double[][] |
cumProduct(double[][] v)
Calculates the cumulative product of each column in a matrix.
|
static double[] |
cumSum(double[] v)
Calculates the cumulative sum of an array.
|
static double[][] |
cumSum(double[][] v)
Calculates the cumulative sum of each column in a matrix.
|
static double[] |
delete(double[] x,
int... J)
Delete a list of elements from an array.
|
static double[][] |
deleteColumns(double[][] x,
int... J)
Deletes a list of columns from a matrix.
|
static double[][] |
deleteColumnsRange(double[][] x,
int J1,
int J2)
Deletes a range of columns from a matrix.
|
static double[] |
deleteRange(double[] x,
int J1,
int J2)
Delete a range of elements from an array.
|
static double[][] |
deleteRows(double[][] x,
int... I)
Deletes a list of rows from a matrix.
|
static double[][] |
deleteRowsRange(double[][] x,
int I1,
int I2)
Deletes a range of rows from a matrix.
|
static double[][] |
diagonal(double... c)
Returns an m x m matrix.
|
static double[][] |
diagonal(int m,
double c)
Returns an m x m matrix.
|
static double[][] |
f(double[][] M,
Function f)
Apply a scalar function to every element of an array.
|
static double[] |
f(double[] M,
Function func)
Apply a scalar function to every element of an array.
|
static double[] |
fill(int m,
double c)
Provides an m element array filled with constant c.
|
static double[][] |
fill(int m,
int n,
double c)
Fills an m x n matrix of doubles with constant c.
|
static double[] |
findex(int m,
IndexFunction f)
Provides a sequence of values to which some function has been applied.
|
static double[] |
getColumnCopy(double[][][] M,
int j,
int k)
Extract one column from a three dimensional array.
|
static double[] |
getColumnCopy(double[][] M,
int j)
Extract one column from a matrix.
|
static int |
getColumnDimension(double[][] M,
int i)
Get the number of columns in a specified row of a matrix.
|
static double[][] |
getColumnsCopy(double[][] M,
int... J)
Extract specific columns from a matrix.
|
static double[][] |
getColumnsRangeCopy(double[][] M,
int j1,
int j2)
Extract a range of columns from a matrix.
|
static double[] |
getCopy(double[] M,
int... I)
Extract specific elements from an array.
|
static double[] |
getDiagonal(double[][] M,
int I)
Extract diagonal from a matrix.
|
static double[] |
getRangeCopy(double[] M,
int j1,
int j2)
Extract a section of an array.
|
static double[] |
getRowCopy(double[][] M,
int i)
Extract a row from a matrix.
|
static double[][] |
getRowsCopy(double[][] M,
int... I)
Extract specific rows from a matrix.
|
static double[][] |
getRowsRangeCopy(double[][] M,
int i1,
int i2)
Extract a range of rows from a matrix.
|
static double[][] |
getSubMatrixRangeCopy(double[][] M,
int i1,
int i2,
int j1,
int j2)
Carve out a submatrix from the input matrix and return a copy.
|
static double[][] |
identity(int m)
Generates an m x m identity matrix.
|
static double[] |
increment(double begin,
double pitch,
double end)
Generates an array of successive values from begin to
end with step size pitch.
|
static double[] |
increment(int m,
double begin,
double pitch)
Provides a sequence of successive values in an array.
|
static double[][] |
increment(int m,
int n,
double[] begin,
double[] pitch)
Generates an mxn matrix.
|
static double[][] |
increment(int m,
int n,
double begin,
double pitch)
Provides an mxn matrix.
|
static double[] |
insert(double[] x,
int I,
double... y)
Insert any number of values, or a single array, between 2 elements of an
array.
|
static double[][] |
insertColumns(double[][] x,
int J,
double[]... y)
Insert any number of arrays between 2 columns of a matrix.
|
static double[][] |
insertRows(double[][] x,
int I,
double[]... y)
Insert any number of arrays between 2 rows of a matrix.
|
static boolean |
isColumnDimension(double[][] M,
int n)
Same as checkColumnDimension() but just returns a boolean value rather
than throwing an exception.
|
static boolean |
isLength(double[] M,
int n)
Same as checkLength but returns a boolean value rather than throwing an
exception.
|
static boolean |
isRowDimension(double[][] M,
int m)
Same as checkRowDimension() but just returns a boolean value rather than
throwing an exception.
|
static void |
main(String[] args) |
static double |
max(double... M)
Finds maximum value in either a list of numbers or a single array.
|
static double[] |
max(double[][] M)
Finds the maximum value in each column of a matrix.
|
static int |
maxIndex(double... M)
Finds the index of the maximum value in a list of values or an array.
|
static int[] |
maxIndex(double[][] M)
Finds the indices of the minimum values in each column of a matrix.
|
static double[] |
merge(double[]... x)
Concatenates arrays.
|
static double[][] |
mergeColumns(double[]... x)
Combine a set of arrays into a matrix.
|
static double[][] |
mergeRows(double[]... x)
Combine a set of arrays into a matrix.
|
static double |
min(double... M)
Finds minimum value in either a list of numbers or a single array.
|
static double[] |
min(double[][] M)
Finds the minimum value in each column of a matrix.
|
static int |
minIndex(double... M)
Finds the index of the minumum value in a list of values or an array.
|
static int[] |
minIndex(double[][] M)
Finds the indices of the minimum values in each column of a matrix.
|
static double[] |
one(int m)
Deprecated.
use
fill(int m, double c) instead. |
static double[] |
one(int m,
double c)
Deprecated.
Use
fill(int m, double c) instead. |
static double[][] |
one(int m,
int n)
Deprecated.
use
fill(int m, int n, 1.0) instead. |
static double[][] |
one(int m,
int n,
double c)
Deprecated.
use
fill(int m, int n, double c) instead. |
static double |
product(double[] v)
Calculates the product of the values in an array.
|
static double[] |
product(double[][] v)
Calculates the product of the values in each column of a matrix.
|
static double[] |
random(int m)
Generates an m element array of random numbers uniformly distributed
between 0 and 1.
|
static double[] |
random(int m,
double min,
double max)
Generates an m element array of random numbers uniformly distributed
between min and max.
|
static double[][] |
random(int m,
int n)
Generates an m x n matrix of random numbers uniformly distributed between
0 and 1.
|
static double[][] |
random(int m,
int n,
double[] min,
double[] max)
Generates an m x n matrix of random numbers uniformly distributed
numbers.
|
static double[][] |
random(int m,
int n,
double min,
double max)
Generates an mxn matrix of random numbers uniformly distributed between
min and max.
|
static double[][] |
resize(double[][] M,
int m,
int n)
Generate a resized copy of a matrix
|
static double[][] |
rowVector(double[] x)
Converts an n element array into an 1 x n matrix.
|
static double[] |
sort(double[] values)
Sorts an array in ascending order.
|
static double[][] |
sort(double[][] values,
int column)
Sorts the rows of a matrix using a specified column as the key.
|
static double |
sum(double[] v)
Calculate the sum of the values in an array
|
static double[] |
sum(double[][] v)
Calculates the sum of each column in a matrix.
|
static void |
throwError(String msg)
Throws an error exception if an argument is invalid.
|
static String |
toString(double[]... v)
Generates a string that holds a nicely organized space-seperated version
of a matrix or array.
|
static String |
toString(String format,
double[]... v)
Generates a string that holds a nicely organized version of a matrix or
array.
|
static double[][] |
transpose(double[][] M)
Transposes an mxn matrix into an nxm matrix.
|
public static void main(String[] args)
public static double[][] add(double[][] M, double a)
public static double[][] add(double[][] M1, double[][] M2)
public static double[][] identity(int m)
double[][] id = identity(3);
Result is:
1.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
m
- an integer > 0.public static double[][] diagonal(int m, double c)
double[][] eig = diagonal(3, 2.1);
Result is:
2.1 0.0 0.0
0.0 2.1 0.0
0.0 0.0 2.1
m
- an integer > 0.c
- Constant that lies along diagonal. Set c=1 for identity
matrix.public static double[][] diagonal(double... c)
double[][] eig = diagonal(1.0,2.0,3.0);
Result is:
1.0 0.0 0.0
0.0 2.0 0.0
0.0 0.0 3.0
c
- Values that lies along diagonal.public static double[][] one(int m, int n)
fill(int m, int n, 1.0)
instead.m
- Number of rows in returned matrixn
- Number of columns in returned matrixpublic static double[][] one(int m, int n, double c)
fill(int m, int n, double c)
instead.m
- Number of rows in returned matrixn
- Number of columns in returned matrixc
- Constant that fills matrixpublic static double[] one(int m)
fill(int m, double c)
instead.m
- Number of elements in returned arraypublic static double[] one(int m, double c)
fill(int m, double c)
instead.m
- Number of elements in returned arrayc
- Constant that fills arraypublic static double[][] fill(int m, int n, double c)
double[][] u = fill(2, 3, 1.0);
Result is:
1.0 1.0 1.0
1.0 1.0 1.0
m
- Number of rows in matrixn
- Number of columns in matrixc
- constant that fills matrixpublic static double[] fill(int m, double c)
double[] u = fill(3, 1.0);
Result is:
1.0 1.0 1.0
m
- Number of elements in returned arrayc
- Constant that fills arraypublic static double[][] random(int m, int n)
m
- Number of rows in matrixn
- Number of columns in matrixpublic static double[] random(int m)
m
- Size of arraypublic static double[][] random(int m, int n, double min, double max)
m
- Number of rows in matrixn
- Number of columns in matrixmin
- minimum value of the random numbersmax
- maximum value of the random numberspublic static double[] random(int m, double min, double max)
m
- Size of arraymin
- minimum value of the random numbersmax
- maximum value of the random numberspublic static double[][] random(int m, int n, double[] min, double[] max)
m
- Number of rows in matrixn
- Number of columns in matrixmin
- minimum value of the random numbers in a columnmax
- maximum value of the random numbers in a columnpublic static double[][] increment(int m, int n, double begin, double pitch)
m
- Number of rows in matrixn
- Number of columns in matrixbegin
- First value in sequencepitch
- Step size of sequencepublic static double[] increment(int m, double begin, double pitch)
m
- Size of arraybegin
- Starting valuepitch
- Step sizepublic static double[][] increment(int m, int n, double[] begin, double[] pitch)
m
- Number of rows in matrixn
- Number of columns in matrixbegin
- Array of starting values for each column. length must = n.pitch
- Array of step sizes for each column. length must = n.public static double[] increment(double begin, double pitch, double end)
begin
- First value in sequencepitch
- Step size of sequenceend
- Last value of sequencepublic static double[] copy(double[] M)
M
- Input array.public static double[][] copy(double[][] M)
M
- Input matrix.public static double[][] resize(double[][] M, int m, int n)
M
- Input matrix.m
- number of rows of new matrix.n
- number of columns of new matrix.public static double[][] getSubMatrixRangeCopy(double[][] M, int i1, int i2, int j1, int j2)
double[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,25,26,27,28}};
double[][] b = getSubMatrixRangeCopy(a, 2, 3, 1, 3);
input is:
0 1 2 3 4
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
4 25 26 27 28
result is:
13 14 15
19 20 21
M
- Input matrixi1
- Index of first row in cuti2
- Index of last row in cutj1
- Index of first column in cutj2
- Index of last column in cutpublic static double[][] getColumnsRangeCopy(double[][] M, int j1, int j2)
double[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,25,26,27,28}};
double[][] z = getColumnsRangeCopy(a, 2, 4);
input is:
0 1 2 3 4
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
4 25 26 27 28
result is:
2 3 4
8 9 10
14 15 16
20 21 22
26 27 28
M
- Input matrixj1
- Index of first column to be extracted.j2
- Index of last column to be extracted.public static double[][] getColumnsCopy(double[][] M, int... J)
double[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,25,26,27,28}};
double[][] z = getColumnsCopy(a, 2, 4);
input is:
0 1 2 3 4
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
4 25 26 27 28
result is:
0 2 4
1 8 10
2 14 16
3 20 22
4 26 28
M
- Input matrixJ
- Each is the index of a column. There can be as many indices
listed as there are columns in M.public static double[] getColumnCopy(double[][] M, int j)
double[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,25,26,27,28}};
double[][] z = getColumnCopy(a, 2);
input is:
0 1 2 3 4
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
4 25 26 27 28
Result is:
2 8 14 20 26
M
- Input matrixj
- Index of desired columnpublic static double[] getColumnCopy(double[][][] M, int j, int k)
M
- Input 3D arrayj
- The index of the second dimension.k
- The index of the third dimensionpublic static double[][] getRowsCopy(double[][] M, int... I)
double[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,25,26,27,28}};
double[][] z = getRowsCopy(a, 2, 4);
input is:
0 1 2 3 4
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
4 25 26 27 28
result is:
2 13 14 15 16
4 25 26 27 28
M
- Input matrixI
- Each is the index of a column.public static double[] getRowCopy(double[][] M, int i)
double[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,25,26,27,28}};
double[] z = getRowCopy(a, 2);
input is:
0 1 2 3 4
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
4 25 26 27 28
result is:
2 13 14 15 16
M
- Input matrixi
- index of row to copypublic static double[][] getRowsRangeCopy(double[][] M, int i1, int i2)
double[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,25,26,27,28}};
double[][] z = getRowsRangeCopy(a, 2, 4);
input is:
0 1 2 3 4
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
4 25 26 27 28
result is:
2 13 14 15 16
3 19 20 21 22
4 25 26 27 28
M
- Input matrixi1
- Index of first row to be extracted.i2
- Index of last row to be extracted.public static double[] getRangeCopy(double[] M, int j1, int j2)
double[] a = {00,11,22,33,44,55,66,77,88,99};
double[] z = getRangeCopy(a, 2, 5);
result is:
22 33 44 55
M
- Input arrayj1
- Index of first term to getj2
- Index of last term to getpublic static double[] getCopy(double[] M, int... I)
double[] a = {00,11,22,33,44,55,66,77,88,99};
double[] z = getCopy(a, 2, 5);
result is:
22 55
M
- The input array.I
- the indices of the elements to extractpublic static int getColumnDimension(double[][] M, int i)
M
- Input matrixi
- Index of row whose column length will be returnedpublic static double[] getDiagonal(double[][] M, int I)
double[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,25,26,27,28}};
double[] z = getDiagonal(a, 1);
input is:
0 1 2 3 4
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
4 25 26 27 28
result is:
1 8 15 22
M
- Input matrixI
- index of diagonal to copypublic static double[][] mergeRows(double[]... x)
double[] a = {00,11,22,33,44}, b = {55,66,77,88};
double[][] z = mergeRows(a, b);
result is:
0 11 22 33 44
55 66 77 88
x
- Input arrayspublic static double[][] mergeColumns(double[]... x)
double[] a = {00,11,22,33,44}, b = {55,66,77,88,99};
double[][] z = mergeColumns(a, b);
result is:
0 55
11 66
22 77
33 88
44 99
x
- Input arrayspublic static double[][] columnVector(double[] x)
x
- n element arraypublic static double[][] rowVector(double[] x)
x
- n element arraypublic static double[] merge(double[]... x)
double[] a = {00,11,22,33,44}, b = {55,66,77,88,99};
double[] z = merge(a, b, a);
result is:
0 11 22 33 44 55 66 77 88 99 0 11 22 33 44
x
- Input arrayspublic static double[][] insertColumns(double[][] x, int J, double[]... y)
double[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,23,24,25,26}};
double[] b = {00,11,22,33,44}, c = {55,66,77,88,99};
double[][] z = insertColumns(a, 2, b, c);
input matrix is:
0 1 2 3 4
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
4 23 24 25 26
result is:
0 1 0 55 2 3 4
1 7 11 66 8 9 10
2 13 22 77 14 15 16
3 19 33 88 20 21 22
4 23 44 99 24 25 26
x
- Input m x n matrix.J
- Index of column before which the new columns will be inserted.y
- The arrays to be insertedpublic static double[][] insertRows(double[][] x, int I, double[]... y)
double[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22}};
double[] b = {0,11,22,33,44}, c = {55,66,77,88,99};
double[][] z = insertRows(a, 1, b, c);
result is:
0 1 2 3 4
0 11 22 33 44
55 66 77 88 99
1 7 8 9 10
2 13 14 15 16
3 19 20 21 22
x
- Input m x n matrix.I
- Index of row before which the new rows will be inserted.y
- The arrays to be insertedpublic static double[] insert(double[] x, int I, double... y)
double[] b = {00,11,22,33,44}, c = {55,66,77,88,99};
double[] z = insert(b, 2, 333, 444);
result is:
0 11 333 444 22 33 44
double[] z = insert(b, 2, c);
result is:
0 11 55 66 77 88 99 22 33 44
x
- Input array.I
- Index of element before which the values will be inserted.y
- Values to be inserted. Can also be a single array.public static double[][] deleteColumnsRange(double[][] x, int J1, int J2)
double[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,23,24,25,26}};
double[][] z = deleteColumnsRange(a, 1, 3);
result is:
0 4
1 10
2 16
3 22
4 26
x
- The input matrixJ1
- The Index of the first column to delete.J2
- The index of the last column to delete.public static double[][] deleteColumns(double[][] x, int... J)
double[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,23,24,25,26}};
double[][] z = deleteColumns(a, 1, 3);
result is:
0 2 4
1 8 10
2 14 16
3 20 22
4 24 26
x
- The input matrixJ
- The indices of the columns to be deleted. There must be no
more indices listed than there are columns in the input
matrix.public static double[][] deleteRowsRange(double[][] x, int I1, int I2)
double[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,23,24,25,26}};
double[][] z = deleteRowsRange(a, 1, 3);
result is:
0 1 2 3 4
4 23 24 25 26
x
- The input matrixI1
- The Index of the first row to delete.I2
- The index of the last row to delete.public static double[][] deleteRows(double[][] x, int... I)
double[][] a = {{0,1,2,3,4},{1,7,8,9,10},{2,13,14,15,16},{3,19,20,21,22},{4,23,24,25,26}};
double[][] z = deleteRows(a, 1, 3);
result is:
0 1 2 3 4
2 13 14 15 16
4 23 24 25 26
x
- The input matrixI
- The indices of the rows to delete.public static double[] deleteRange(double[] x, int J1, int J2)
double[] b = {00,11,22,33,44};
double[] z = deleteRange(b, 1, 3);
Result is:
0 44
x
- Input arrayJ1
- Index of first element to delete. Must be >= 0 and <= x.lengthJ2
- Index of last element to delete. Must be >= J1 and <= x.lengthpublic static double[] delete(double[] x, int... J)
double[] b = {00,11,22,33,44};
double[] z = deleteRange(b, 1, 3);
Result is:
0 22 44
x
- Input arrayJ
- Index of elements to delete. Each must be >= 0 and <= x.lengthpublic static double[][] buildXY(double Xmin, double Xmax, double[] Y)
double[] y = {0.0, 1.0, 4.0, 9.0, 16.0};
double[][] xy = buildXY(0.0, 4.0, y);
result:
0.0 0.0
1.0 1.0
2.0 4.0
3.0 9.0
4.0 16.0
Xmin
- The first value in the first columnXmax
- The last value in the first columnY
- An array that will fill the second column.IllegalArgumentException
public static double[][] buildXY(double[] X, double[] Y)
double[] x = {0,1,2};
double[] y = {1,7,8};
double[][] z = buildXY(x, y);
result is:
0 1
1 7
2 8
mergeColumns(double[][])
public static double[] min(double[][] M)
double[][] a = {{0, 1, 2, 3, 4},
{1, .7, 8, 9, 10},
{2, 13, 1.4, 1.5, 16},
{3, 19, 20, 21, 22},
{4, 23, 24, 25, 2.6}};
double[] z = min(a);
Result is:
0.0 0.7 1.4 1.5 2.6
M
- The input matrixpublic static double min(double... M)
M
- Can be a list of values e.g. min(1,22,333,.4) or an array.public static double[] max(double[][] M)
double[][] a = {{0, 1, 2, 3, 4},
{1, 7, 88, 9, 10},
{2, 13, 14, 15, 16},
{3, 19, 20, 201, 22},
{4, 23, 24, 25, 26}};
double[] z = max(a);
Result is:
4 23 88 201 26
M
- The input matrixpublic static double max(double... M)
M
- Can be a list of values e.g. min(1,22,333,.4) or an array.public static int[] minIndex(double[][] M)
double[][] a = {{0, 1, 2, 3, 4},
{1, .7, 8, 9, 10},
{2, 13, 1.4, 1.5, 16},
{3, 19, 20, 21, 22},
{4, 23, 24, 25, 2.6}};
int[] z = minIndex(a);
Result is:
0 1 2 2 4
M
- Input matrix.public static int minIndex(double... M)
M
- Can be a list of values e.g. minIndex(11,22,44,2) or an arraypublic static int[] maxIndex(double[][] M)
double[][] a = {{0, 1, 2, 3, 4},
{1, 7, 88, 9, 10},
{2, 13, 14, 15, 16},
{3, 19, 20, 201, 22},
{4, 23, 24, 25, 26}};
int[] z = maxIndex(a);
Result is:
4 4 1 3 4
M
- Input matrix.public static int maxIndex(double... M)
M
- Can be a list of values e.g. maxIndex(11,22,44,2) or an arraypublic static double sum(double[] v)
v
- input arraypublic static double[] sum(double[][] v)
v
- public static double[] cumSum(double[] v)
double[] b = {0,1,2,3,4};
double[] z = cumSum(b);
result is:
0 1 3 6 10
v
- Input array.public static double[][] cumSum(double[][] v)
double[][] a = {{0, 1, 2, 3, 4},
{1, 7, 8, 9, 10},
{2, 13, 14, 15, 16},
{3, 19, 20, 21, 22},
{4, 23, 24, 25, 26}};
double[][] z = cumSum(a);
result is:
0 1 2 3 4
1 8 10 12 14
3 21 24 27 30
6 40 44 48 52
10 63 68 73 78
v
- public static double product(double[] v)
v
- Input array.public static double[] product(double[][] v)
v
- Input matrix.public static double[] cumProduct(double[] v)
double[] b = {1,2,3,4};
double[] z = cumProduct(b);
Result is:
1 2 6 24
v
- Input arraypublic static double[][] cumProduct(double[][] v)
double[][] a = {{0, 1, 2, 3, 4},
{1, 7, 8, 9, 10},
{2, 13, 14, 15, 16},
{3, 19, 20, 21, 22},
{4, 23, 24, 25, 26}};
result is:
0 1 2 3 4
0 7 16 27 40
0 91 224 405 640
0 1729 4480 8505 14080
0 39767 107520 212625 366080
v
- public static String toString(double[]... v)
double[][] a = {{1.234, 4.5, 6.78},{1.2, 3.45, 6.789}};
System.out.println(tostring(a));
result is:
1.234 4.5 6.78
1.2 3.45 6.789
v
- Matrix or arraypublic static String toString(String format, double[]... v)
double[][] a = random(2, 3);
System.out.println(tostring("%7.3f", a));
result is:
0.654 0.115 0.422
0.560 0.839 0.280
format
- A standard format specifier for one valuev
- Matrix or arraypublic static void throwError(String msg)
msg
- Message to be printed if the error occurs.IllegalArgumentException
public static void checkColumnDimension(double[][] M, int n)
M
- Input matrixn
- Number of elements that should be in each row of MIllegalArgumentException
public static boolean isColumnDimension(double[][] M, int n)
M
- Input matrixn
- Number of elements that should be in each row of McheckColumnDimension(double[][], int)
public static void checkRowDimension(double[][] M, int m)
M
- Input matrixm
- Number of elements that should be in each column of M.IllegalArgumentException
public static boolean isRowDimension(double[][] M, int m)
M
- Input matrixm
- Number of elements that should be in each column of McheckRowDimension(double[][], int)
public static void checkLength(double[] M, int n)
M
- Input array.n
- Required number of elements in MIllegalArgumentException
public static boolean isLength(double[] M, int n)
M
- Input array.n
- Required number of elements in M.public static double[][] f(double[][] M, Function f)
double[] b = {{1,2,3,4},{5,6,7,8}};
Function inverse = new Function() { public double f(double x) { return 1/x; }};
double[] z = f(b, inverse);
Result is:
1.00 0.50 0.333 0.25
0.20 0.167 0.143 0.125
M
- The input arrayf
- Function objectpublic static double[] f(double[] M, Function func)
double[] b = {1,2,3,4};
Function inverse = new Function() { public double f(double x) { return 1/x; }};
double[] z = f(b, inverse);
Result is:
1.00 0.50 0.33 0.25
M
- The input arrayfunc
- Function object whose sole method f(double) has already been
overridden.public static double[] findex(int m, IndexFunction f)
IndexFunction square = new IndexFunction()
{ public double fi(int x) { return x*x; }};
double[] z = findex(5, square);
Result is:
0 1 4 9 16
m
- Number of terms in the output array. The values 0..m-1 will be
fed to the functionf
- An IndexFunction object whose method fi(int) has already been
overridden.public static double[] sort(double[] values)
values
- Input arraypublic static double[][] sort(double[][] values, int column)
double[][] a = {{3, 5, 2, 1, 2},
{1, 3, 8, 9, 0},
{2, 4, 2, 5, 6},
{0, 1, 2, 3, 4},
{4, 2, 1, 5, 2}};
double[][] z = sort(a,1);
Result is:
0 1 2 3 4
4 2 1 5 2
1 3 8 9 0
2 4 2 5 6
3 5 2 1 2
Fixed (I hope) 3/28/06.values
- Input matrixcolumn
- Index of column to be used as the sorting key.public static double[][] transpose(double[][] M)
M
- Input matrix.Jas4pp 1.5 © Java Analysis Studio for Particle Physics