|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object | +--ArrayMath
ArrayMath is used to perform various calculations on arrays-- addition, multiplication, transposition. Invoke: java ArrayMath
| Constructor Summary | |
ArrayMath()
|
|
| Method Summary | |
static int[][] |
addArrays(int[][] array1,
int[][] array2)
Matrix addition. |
static void |
addOneToArray(int[][] array)
addOne adds one to every element of the array. |
static int |
dotProduct(int[] firstVector,
int[] secondVector)
Computes the dot product of two single-dimension vectors. |
static void |
main(java.lang.String[] args)
The main method, the entry point for the class when run from the command line. |
static int[][] |
multiplyArrays(int[][] array1,
int[][] array2)
Matrix multiplication. |
static void |
printArray(int[][] array)
Print out the contents of a 2-dimensional array. |
static void |
printVector(int[] vector)
prints out the contents of a one-dimensional array in the format (a, b, c). |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Constructor Detail |
public ArrayMath()
| Method Detail |
public static void main(java.lang.String[] args)
args[] - An array of String objects that contain command line argumentspublic static void printVector(int[] vector)
vector - the vector to be printed outpublic static void printArray(int[][] array)
array[][] - the array to be printed out
public static int dotProduct(int[] firstVector,
int[] secondVector)
firstVector - first input, single dimensioned, not changedsecondVector - second iput, single dimensioned, not changed
public static int[][] addArrays(int[][] array1,
int[][] array2)
This is hard-wired to handle two-dimensional arrays.
Again, it would be better to throw an exception if we have some show-stopping problem like mismatched array sizes rather than just return a null. But we don't know enough about exceptions yet.
array1 - The first input array, must be two-dimensional, not modified by this methodarray2 - second input array, not modified by this method
public static int[][] multiplyArrays(int[][] array1,
int[][] array2)
The number of coluns in a must match the number of rows in b. If this is not the case, the arrays can't be multiplied; null is returned. It would be better to throw an exception.
This is less than perfect, since it doesn't handle single-dimensioned arrays, which are legal; (1, 2, 3) * (1, 2, 3)^T, for example. Everything has to be framed in terms of 2D arrays.
array1 - some 2-dimensional array, number of columns must match number of rows in array2array2 - some 2-dimensional array, number of rows must match number of columns in array1public static void addOneToArray(int[][] array)
array - The array to be modified
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||