2

I would like to perform row-wise and column-wise matrix concatenation using .NET Framework with MathNet library. For example, if I have 3 matrices A, B, C of dimension nxn, I would like create a new matrix D of dimension 2nx2n where

// I have used MATLAB syntax here to explain the operation
// D = [A B; B C];

I have currently defined the matrices A, B, C as DenseMatrix class and would like to proceed from here.

Stefan
  • 919
  • 2
  • 13
  • 24
Ram Sam
  • 21
  • 1

2 Answers2

4

That's one way to do it in VB.Net:

Dim D =
    MathNet.Numerics.LinearAlgebra.Double.Matrix.Build.DenseOfMatrixArray(
        New MathNet.Numerics.LinearAlgebra.Matrix(Of Double)(,)
             {{A, B}, {B, C}})
Stefan
  • 919
  • 2
  • 13
  • 24
Joseph
  • 380
  • 3
  • 16
0

In C# you could do:

// To shorten build notation.
var M = Matrix<double>.Build;

// Define these matrices how you want it.
Matrix<double> A = ...;
Matrix<double> B = ...;
Matrix<double> C = ...;

// Define a 2D array of matrices.
Matrix<double>[,] MatrixArray2D =
{  
    { A, B },
    { B, C }
};

// Use the 2D array to construct the concatenated matrix.
Matrix<double> ConcatinatedMatrix = M.DenseOfMatrixArray(MatrixArray2D);
Stefan
  • 919
  • 2
  • 13
  • 24