---
title: "Building Block Matrices"
canonical: "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/Matrices/join.html"
source: "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/Matrices/join.md"
part: "Matrices and Linear Algebra"
chapter: "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": "Matrices", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/Matrices/index-matrices.md"}
prev: {"title": "Accessing or Modifying Entries", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/Matrices/entries.md"}
next: {"title": "Changing Ring", "source": "https://docs.magma-maths.org/v2.30-1/MatricesLinearAlgebra/Matrices/change-ring.md"}
intrinsics:
  - {"name": "BlockMatrix", "signature": "BlockMatrix(m, n, blocks): RngIntElt, RngIntElt, [ Mtrx ] -> Mtrx"}
  - {"name": "BlockMatrix", "signature": "BlockMatrix(m, n, rows): RngIntElt, RngIntElt, [ [ Mtrx ] ] -> Mtrx"}
  - {"name": "BlockMatrix", "signature": "BlockMatrix(rows): [ [ Mtrx ] ] -> Mtrx"}
  - {"name": "HorizontalJoin", "signature": "HorizontalJoin(X, Y): Mtrx, Mtrx -> Mtrx"}
  - {"name": "HorizontalJoin", "signature": "HorizontalJoin(Q): [ Mtrx ] -> Mtrx"}
  - {"name": "HorizontalJoin", "signature": "HorizontalJoin(T): < Mtrx > -> Mtrx"}
  - {"name": "VerticalJoin", "signature": "VerticalJoin(X, Y): Mtrx, Mtrx -> Mtrx"}
  - {"name": "VerticalJoin", "signature": "VerticalJoin(Q): [ Mtrx ] -> Mtrx"}
  - {"name": "VerticalJoin", "signature": "VerticalJoin(T): < Mtrx > -> Mtrx"}
  - {"name": "DiagonalJoin", "signature": "DiagonalJoin(X, Y): Mtrx, Mtrx -> Mtrx"}
  - {"name": "DiagonalJoin", "signature": "DiagonalJoin(Q): [ Mtrx ] -> Mtrx"}
  - {"name": "DiagonalJoin", "signature": "DiagonalJoin(T): < Mtrx > -> Mtrx"}
  - {"name": "KroneckerProduct", "signature": "KroneckerProduct(A, B): Mtrx, Mtrx -> Mtrx"}
---

# Building Block Matrices

Block matrices can be constructed either by listing the blocks, or by joining together smaller matrices horizontally, vertically, or diagonally.

<a id="function-blockmatrix-rngintelt-rngintelt-mtrx"></a>
## `BlockMatrix(m, n, blocks): RngIntElt, RngIntElt, [ Mtrx ] -> Mtrx`

The matrix constructed from the given block matrices, which should all have the same dimensions, and should be given as a sequence of $m\cdot n$ block matrices (given in row major order, in other words listed across rows).

<a id="function-blockmatrix-rngintelt-rngintelt-mtrx-2"></a>
## `BlockMatrix(m, n, rows): RngIntElt, RngIntElt, [ [ Mtrx ] ] -> Mtrx`

<a id="function-blockmatrix-mtrx"></a>
## `BlockMatrix(rows): [ [ Mtrx ] ] -> Mtrx`

The matrix constructed from the given block matrices, which should all have the same dimensions, and should be given as a sequence of $m$ rows, each containing $n$ block matrices.

<a id="function-horizontaljoin-mtrx-mtrx"></a>
## `HorizontalJoin(X, Y): Mtrx, Mtrx -> Mtrx`

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

<a id="function-horizontaljoin-mtrx"></a>
## `HorizontalJoin(Q): [ Mtrx ] -> Mtrx`

<a id="function-horizontaljoin-mtrx-2"></a>
## `HorizontalJoin(T): < Mtrx > -> Mtrx`

Given a sequence $Q$ or tuple $T$ of matrices, each having the same number of rows and being over the same coefficient ring $R$, return the matrix over $R$ obtained by joining the elements of $Q$ or $T$ horizontally in order.

<a id="function-verticaljoin-mtrx-mtrx"></a>
## `VerticalJoin(X, Y): Mtrx, Mtrx -> Mtrx`

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

<a id="function-verticaljoin-mtrx"></a>
## `VerticalJoin(Q): [ Mtrx ] -> Mtrx`

<a id="function-verticaljoin-mtrx-2"></a>
## `VerticalJoin(T): < Mtrx > -> Mtrx`

Given a sequence $Q$ or tuple $T$ of matrices, each having the same number of columns and being over the same coefficient ring $R$, return the matrix over $R$ obtained by joining the elements of $Q$ or $T$ vertically in order.

<a id="function-diagonaljoin-mtrx-mtrx"></a>
## `DiagonalJoin(X, Y): Mtrx, Mtrx -> Mtrx`

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

<a id="function-diagonaljoin-mtrx"></a>
## `DiagonalJoin(Q): [ Mtrx ] -> Mtrx`

<a id="function-diagonaljoin-mtrx-2"></a>
## `DiagonalJoin(T): < Mtrx > -> Mtrx`

Given a sequence $Q$ or tuple $T$ of matrices, each being over the same coefficient ring $R$, return the matrix over $R$ obtained by joining the elements of $Q$ or $T$ diagonally in order.

<a id="function-kroneckerproduct-mtrx-mtrx"></a>
## `KroneckerProduct(A, B): Mtrx, Mtrx -> Mtrx`

Given an $m \times n$ matrix $A$ and a $p \times q$ matrix $B$, both over a ring $R$, return the Kronecker product of $A$ and $B$, which is the $mp\times nq$ matrix $C$ over $R$ such that the $((i-1)p+r, (j-1)q+s)$-th entry of $C$ is the $(i,j)$-th entry of $A$ times the $(r,s)$-th entry of $B$, for $1\leq i\le m$, $1\leq j\leq n$, $1\leq r\leq p$, and $1\leq s\leq q$.
