Extreme Optimization > Mathematics Library for .NET > User's Guide > Current Page > General Matrices

Extreme Optimization Mathematics Library for .NET

General matrices

A GeneralMatrix represents a dense matrix with arbitrary components.

How general matrices are stored

The components of a GeneralMatrix are stored in a one-dimensional Double array. Matrix components can be stored in two ways: column major and row major. Column major order means that the components of each column are stored in adjacent elements of the array. Row major order means that the components of each row are stored in adjacent elements of the array.

For historical reasons, most linear algebra algorithms have been optimized for column major storage. For this reason, column major order is the default. Row major order is supported transparently. Conversions are performed when necessary. Very often, row major order can be used without any significant loss of speed.

The element order is usually only important when initializing the components of a matrix. No application should have any other explicit depency on the way matrix components are stored.

The element order is given by the ElementOrder property, which is of type MatrixElementOrder. Possible values are ColumnMajor, RowMajor and NotApplicable.

Constructing general matrices

The constructors for GeneralMatrix fall into three clear groups.

The first group has two members. The first constructor has two parameters: the number of rows and the number of columns in the matrix. This creates a matrix with the specified number of rows and columns. All components are initially set to zero. The example below creates a matrix with 3 rows and 4 columns:

GeneralMatrix m1 = new GeneralMatrix(3, 4);
C#VB.NET 

A third parameter can be added that specifies the order in which matrix components are stored. This parameter is of the MatrixElementOrder enumeration type. The following creates a matrix with 3 rows and 4 columns, whose elements are stored in row major order:

GeneralMatrix m2 = new GeneralMatrix(3, 4, MatrixElementOrder.RowMajor);
C#VB.NET 

The second group of constructors lets you initialize the matrix. The first and second parameters are once again the number of rows and the number of columns. The matrix is initialized using the values in a Double array. For example, to create a matrix with 3 rows and 2 columns, you need:

double[] components = {11, 21, 31, 12, 22, 32};
GeneralMatrix m3 = new GeneralMatrix(3, 2, components);
C#VB.NET 

The elements are stored in column major order by default. This means that the first column has as its components 11, 21, and 31. The first row has components 11 and 12.

You can specify the order of the componets by adding a parameter of type MatrixElementOrder. The following creates a matrix that is identical to the previous one, but its elements are provided and stored in row major order:

double[] componentsByRow = {11, 12, 21, 22, 31, 32};
GeneralMatrix m4 = new GeneralMatrix(3, 2, components,
        MatrixElementOrder.RowMajor);
C#VB.NET 

By default, the matrix elements are copied from the component array to a private storage array. This may become expensive when the number of components is large. You can let the new matrix reuse the component array by supplying a Boolean parameter with a value of True. The example below creates matrices identical to the two examples above, but the componentarray is reused:

// Column major order:
double[] components = {11, 21, 31, 12, 22, 32};
GeneralMatrix m5 = new GeneralMatrix(3, 2, components, true);
// Row major order:
double[] componentsByRow = {11, 12, 21, 22, 31, 32};
GeneralMatrix m6 = new GeneralMatrix(3, 2, components,
        MatrixElementOrder.RowMajor, true);
C#VB.NET 

It is important to note the effects of reusing the component array. Any change to an element of the component array will change the corresponding component of the matrix, and vice versa. In general, the component array should not be used for any other purpose.

One last constructor uses a two-dimensional Double array that contains the components of the new matrix. It is not necessary to specify the number of rows and columns. These are taken from the dimensions of the component array. Let's once again construct the same matrix using this last constructor:

double[,] components = {{11, 12}, {21, 22}, {31, 32}};
GeneralMatrix m7 = new GeneralMatrix(components);
C#VB.NET 

It is generally recommended to not use two-dimensional arrays. This constructor is mostly supplied for convenience.

Overview
Introduction
Features
Documentation
QuickStart Samples
Sample Applications
Downloads
Get it now!
Download trial version
How to Buy
Search

"The Extreme Optimization Statistics Library for .NET is a major boon for those doing statistical work in .NET. I strongly recommend this product."
- Marc Brooks

"I have made it my mission to institutionalize the value of good API design.  I strongly believe that this is key to making developers more productive and happy on our platform. It is clear that you value good API design in your work, and take to heart developer productivity and synergy with the .NET framework."
- Brad Abrams,
Lead Program Manager, Microsoft.

This is a partial list of companies who are using our libraries:
ABB Robotics
Allstate
Applied Materials
Arcam
Astra Schedule
Babson College
Canadian Council on Learning
Canyon Associates
Caxton Associates
CECity
Constellation Energy
CreditSights
DeepOcean
Duke University
Dynamotive
Elecsoft
Engelhard Corporation
Epcor
Equipoise Software
Galileo International
GAM UK
Gammex
GlaxoSmithKline
Global Matrix
The Hartford
Infinera Corporation
Intel
JDS Uniphase
LaBranche & Co.
Learning & Skills Council
Jacobs Consultancy
Litman Gregory
Lucas Systems
Malvern Instruments
Medrio
Merck & Co.
Mintera.
Monitor Software
MorningStar
NanoString Technologies
Paletta Invent
Parametric Portfolio Associates
Prosanos
RATA Associates
RiskShield
Ramboll
Standard & Poor's
Strategic Analysis Corporation
Univ. of Alicante
Univ. of South Carolina
vielife
Xerox
US Army