|
| |
Matrix.NET - C# managed code classes for Linear Algebra.
View the
C# Finite Element Sample Program
here
Introduction
Matrix.NET 2.0 is a complete redesign
based on this premise:
|
|
0 is too valuable a symbol to
waste on a subscript,
so all Vector and Matrix subscripts are base 1. |
Matrix.NET gives you the classes you need to
make it even easier to program matrices & vectors, simply because the vast
majority of texts that discuss matrices and vectors use base 1. Translating from
a text to your program is thus greatly simplified.
-
Translate legacy Fortran to C#
without having to adjust all the subscripts back to 0.
-
Write your matrix expressions in
standard matrix notation, so you can work at a higher level, like this:
A = B * D * (E + F);
The Matrix & Vector
classes comply with .NET 2.0, and play well together.
-
We've added the IntMatrix and IntVector classes
to
handle those problems in which you need to use integers, rather than doubles.
-
All classes are serializable (that
is, can be written to, and read from, binary streams), so you can save your matrices
for later retrieval.
-
All methods are commented so that they
appear in the object browser.
-
Matrix.NET is sold as source code (more than
5000 lines), so in the event of .NET upgrades, a simple recompile will ensure
that your code is compatible over the long term.
-
Matrix.NET comes with the Engineering Objects Tester class,
and a program that exercises all the class methods, so you can
see clearly how they work.
-
Matrix.NET uses the fastest element .NET
access techniques. Our code is fast, so your code will be fast,
too.
-
And, the code is guaranteed; cf
Policies.
top
Namespaces
in the Distribution
|
Namespace |
Contents |
|
EngineeringObjects.LinearAlgebra |
C# code for Matrix,
Vector, IntMatrix, IntVector, EigenContainer, and exception classes |
|
EngineeringObjects.TestLinearAlgebra |
C# code to test (and
time) each constructor, property, method, exception |
| TestClasses |
C# code to execute the
tests |
|
EngineeringObjects.Functions |
C# code of several
functions omitted from System.Math |
| EngineeringObjects.Tester |
a 'lite' testing rig, cf
Test |
| XTest |
C# code to test Test |
The classes in the
LinearAlgebra namespace are shown below.
top
Delegates
namespace
{
public delegate
double Function(double
x);
public delegate
int IntFunction(int
x);
}
top
EigenContainer
[SerializableAttribute(..)]
[DefaultMemberAttribute(..)]
public class
EigenContainer {
public EigenContainer(int
size);
public
Vector EigenValues { get; }
public
Matrix EigenVectors { get; }
public
double this[int
componentValue, int vectorNumber] {
get; set; }
public void
InsertEigenValue(int index,
double value);
}
top
IntMatrix
[SerializableAttribute(..)]
[DefaultMemberAttribute(..)]
public class
IntMatrix {
public IntMatrix();
public IntMatrix(int
rows, int columns);
public IntMatrix(int[,]
a);
public IntMatrix(IntMatrix
source);
public int
Columns { get; }
public bool
IsSquare { get; }
public int
Max { get; }
public int
MaxOffDiagonal { get; }
public int
MaxOnDiagonal { get; }
public int
Rows { get; }
public int
this[int irow,
int icol] { get;
set; }
public
static IntMatrix Add(IntMatrix
addend, IntMatrix augend);
public
static IntMatrix Apply(IntMatrix
M, IntFunction f);
public
IntVector Column(int colIndex);
public bool
Conformant(IntMatrix that);
public void
CopyTo(IntMatrix to);
public
override bool Equals(object
obj);
public
IntMatrix Extract(int whereRow,
int whereCol, int sizeRow, int sizeCol);
public
static IntMatrix Extract(IntMatrix
source, int whereRow,
int whereCol, int sizeRow,
int sizeCol);
public void
Fill(int value);
public void
FillColumn(int colIndex,
int value);
public void
FillDiagonal(int value);
public void
FillRow(int rowIndex,
int value);
public void
FillWithIndexes();
public
override int GetHashCode();
public
static IntMatrix Identity(int
rows, int cols);
public void
Insert(IntMatrix subMatrix,
int whereRow, int
whereCol);
public
static IntMatrix Insert(IntMatrix
subMatrix, int whereRow,
int whereCol, IntMatrix
into);
public void
Print(string name);
public void
Print(string name, TextWriter tw);
public
IntVector Row(int rowIndex);
public
static IntMatrix Scale(IntMatrix
A, int value);
public
static IntMatrix Subtract(IntMatrix
subtrahend, IntMatrix minuend);
public
static IntMatrix Transpose(IntMatrix
M);
public int
UpperBound(int index);
public
static IntMatrix
operator +(IntMatrix aMatrix);
public
static IntMatrix
operator +(IntMatrix addend,
IntMatrix augend);
public
static IntMatrix
operator -(IntMatrix aMatrix);
public
static IntMatrix
operator -(IntMatrix minuend,
IntMatrix subtrahend);
public
static IntMatrix
operator *(int d,
IntMatrix A);
public
static IntMatrix
operator *(IntMatrix A,
int d);
public
static bool
operator ==(IntMatrix A,
IntMatrix B);
public
static bool
operator !=(IntMatrix A,
IntMatrix B);
}
top
IntVector
[SerializableAttribute(..)]
[DefaultMemberAttribute(..)]
public class
IntVector {
protected IntVector();
public IntVector(int
length);
public IntVector(int[]
a);
public IntVector(IntVector
source);
public int
Length { get; }
public int
Max { get; }
public int
Min { get; }
public int
Norm1 { get; }
public int
SizeSquared { get; }
public int
this[int index]
{ get; set; }
public
static IntVector Add(IntVector
addend, IntVector augend);
public
static IntVector Apply(IntVector
V, IntFunction f);
public
IntVector Clone();
public
static void Copy(IntVector
from, IntVector to);
public
static IntVector Cross(IntVector
a, IntVector b);
public
static int Dot(IntVector
a, IntVector b);
public
override bool Equals(object
o);
public void
Fill(int Value);
public void
Fill(int startValue,
int Increment);
public
override int GetHashCode();
public bool
IsIntVectorConformant(IntVector that);
public int
MaxAt(ref int
max);
public int
MinAt(ref int
min);
public void
Print(string name);
public void
Print(string vectorName, TextWriter tw);
public void
Reverse();
public
static IntVector Scale(int
d, IntVector aIntVector);
public
static IntVector Subtract(IntVector
minuend, IntVector subtrahend);
public void
Swap(int index1, int
index2);
public
static IntVector UnaryMinus(IntVector
aIntVector);
public
static void VerifyConformant(IntVector
a, IntVector b, string
msg);
public
static IntVector
operator +(IntVector aIntVector);
public
static IntVector
operator +(IntVector addend,
IntVector augend);
public
static IntVector
operator -(IntVector aIntVector);
public
static IntVector
operator -(IntVector minuend,
IntVector subtrahend);
public
static IntVector
operator *(int d,
IntVector a);
public
static IntVector
operator *(IntVector a,
int d);
public
static int
operator *(IntVector a,
IntVector b);
public
static IntVector
operator %(IntVector a,
IntVector b);
public
static bool
operator ==(IntVector a,
IntVector b);
public
static bool
operator !=(IntVector a,
IntVector b);
}
top
Matrix
[SerializableAttribute(..)]
[DefaultMemberAttribute(..)]
public class
Matrix {
protected Matrix();
public Matrix(double[,]
a);
public Matrix(int
rows, int columns);
public Matrix(Matrix
source);
public
double ColumnNorm { get; }
public int
Columns { get; }
public bool
IsPositiveDefinite { get; }
public bool
IsSquare { get; }
public
double Max { get; }
public
double MaxOffDiagonal { get; }
public
double MaxOnDiagonal { get; }
public
double RowNorm { get; }
public int
Rows { get; }
public
double SumOfSquaresOfDiagonal { get;
set; }
public
double this[int
irow, int icol] { get;
set; }
public
static Matrix Add(Matrix
addend, Matrix augend);
public
static Matrix Apply(Matrix
M, Function f);
public
static Matrix AtBA(Matrix
B, Matrix A);
public
Vector Column(int colIndex);
public bool
Conformant(Matrix that);
public void
CopyTo(Matrix to);
public
static Matrix
DirectionCosineTransformation(Matrix T,
Matrix M);
public
EigenContainer EigenExtraction();
public
override bool Equals(object
obj);
public
Matrix Extract(int whereRow,
int whereCol, int sizeRow, int sizeCol);
public
static Matrix Extract(Matrix
source, int whereRow,
int whereCol, int sizeRow, int sizeCol);
public void
Fill(double value);
public void
FillColumn(int colIndex,
double value);
public void
FillDiagonal(double value);
public void
FillRow(int rowIndex,
double value);
public void
FillWithIndexes();
public
override int GetHashCode();
public
static Matrix Hilbert(int
order);
public
static Matrix Identity(int
rows, int cols);
public void
Insert(Matrix subMatrix,
int whereRow, int
whereCol);
public
static Matrix Insert(Matrix
subMatrix, int whereRow,
int whereCol, Matrix
into);
public
static Matrix Invert(Matrix
M, ref double
logDeterminant, ref
double condition);
public
static Matrix InvertSymmetric(Matrix
M, ref double
logDeterminant, ref
double condition);
public
static Matrix Multiply(Matrix
multiplier, Matrix multiplicand);
public
static Vector Multiply(Matrix
multiplier, Vector multiplicand);
public
static Vector Multiply(Vector
multiplier, Matrix multiplicand);
public void
Print(string name);
public void
Print(string name, TextWriter tw);
public
static double QuadraticForm(Matrix
M, Vector v);
public
Vector Row(int rowIndex);
public
static Matrix Scale(Matrix
A, double value);
public
static Matrix Subtract(Matrix
subtrahend, Matrix minuend);
public
double SumOfAbsOfColumn(int column);
public
double SumOfAbsOfRow(int row);
public
static double Trace(Matrix
M);
public
static Matrix Transpose(Matrix
M);
public
static Matrix TransposeMultiply(Matrix
multiplierT, Matrix multiplicand);
public
static Vector UpperRightColumn(Matrix
M, int col);
public
static Matrix
operator +(Matrix aMatrix);
public
static Matrix
operator +(Matrix addend,
Matrix augend);
public
static Matrix
operator -(Matrix aMatrix);
public
static Matrix
operator -(Matrix minuend,
Matrix subtrahend);
public
static Matrix
operator *(double d,
Matrix A);
public
static Matrix
operator *(Matrix A,
double d);
public
static Matrix
operator *(Matrix A,
Matrix B);
public
static Vector
operator *(Matrix A,
Vector v);
public
static Vector
operator *(Vector v,
Matrix A);
public
static bool
operator ==(Matrix A,
Matrix B);
public
static bool
operator !=(Matrix A,
Matrix B);
}
top
Vector
[SerializableAttribute(..)]
[DefaultMemberAttribute(..)]
public class
Vector {
protected Vector();
public Vector(double[]
a);
public Vector(int
upperBound);
public Vector(Vector
source);
public bool
Is3D { get; }
public
double Length { get; }
public
double Max { get; }
public
double Min { get; }
public
double Norm1 { get; }
public
double Norm2 { get; }
public int
UpperBound { get; }
public
double this[int
index] { get; set;
}
public
static Vector Add(Vector
addend, Vector augend);
public
static Vector Apply(Vector
V, Function f);
public
Vector Clone();
public
static void Copy(Vector
from, Vector to);
public
static Matrix CrossProduct(Vector
aT, Vector b);
public
static double Dot(Vector
a, Vector b);
public
override bool Equals(object
o);
public void
Fill(double Value);
public void
Fill(double startValue,
double Increment);
public
override int GetHashCode();
public bool
IsVectorConformant(Vector that);
public int
MaxAt(ref double
max);
public int
MinAt(ref double
min);
public void
Print(string name);
public void
Print(string vectorName, TextWriter tw);
public void
Reverse();
public
static Vector SaXpY(double
a, Vector X, Vector
Y);
public
static Vector Scale(double
d, Vector aVector);
public
static Vector Subtract(Vector
minuend, Vector subtrahend);
public void
Swap(int index1, int
index2);
public
static Vector UnaryMinus(Vector
aVector);
public
static Vector Unit(Vector
a);
public
static void VerifyConformant(Vector
a, Vector b, string
msg);
public
static Vector
operator +(Vector aVector);
public
static Vector
operator +(Vector addend,
Vector augend);
public
static Vector
operator -(Vector aVector);
public
static Vector
operator -(Vector minuend,
Vector subtrahend);
public
static Vector
operator *(double d,
Vector a);
public
static Vector
operator *(Vector a,
double d);
public
static double
operator *(Vector a,
Vector b);
public
static bool
operator ==(Vector a,
Vector b);
public
static bool
operator !=(Vector a,
Vector b);
}
top
Vector3D
[SerializableAttribute(..)]
[DefaultMemberAttribute(..)]
public class
Vector3D: Vector {
public Vector3D();
public Vector3D(double
x, double y, double
z);
public Vector3D(double[]
a);
public
static Vector3D Cross(Vector3D
a, Vector3D b);
public
static Vector3D
operator %(Vector3D a,
Vector3D b);
}
top
Exceptions
public class
MustBeSquare: Exception, _Exception,
ISerializable {
public MustBeSquare(string
msg);
}
public class
VectorsNotConformant: Exception, _Exception,
ISerializable {
public VectorsNotConformant(string
msg);
}
public class
VectorUpperBoundError: Exception, _Exception,
ISerializable {
public VectorUpperBoundError(string
msg);
}
public class
ZeroDimension: Exception, _Exception,
ISerializable {
public ZeroDimension();
}
public class
ZeroLengthVector: Exception, _Exception,
ISerializable {
public ZeroLengthVector();
}
public class
ZeroOnDiagonal: Exception, _Exception,
ISerializable {
public ZeroOnDiagonal(int
row);
}
top
Useful Functions
Utility functions simplify code production, and
the Matrix and Vector classes use a few functions that are missing from .NET.
We provide these functions as a complement to Matrix.NET at no extra charge. The
additional code (100+ lines of managed C#) includes:
|
Function |
Purpose |
| |
|
| AreaOfPolygon |
area of a plane polygon |
| Cube |
x * x * x |
| DegreesToRadians |
return radians from an argument in
degrees |
| PiOn180 |
p
/ 180 |
| PrintIntArray |
Display array of ints on Console |
| PrintIntArray |
Display array of ints on a TextStream |
| Sqr |
x * x |
| Tolerance |
smallest double x such that 1 - x !=
1 |
top
Pricing US$99
Delivery via email
top
|