Ram Sam
Ram Sam

Reputation: 21

Matrix concatenation using MathNet.Numerics.LinearAlgebra in .NET Framework

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.

Upvotes: 2

Views: 1236

Answers (2)

Joseph
Joseph

Reputation: 400

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}})

Upvotes: 4

Stefan
Stefan

Reputation: 1237

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);

Upvotes: 0

Related Questions