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

Extreme Optimization Mathematics Library for .NET

Operations On Matrices

The Extreme Optimization Mathematics Library for .NET provides static methods for all common operations on matrices and combined matrix-vector operations. Where applicable, overloaded operator methods are supplied for languages that support them. In addition, a series of instance methods have been defined. These provide more efficient use of resources. All instance methods return a reference to the (modified) instance. This enables their use in compound expressions.

Addition and subtraction

The Add and Subtract methods support matrix addition and subtraction. These methods have several overloads, corresponding to the most common composite operations. Performing several operations in one method call is more efficient, because a lot of overhead and most temporary storage can be eliminated. The following table lists the instance methods for addition and subtraction:

Method Description
a.Add(b) Adds the vector b to the vector a.
a.Add(f, b) Adds the scalar f times the vector b to the vector a.
a.Add(m, b) Adds the matrix m times the vector b to the vector a.
a.Subtract(b) Subtracts the vector b from the vector a.
a.Subtract(f, b) Subtracts the scalar f times the vector b from the vector a.
a.Subtract(m, b) Subtracts the matrix m times the vector b from the vector a.
Table 1. Matrix methods for addition and subtraction.

Also, two static Add and Subtract methods are available that return a new vector that is the sum or the difference of its two arguments. The overloaded addition (+) and subtraction (-) operators correspond to these two static methods. In languages that don't support operator overloading, you must use these methods.

Scaling

The Multiply method multiplies the components of a matrix by a real constant. The instance method with the same name scales the components of the instance. The static (Shared) method scales the matrix that was passed as the second argument.

The static Multiply method has equivalent operator overloads of the * and / operators. The table below summarizes the operator overloads and the static method equivalent for a Double a, and a Vector v.

Operator Static method equivalent
a * x Matrix.Multiply(a, x)
x * a Matrix.Multiply(a, x)
x / a Matrix.Divide(1/a, x)
Table 2. Matrix multiplication and division operators and their method equivalents.

The ScaleRows and ScaleColumns methods each take a Vector as their only argument. They multiply each row (column) of the matrix by the corresponding component of the vector. This is equivalent to multiplying a matrix on the left (right) by a diagonal matrix with diagonal specified by the vector. The UnscaleRows and UnscaleColumns methods perform the inverse operation. They divide each row or column by the corresponding component of the vector.

A note on compound assignment operators

The C# language does not provide for explicit overloading of compound assignment operators. A compound operator is translated into the operator followed by an assignment. This means that an expression like

a += b;

is exactly equivalent to

a = a + b;

This is important when working with reference types such as vectors. To perform the above addition, a new vector instance must be created to hold the sum of a and b. This new instance is then assigned to a, releasing the original value. This causes an unnecessary memory allocation. For large vectors, this may lead to excessive garbage collection, degrading overall performance.

References

G. H. Golub, C. F. Van Loan, Matrix Computations (3rd Ed), Johns Hopkins University Press, 1996.

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