Computer Algebra Kit (c) 1993,00 by Comp.Alg.Objects. All Rights Reserved.

**Maturity Index:** Relatively mature

There are methods to access, insert and remove rows and *columns*. Columns are collection objects of scalars (not vector objects). It's also possible to place or replace a scalar directly at a position given by a row and column index. See the documentation on **eachSequence** to access the scalar at a given row and column index.

**Note:** Matrix objects are meant for computational tasks. They are no substitute for a List or Collection object, and sometimes, e.g. for frequent random access, it's indeed better to work with a collection of collections than with a Matrix object.

+Creates a new, square matrix with the objects indiagonal:cltnOfScalars

+Creates a newcirculant:cltnOfScalars

+Creates a newcompanion:cltnOfScalars

+Creates a new rectangualr Hankel matrix, a matrix withhankel:rowScalars:colScalars

+Creates a new rectangualr Toeplitz matrix, a matrix withtoeplitz:rowScalars:colScalars

+Creates a new Hilbert matrix over the rational numbers. The element at positionhilbert:(int)n

+Creates a newscalar:aScalarnumRows:(int)numRowsnumColumns:(int)numColumns

aPolynomial = [Polynomial new]; aMatrix = [Matrix scalar:aPolynomial numRows:5 numColumns:5];

-Returns a new copy of the original; the rows are also copies of the original rows, not just new references.copy

-Makes a fully independent copy of the matrix.deepCopy

-Returns a new empty vector.emptyVector

-Returns the zero scalar element.scalarZero

-Returns the collection of row vectors; the first row is the first member of this collection.rows

- (int)Returns the number of rows in the matrix, or zero if there are no rows in the matrix. IfnumRows

- (int)Returns the number of columns in the matrix, or zero if there are no columns in the matrix. Note that ifnumColumns

- (BOOL)Returns YES if the matrices have the same number of rows and columns and if the scalars are equal.isEqual:aMatrix

- (unsigned)Returns a small integer that is the same for matrices that are equal (in the sense ofhash

- (BOOL)Returns YES if all scalars that are not on the diagonal of the matrix, are zero.isDiagonal

- (BOOL)Returns YES if the scalar at positionisSymmetric

- (BOOL)Returns YES if the scalar at positionisAntiSymmetric

-InsertsinsertRow:aVector

-Similar toinsertRow:aVectorat:(int)i

-InsertsinsertColumn:aCollection

-Similar toinsertColumn:aCollectionat:(int)i

-Removes (and returns) the last row of the matrix. ReturnsremoveRow

To remove a row, the reference count of the matrix must be equal to one.while (row = [matrix removeRow]) { /* do something with row */ }

-Similar toremoveRowAt:(int)i

-Removes (and returns) the first column of the matrix. The column is a collection of scalars, not a vector object. ReturnsremoveColumn

The reference count of the matrix must be equal to one.while (column = [matrix removeColumn]) { /* do something with column */ }

-Similar toremoveColumnAt:(int)i

-Frees the scalar at positionplaceScalar:aScalarat:(int)i:(int)j

The scalar *aScalar* belongs, after placing, to the receiving matrix object; it is not necessarily copied. It is an error to use illegal indices *i* and *j* or to attempt to place a scalar in a matrix whose reference count is not equal to one.

-Similar toreplaceScalarAt:(int)i:(int)jwith:aScalar

-Returns a new matrix, whose scalars are the numerical value of the scalars of the original matrix. For a matrix with integer scalars, this method returns a matrix with floating-point scalars.asNumerical

-Returns a new matrix, whose scalars are the value of the scalars of the original matrix modasModp:(unsigned short)p

-Puts a matrix with fractional scalars on a common denominator. Returns a new matrix with integral scalars, and, by reference, the common denominator of the scalars in the matrix (the least common multiple of the denominators of the fractions in the matrix).onCommonDenominator:(id *)denominator

-Returns therowAt:(int)i

int i; for(i=0;i<[aMatrix numRows];i++) { id aRow = [aMatrix rowAt:i]; /* do something with aRow */ }

-Returns a new sequence of the rows of the matrix. You cannot add or remove rows, or alter in any other way the matrix, until you're done with the sequence object (the sequence contains a reference to the rows of the matrix). TheeachRow

id aRow,aSequence; aSequence = [aMatrix eachRow]; while (aRow = [aSequence next]) { /* do something with aRow */ }

-Returns a new sequence of scalars, obtained by concatenating the sequences of scalars of all row vectors of the matrix. If the matrix containseachScalar

**Note:** The sequence returned by this method cannot be accessed through an index. It doesn't implement the **at:** and **toElementAt:** methods.

-Returns a new sequence of sequences of scalars. You cannot add or remove scalars, or alter in any other way the matrix, until you're done with the sequence object (the sequence contains a reference to the matrix). The following example shows how to access theeachSequence

aSequence = [aMatrix eachSequence]; aScalar = [[aSequence at:i] at:j]; /* do something here with aScalar */

- (float)Returns thefloatValueAt:(int)i:(int)j

-Returns a zero matrix of the same dimensions as the matrix that receives the message.zero

-Negates the matrix row by row.negate

-Returns a new matrix equal to the matrix multiplied by two. Multiplies the matrix row by row by two.double

-Returns a new matrix equal to the sum of the two matrices. Adds the matrices row by row together.add:b

-Returns a new matrix equal to the difference of the two matrices. Subtracts the matrices row by row from each other.subtract:b

-Adds the scalaraddScalar:s

-Subtracts the scalarsubtractScalar:s

-Returns the (right) unity matrix of the same dimensions as the matrix that receives the message.one

-Multiplies the (square) matrix by itself.square

-Returns the productmultiply:b

-Returns a new vector, the product of the matrix by a column vector object. The number of rows of the matrix must match the number of scalars in the vector.multiplyVector:aColumn

-Returns the matrix multiplied (to the right) by the scalarmultiplyScalar:b

-Returns the matrix divided by the scalardivideScalar:b

-Returns the transposed of the matrix (a new matrix object). If the matrix hastranspose

-Computes the determinant of the square matrix. Returns a new scalar object.determinant

For fields of fractions, the method will extract a common denominator for the scalars, and compute the determinant over the associated integral domain. For fields that are not fields of fractions, the method computes the determinant by Gaussian elimination taking inverses of leading non-zero elements. For matrices over an integral domain, the determinant is computed by the Bareiss method.

**Note:** You can't compute a determinant over the floating-point numbers yet.

-Returns a vectorsolveVector:y

The method works over fields and integral domains, but in the latter case, the method looks for an integral (and primitive i.e., common gcd divided out) solution only. It will give an error message if the solution requires the construction of the field of fractions.

-Returns the inverse of the matrix (a new matrix object). The matrix must be square; if it is singular (determinant equal to zero), the method returnsinverse

-Returns a new matrix, equal to the matrix multiplied to the right by the inverse of the matrixdivide:b

**Note:** Currently matrix inversion only works over a field (by Gaussian elimination).

- (int)Returns the dimension of the image of the matrix, without computing the image vectors themselves. Works currently only over a field.rank

- (int)Returns the dimension of the kernel (nullspace) of the matrix, without computing the kernel itself. By the dimension theorem, the nullity of the matrix is the number of columns minus the rank of the matrix.nullity

-Returns the kernel (or nullspace) of the matrix as a collection of columns; each column is a vector object. Works currently only over a field.kernel

-Returns the image of the matrix as a collection of columns; each column is a vector object. Works currently only over a field.image

-Returns a new scalar object, the trace of the square matrix, ie. the sum of the scalars on the diagonal of the matrix.trace

-Returns a new matrix, the adjoint of the matrix computed through repeated trace computations (ie. the Faddeev-Leverrier method). If the characteristic of the scalars is non-zero, it must be larger than the number of rows in the matrix.adjoint

-Prints, between braces, a comma separated list of the rows. SendsprintOn:(IOD)aFile