New Matrices

Back to: Main contents.

Contents

Identity matrices (the Eye suite)
Partitioning matrices (the Block suite)
Concatenating matrices (the Merge suite)
Random matrices (the Randu and Randn suites)

Although the core matrix classes have constructors to generate new matrices, there are other ways of forming matrices. The suites in this section all generate new matrices, sometimes from old matrices, sometimes from scratch.

Identity matrices (the Eye suite)

Back to: Main contents, Top of section.

The Eye suite has two methods: one to generate an identity matrix and one to generate a matrix with a leading identity matrix.

public static Zmat o(int n)
Returns an identity matrix of order n.

public static Zmat o(int m, int n)
Returns an mxn matrix with ones on its main diagonal and zeros on its off diagonals.

Partitioning matrices (the Block suite)

Back to: Main contents, Top of section.

In many applications it is necessary to work with the blocks of a partitioned matrix; e.g.,

A = | A00 A01 A02 |
    | A10 A11 A12 |
If A is a Zmat, any particular Aij can be obtained by using A.get. But this procedure is unwieldy when all the submatrices of a partition are needed. The block suite provides a method for gathering all the matrices of the partition into a block matrix.

Specifically, in Jampack a block Zmat is a two-dimensional array of Zmats. The Zmats in a block Zmat are not arbitrary but must satisfy two conformity conditions.

For each i the blocks B[i][j] must have the same number of rows.

For each j the blocks B[i][j] must have the same number of columns
These conditions insure that a block Zmat represents a partition of a larger Zmat.

A partition of a matrix A can be specified by two arrays of integers. Specifically, if ii[] and jj[] are integer arrays of lengths m and n respectively with

bx <= ii[0] < ii[1] < ... < ii[m] <= rx + 1
and
bx <= jj[0] < jj[1] < ... < jj[n] <= cx + 1,
then the arrays specify an mxn block matrix whose (i,j)-block is A.get(ii[i], ii[i+1]-1, jj[j], jj[j+1]-1). This is the block matrix that is returned by the single method of the class Block.

public static Zmat[][] o(Zmat A, int ii[], int jj[])
Returns the block matrix whose (i,j)-block is
A.get(ii[i], ii[i+1]-1, jj[j], jj[j+1]-1).
Throws JampackException for illegal ii or jj.

Concatenating matrices (the Merge suite)

Back to: Main contents, Top of section.

In many applications it is necessary to merge matrices to form a single matrix. For example, given the matrices B00, B01, B10, and B11, we may want to form the matrix

A = | B00 B01 |
    | B10 B11 |
(the B's are called blocks of A). Of course the blocks must conform for the assembly to be successful. Specifically,
B00 and B01 must have the same number of rows.
B10 and B11 must have the same number of rows.
B00 and B10 must have the same number of columns.
B01 and B11 must have the same number of columns.

The Merge suite contains methods to merge blocks into larger matrices. For the basic routine the blocks are contained in an array of Zmats.

public static Zmat o(Zmat[][] B)
If B has m rows and n columns, this method returns the Zmat
           | B[0][0]   ... B[0][n-1]   |
           |    .             .        |
           |    .             .        |
           |    .             .        |
           | B[m-1][0] ... B[m-1][n-1] |
           
Throws a JampackExcption for nonconformity.
In many applications one has to merge only a few matrices, in which case it is unwieldy to create the block matrix B. For this reason, the Merge suite has a number of special methods which are fed the blocks to be merged directly. For example, the method
o23(B00, B01, B02,
    B10, B11, B12)
produces the matrix
| B00 B01 B02 |
| B10 B11 B12 |
Here is a list of the current methods of this form. The names have the form omn, where m and n are the dimensions of the block matrix. The arguments are all Zmats.

public static Zmat o12(B00, B01) 

public static Zmat o21(B00,
                       B10)

public static Zmat o22(B00, B01,
                       B10, B11)

public static Zmat o13(B00, B01, B02)

public static Zmat o31(B00,
                       B10,
                       B20) 

public static Zmat o23(B00, B01, B02,
                       B10, B11, B12)

public static Zmat o32(B00, B01,
                       B10, B11,
                       B20, B21) 

public static Zmat o33(B00, B01, B02
                       B10, B11, B12,
                       B20, B21, B22) 

Random matrices (the Rand suite)

Back to: Main contents, Top of section.

Jampack has a suite of functions for generating (pseudo) random matrices as well as other objects (e.g. arrays of doubles, Z1s, etc.) Two kinds of distributions are supported. Methods whose names begin with "u" return object with uniform random entries in the interval [0,1]. Methods whose names begin with "n" return objects with normal random entries having mean zero and standard deviation one.

public static double ud(), nd()
Returns a random double.

public static double[] udary(int n), ndary(int n)
Returns a one-dimensional array of length n consisting of random doubles.

public static double[][] udary(int m, int n), ndary(int m, int n)
Returns an mxn two-dimensional array of random doubles.

public static Z uz(), nz()
Returns a random Z, i.e., a Z whose real and imaginary parts are random.

public static Z1 uz1(int n), nz1(int n)
Returns a random Z1 of length n.

public static Zmat uzmat(int m, int n), nzmat(int m, int n)
Returns a random mxn Zmat.

The suite has a method to set the seed of the random number generator.

public static void setSeed(long seed)
Sets the seed of the random number generator to seed.