This project has moved. For the latest updates, please go here.
Matrices are arrays of numbers which can be added, subtracted, and multiplied together according to matrix multiplication rules. They appear in many areas of applied mathematics.

The Meta.Numerics library defines several different kinds of matrices. Many of the methods and properties of the the different matrix classes are anologous, but each one also offers members which exist only for that kind of matrix, and even for the common members the implementations are optimized for each particuar class of matrix.
  • RectangularMatrix: A matrix of real numbers with arbitrary numbers of rows and columns.
  • SquareMatrix: A matrix of real numbers with equal numbers of rows and columns.
  • SymmetricMatrix: A square matrix whose elements on opposite sides of the diagonal are equal.
  • TridiagonalMatrix: A square matrix whose entries are non-zero only along the diagonal and immediately above and below it.
  • ColumnVector: A N X 1 rectangular matrix.
  • RowVector: A 1 X N rectangular matrix.

Using the appropriate matrix class can result in very large efficiency gains. For example: the inversion of an arbitrary square matrix is an O(N^3) operation; the inversion of a tridiagonal matrix is an O(N) operation. So if you have a 1000x1000 tridiagonal matrix, using the TridiagonalMatrix class will allow you to invert it about 1,000,000 times faster than using the SquareMatrix class.


Meta.Numerics allows you to add, subtract, and multiply matrices of all types according to the usual rules.

For example, here is a stochastic matrix correspoding to a game of tag between players 0, 1, and 2. The state of the game is indicated by which player is "it". Player 0 is faster than player 1, who is faster than player 2. Each entry of the transition matrix gives the probability that a game that begines with that column number being "it" to end with that row number being "it".
SquareMatrix T = new SquareMatrix(3);
T[0,0] = 0.0; T[0,1] = 0.2; T[0,2] = 0.3;
T[1,0] = 0.4; T[1,1] = 0.0; T[1,2] = 0.7;
T[2,0] = 0.6; T[2,1] = 0.8; T[2,2] = 0.0;

The five-game transition matrix is simply T5. Here is some code that finds the probabilities for each player to be "it" after five games, assuming the game starts with "it" being player 0.

SquareMatrix T5 = T * T * T * T * T;
Console.WriteLine("{0}  {1}  {2}", T5[0,0], T5[1,0], T5[2,0]);

Last edited Sep 28, 2010 at 9:14 AM by ichbin, version 5


No comments yet.