Skip to main content
Email Password   helpLost your password?

Download csml_complex.zip - 167.3 KB

Download doc.zip - 210.8 KB (Documentation)

Version Info

Version 0.9 - Last Update: July 4, 2007

Introduction

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.

Remark

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.

What it can do

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.

What it cannot do

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.

How to use CSML

Two general possibilities for using the code:

  1. Include CSML.dll as reference to your project and type "using CSML;" on top of your source file
  2. Include classes Matrix.cs and Complex.cs to your project and adjust namespaces

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.

Points of Interest

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.

A Word About Eigenvalues

The Eigenvalues() method in its current state uses basic QR iteration based upon Gram-Schmidtian orthogonalization. This implies two things:

  1. for now, computation of eigenvalues is possible only for real matrices
  2. if a matrix has multiple eigenvalues or complex eigenvalues, the method works, but junk may be returned

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.

History

Coming soon

Update July 4, 2007

Update July 3, 2007 #2

Update July 3, 2007

Update July 2, 2007

Update June 29, 2007

Update June 10, 2007

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralLatest developments Pin
cornelius1729
8:04 29 Oct '09  
GeneralBug in Matrix Inverse Pin
Rajnikant Sharma BYU
6:35 17 May '09  
GeneralRe: Bug in Matrix Inverse Pin
safee ullah
18:32 2 Sep '09  
GeneralRe: Bug in Matrix Inverse Pin
emre unsal
4:11 17 Nov '09  
General3 warrnings detected Pin
chen dingjun
13:15 17 Dec '08  
GeneralHorizontalConcat seems to have a bug Pin
Matthias Zeintlinger
6:50 3 Dec '08  
GeneralRe: HorizontalConcat seems to have a bug Pin
Håkan MacLean
6:56 5 Apr '09  
Generalbug in Inverse()-Method Pin
arthur_dent42
7:35 8 Apr '08  
GeneralInverse Matrix of Array Pin
get
2:45 13 Dec '07  
Questionstrange operator consequences? Pin
Raven123
6:00 27 Nov '07  
AnswerRe: strange operator consequences? Pin
hanzzoid
0:05 29 Nov '07  
GeneralGreat Pin
zhengdong jin
5:18 23 Nov '07  
GeneralRe: Great Pin
Rajnikant Sharma BYU
15:56 28 Dec '08  
GeneralHorizontalConcat() and VerticalConcat() do not work Pin
alexei_c
14:51 21 Oct '07  
GeneralRe: HorizontalConcat() and VerticalConcat() do not work Pin
hanzzoid
0:24 29 Nov '07  
QuestionInverse of m x n matrix? Pin
joselvra
13:56 29 Sep '07  
AnswerRe: Inverse of m x n matrix? Pin
mvasiliev
22:42 18 Oct '07  
AnswerRe: Inverse of m x n matrix? Pin
hanzzoid
0:09 29 Nov '07  
Generalexception thrown Pin
slady.net
18:05 28 Aug '07  
Generaloperations Pin
matiasjaure
4:55 28 Aug '07  
Generalconversion from int to complex Pin
Drullie19
5:53 20 Aug '07  
GeneralRe: conversion from int to complex Pin
cornelius1729
7:14 29 Oct '09  
GeneralXML comments missing Pin
doolyo
23:12 9 Jul '07  
GeneralRe: XML comments missing Pin
hanzzoid
7:53 14 Jul '07  
GeneralRe: XML comments missing Pin
doolyo
14:49 14 Jul '07  


Last Updated 28 Nov 2007 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009