---
title: "Building Block Matrices"
canonical: "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/join.html"
source: "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/join.md"
part: "Matrices and Linear Algebra"
chapter: "Sparse Matrices"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Matrices and Linear Algebra", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/index-matrices-linear-algebra.md"}
  - {"title": "Sparse Matrices", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/index-sparse-matrices.md"}
prev: {"title": "Accessing or Modifying Entries", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/entries.md"}
next: {"title": "Conversion to and from Dense Matrices", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/SparseMatrices/conversion.md"}
intrinsics:
  - {"name": "HorizontalJoin", "signature": "HorizontalJoin(A, B): MtrxSprs, MtrxSprs -> MtrxSprs"}
  - {"name": "VerticalJoin", "signature": "VerticalJoin(A, B): MtrxSprs, MtrxSprs -> MtrxSprs"}
  - {"name": "DiagonalJoin", "signature": "DiagonalJoin(A, B): MtrxSprs, MtrxSprs -> MtrxSprs"}
---

# Building Block Matrices

<a id="function-horizontaljoin-mtrxsprs-mtrxsprs"></a>
## `HorizontalJoin(A, B): MtrxSprs, MtrxSprs -> MtrxSprs`

Given a sparse matrix $A$ with $r$ rows and $c$ columns, and a sparse matrix $B$ with $r$ rows and $d$ columns, both over the same coefficient ring $R$, return the sparse matrix over $R$ with $r$ rows and $(c+d)$ columns obtained by joining $A$ and $B$ horizontally (placing $B$ to the right of $A$).

<a id="function-verticaljoin-mtrxsprs-mtrxsprs"></a>
## `VerticalJoin(A, B): MtrxSprs, MtrxSprs -> MtrxSprs`

Given a sparse matrix $A$ with $r$ rows and $c$ columns, and a sparse matrix $B$ with $s$ rows and $c$ columns, both over the same coefficient ring $R$, return the sparse matrix with $(r+s)$ rows and $c$ columns over $R$ obtained by joining $A$ and $B$ vertically (placing $B$ underneath $A$).

<a id="function-diagonaljoin-mtrxsprs-mtrxsprs"></a>
## `DiagonalJoin(A, B): MtrxSprs, MtrxSprs -> MtrxSprs`

Given matrices $A$ with $a$ rows and $b$ columns and $B$ with $c$ rows and $d$ columns, both over the same coefficient ring $R$, return the sparse matrix with $(a+c)$ rows and $(b+d)$ columns over $R$ obtained by joining $A$ and $B$ diagonally (placing $B$ diagonally to the right of and underneath $A$, with zero blocks above and below the diagonal).
