appScience software



Matrix calculations

A matrix consists of a two dimensional array of numbers, arranged in rows and columns. Matrices can be manipulated like numbers except they have special multiplication and division properties. Formula calculator enables you to create matrices, will perform matrix multplications, divisions, additions and subtractions, as well as allowing matrices to be used as parameters in functions.

Creating a matrix: A matrix is created using the function

matrix(nr,nc, m11,m12, ..., m1nc, m21, m22 .... mnr nc)

where nr is an integer specifying the numbers of rows in the matrix and nc is an integer specifying the number of columns. Following these parameters is a list of the elements of the matrix separated by commas. The list must have nr*nc elements. For example a 3x2 matrix


would be specifed by myMatrix=matrix(3,2,0,2,-1,3,-4,6)

The matrix elements can be real or complex numbers, parameters, arrays of numbers (see ranges) or even other matrices.

Viewing matrix elements: Since matrices may contain many numbers, formula calculator does not show you the matrix contents, but lets you know the parameter is a matrix. For the above example we would see myMatrix=<matrix>. You can view the matrix values by clicking the 'matrix hidden' icon, which changes to the 'matrix shown' icon. Also you can access matrix elements using the element(myMatrix,n,m) function that returns the element of the matrix at row n and column m.


Matrix values hidden


Matrix values shown

Matrix operations: Formula calculator performs the usual matrix operations of addition, subtraction, multiplication and division. Division is performed by multplying by the matrix inverse. A matrix inverse is only possible for square matrices, where the number of rows equals the number of columns.

If the function or an operation is between a matrix and a single number, then formula calculator applies the operation to each element of the matrix. For example, myMatrix+2 would add 2 to every element in the matrix and myMatrix*2 multiplies every element by 2. Matrix inversion is then very simple. The expression inv=1/matrix causes formula calculator to invert the matrix and multiply the result by 1, assigning the result to inv.

If a matrix parameter is the argument of a non-matrix function, then the function is applied to every element of the matrix. For example, sin(myMatrix) would take the sine of each element in the matrix and return the result as another matrix.

Matrix functions: Other special matrix functions are:

  • transpose(matrix) - interchanges the rows and columns
  • adjoint(matrix) - returns the complex conjugate transpose of a matrix
  • det(matrix) - calculates the matrix determinant
  • eigenvalues(matrix,v,y) - returns eigenvectors (v) and eigenvalues (y) of the matrix
  • row(matrix,n) or column(matrix,n) - return the n-th row or column of the matrix