![]() |
Languages »
C# »
General
Intermediate
C# Matrix LibraryBy hanzzoidA C# library for basic numerical linear algebra. |
C# 2.0, Windows, .NET 2.0VS2005, Dev, QA
|
||||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
Download doc.zip - 210.8 KB (Documentation)
Version 0.9 - Last Update: July 4, 2007
CSML - C# Matrix Library - is a compact and lightweight package for numerical linear algebra. Many matrix operations known from Matlab, Scilab and Co. are implemented.
Make sure to return to this article once in a while for updates. A project of this size a is big thing for one man to handle. Scilab (free Matlab clone), for instance, has been created by an academic consortium, and Matlab's creator, Mathworks, is a well-fed enterprise.
Bugfixes will always come as updates, and if you have a look at the history below, you will see there have been quit a number of, ehm, improvements in a short period of time.
The core of the library, the Matrix class, includes over 90 methods for matrix operations such as multiplication, summation, exponentiation and solving linear equation systems; matrix manipulations such as concatenation, insertion, transpose, inverse, flipping, symmetrizing, insertion and extraction; for matrix computations such as determinant, trace, permanent, norm (Frobenius, Euclidian, maximum norm, taxi norm, p-norm), condition number; for matrix decompositions such as LU factorization, Gram-Schmidtian orthogonalization and Cholesky factorization.
Now, the entire library has been updated to work with complex arithmetics. A real matrix M is to be considered a special complex matrix, where M.Re() == M, e.i. imaginary part of each entry equals 0.
The project is nearly entirely pdf-documented; most methods are also illustrated with examples. Difficult algorithms like the computation of the inverse are explained on a mathematical level as well. If vitally necessary, complexity classes of certain algrithms are noted.
At this time, there is no implementation of
(*) - Working on it. Any contribution is welcome. A complex numbers library has been issued by me here on CodeProject, look for CompLib. A library for polynomials is has been released as well, PolyLib.
Two general possibilities for using the code:
Let us see an example. Say, we want to compute the determinant and the inverse of the 2 by 2 matrix [1, 1; 1, 2]:
Matrix M = new Matrix("1,1;1,2"); // init Complex det = M.Determinant(); // det = 1 Matrix Minv = M.Inverse(); // Minv = [2, -1; -1, 1]
For details of implementation and usage, refer to the documentation.
This project is issued without license and warranty, it should be considered a gift to the developer's community in general and to this page in particular - most of my programming knowledge is based on free code, on examples and tutorials submitted without the greed for money. I am now in the happy position not having to turn anything into bucks: This is the result.
The Eigenvalues() method in its current state uses basic QR iteration based upon Gram-Schmidtian orthogonalization. This implies two things:
In fact, I had thoroughly satifying results only for triangular matrices and symmetric positive definite matrices.
These problems mirror the difficulties buried under the eigenvalue problem. Since the eigenvalues of a matrix A are defined as the roots of the characteristic polynomial
p(L) = det(A-L*id),
computation is mathematically equivalent to the computation of a determinant and the n roots of p. (Well, this would work for all matrices with any distribution of eigenvalues, but it is numerically the worst idea, since Weierstrass iteration (compare the Roots() method in PolyLib) is badly conditioned for polynomials with roots not being well-separated.)
Therefore; I am working on canonical double-shift QR iteration based upon Givens rotations. That is the way Matlab's function eig is working.
That I am forced to talk at length about eigenvalues, although there are so many other difficult computations implemented, reveals to me that this problem is one of the deepest and most bothersome in basic numerical linear algebra.
conjugate gradient method (SolveCG() is implemented but buggy); I'm going to issue an example project showing usage and basic functionality of CSML one of these days
(1) minor bug within the matrix access routine fixed, making two try-catch blocks obsolete and increasing speed enormously; (2) defined matrix exponentiation with negative exponent k as exponentiation of the inverse with (-k); (3) major bug within the Insert() method fixed; (4) old matrix class (without complex number support) deleted
Finally complex numbers and complex matrices; any matrix consists of complex entries now.
New in this version:
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 28 Nov 2007 Editor: |
Copyright 2007 by hanzzoid Everything else Copyright © CodeProject, 1999-2009 Web21 | Advertise on the Code Project |