views:

613

answers:

3
+2  Q: 

.Net Matrix

Is there a standard .Net matrix class? I cannot find it if there is.

If not, why not? It sounds like something people would need very frequently. Are there any non-standard libs you could recommend?

+1  A: 

The XNA Framework has a Matrix structure. I'm not aware of any part of the main framework that has a Matrix class though.

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.matrix.aspx

Dan Herbert
+2  A: 

I don't believe there is, partially because any array can technically be called a "Matrix" if it is a single dimension array of length n, it is an n x 1 matrix. There is also the question of whether you'd want the matrix to hold integers, doubles, or other numerical values that may play a role in some Matrix functions.

There do exist various places like here and here that may bundle some Matrix classes with other Linear Algebra functions.

JB King
A: 

You can find a Matrix class in the Lydos.MatLab library (documentation), which is distributed as open source project under the zlib/libpng license.

Example usage in C#:

using Lydos.Matlab;
using System;

public class Example
{
    static void Main()
    {
        Engine e = new Engine();
        Matrix m = new Matrix(2, 2), n;

        m[0, 0] = 0;
        m[0, 1] = 1;
        m[1, 0] = 2;
        m[1, 1] = 3;

        e.SetMatrix("m", m);
        e.Evaluate("m = m + 1");
        n = e.GetMatrix("m");

        Console.WriteLine(m); // [0 1; 2 3]
        Console.WriteLine(n); // [1 2; 3 4]

        m.Dispose();
        n.Dispose();
        e.Close();
    }
}
splattne