Right Matrix Division in C#

2019-06-07 06:51发布

问题:

How can I perform a Right Matrix Division in C#?. In MATLAB the code would be

AA(I) = ((X(I,:)-mu)/si)*(X(I,:)-mu)';
%where,
%I is index
%AA is a matrix of 1330x1 double
%X is a matrix of 1330x158 double
%mu is a matrix of 1x134 double
%si is a matrix of 134x134 double

For now I am using jagged arrays to perform all my computations. Is there a library I should use that can do efficient matrix computations?

Update with using MathNet LinearAlgebra

 /* MathNet Matrix tests */
            Matrix<double> AA = Matrix<double>.Build.Dense(1330, 1, 1.0);
            Matrix<double> XX = Matrix<double>.Build.Dense(1330, 158, 1.0);
            Matrix<double> si = Matrix<double>.Build.Dense(134, 134, 1.0);
            Matrix<double> mu = Matrix<double>.Build.Dense(1, 134, 1.0);

            AA.Row(0) = ((XX.Row(0) - mu.Row(0)) * si.Inverse()) * (XX.Row(0) - mu.Row(0)).Transpose();

update:

AA.SetRow(0, ((XX.Row(0) - mu.Row(0)) * si.Inverse()) * ((XX.Row(0) - mu.Row(0)).ToRowMatrix().Transpose()));

As suggested by @ander-biguri, the above is the implementation using MathNet Numerics library.

Question: I get an error stating that Transpose cannot be applied to vectors. How can I achieve AA(I) = ((X(I,:)-mu)/si)*(X(I,:)-mu)' statement, what am I doing wrong here?