Filling and manipulating matrices using MathNet.Numerics

8.9k views Asked by At

I'm working on a code where I need to represent a small number of matrices (around 10) and do some operations with them (like get the inverse, transposed, etc). One of my co-workers recommended using the Math.Net Iridium library. The referred page said the project was Discontinued and merged with MathNeh.Numerics, found here.

I manage to install the package successfully. But now, I'm struggling to use the operations properly.

To sum up, what I am asking is: how to put data into matrices and manipulate them using MathNet.Numerics? For instance, how can I add values to a specific row x column y in a given matrix m1. Does it allow us to access a specific index?

One more thing to note, the matrices will always have the same number of columns and rows, but this number is known in run-time only.

I've tried to google for tutorials, found this one, but I didn't get what I needed to know. Any help is appreciated.

-- PS: the method I was using so far was creating Nested Lists to represent each matrix, and using for loops to populate it. I believe I would have a hard time when the time to transpose/invert/multiply would come.

1

There are 1 answers

0
lucas.mdo On

The answer is in the documentation linked in the question itself. http://numerics.mathdotnet.com/Matrix.html#Manipulating-Matrices-and-Vectors

The given example is:

var m = Matrix<double>.Build.Dense(3,4,(i,j) => 10*i + j);
m[0,0]; // 0   (row 0, column 0)
m[2,0]; // 20 (row 2, column 0)
m[0,2]; // 2   (row 0, column 2)
m[0,2] = -1.0;
m[0,2]; // -1