{
  "id": "matrix-multiplication",
  "version": "b3320fec28d7",
  "status": "published",
  "name": "Matrix Multiplication Calculator",
  "question": "What is the matrix multiplication?",
  "summary": "Multiplies an m × n matrix A by an n × p matrix B in exact decimal arithmetic: each entry of A × B is a row of A times a column of B, with the working.",
  "category": "math",
  "subcategory": "linear-algebra",
  "url": "https://www.acalculator.org/math/matrix-multiplication-calculator",
  "markdown": "https://www.acalculator.org/math/matrix-multiplication-calculator.md",
  "kind": "function",
  "method": "The entry in row i, column j of A × B is row i of A times column j of B: cᵢⱼ = Σₖ aᵢₖbₖⱼ.",
  "assumptions": [
    "A has m rows and n columns, and B has n rows and p columns, so A × B has m rows and p columns (1 to 6 each). Otherwise there is no product.",
    "Every entry is read exactly as typed, so the product is exact: 0.1 × 0.2 is 0.02.",
    "The order matters: A × B and B × A are usually different."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "a": {
        "title": "Matrix A",
        "description": "The first matrix, 1 to 6 rows and columns.",
        "type": "array",
        "items": {
          "type": "array",
          "items": {
            "type": "number"
          }
        }
      },
      "b": {
        "title": "Matrix B",
        "description": "The second matrix. It needs as many rows as A has columns.",
        "type": "array",
        "items": {
          "type": "array",
          "items": {
            "type": "number"
          }
        }
      }
    }
  },
  "outputs": {
    "product": {
      "label": "A × B",
      "description": "The product matrix, exact, rows separated by semicolons.",
      "format": "text"
    },
    "size": {
      "label": "Size of A × B",
      "description": "Rows × columns of the product: rows of A by columns of B.",
      "format": "text"
    },
    "steps": {
      "label": "Working",
      "description": "Each entry as a row of A times a column of B, for the first 16 entries.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "a": "1,2,3;4,5,6",
      "b": "7,8;9,10;11,12"
    },
    "outputs": {
      "product": "[58, 64; 139, 154]",
      "size": "2 × 2",
      "steps": "c11 = 1×7 + 2×9 + 3×11 = 58; c12 = 1×8 + 2×10 + 3×12 = 64; c21 = 4×7 + 5×9 + 6×11 = 139; c22 = 4×8 + 5×10 + 6×12 = 154"
    },
    "text": "A × B = [58, 64; 139, 154]."
  },
  "examples": [
    {
      "given": {
        "a": [
          [
            1,
            2,
            3
          ],
          [
            4,
            5,
            6
          ]
        ],
        "b": [
          [
            7,
            8
          ],
          [
            9,
            10
          ],
          [
            11,
            12
          ]
        ]
      },
      "expect": {
        "product": "[58, 64; 139, 154]",
        "size": "2 × 2"
      },
      "source": "hand calculation in content.mdx: 1×7 + 2×9 + 3×11 = 58, …, 4×8 + 5×10 + 6×12 = 154"
    },
    {
      "given": {
        "a": [
          [
            1,
            2
          ],
          [
            3,
            4
          ]
        ],
        "b": [
          [
            5,
            6
          ],
          [
            7,
            8
          ]
        ]
      },
      "expect": {
        "product": "[19, 22; 43, 50]",
        "steps": "c11 = 1×5 + 2×7 = 19; c12 = 1×6 + 2×8 = 22; c21 = 3×5 + 4×7 = 43; c22 = 3×6 + 4×8 = 50"
      },
      "source": "hand calculation in content.mdx: the row-times-column rule, DLMF equation 1.2.34"
    },
    {
      "given": {
        "a": [
          [
            5,
            6
          ],
          [
            7,
            8
          ]
        ],
        "b": [
          [
            1,
            2
          ],
          [
            3,
            4
          ]
        ]
      },
      "expect": {
        "product": "[23, 34; 31, 46]"
      },
      "source": "hand calculation in content.mdx: B × A differs from A × B (5×1 + 6×3 = 23)"
    },
    {
      "given": {
        "a": [
          [
            1,
            2,
            3
          ]
        ],
        "b": [
          [
            4
          ],
          [
            5
          ],
          [
            6
          ]
        ]
      },
      "expect": {
        "product": "[32]",
        "size": "1 × 1"
      },
      "source": "hand calculation in content.mdx: a row times a column is the dot product, 1×4 + 2×5 + 3×6 = 32"
    },
    {
      "given": {
        "a": [
          [
            0.1,
            0.2
          ],
          [
            0.3,
            0.4
          ]
        ],
        "b": [
          [
            0.5,
            0
          ],
          [
            0,
            0.5
          ]
        ]
      },
      "expect": {
        "product": "[0.05, 0.1; 0.15, 0.2]"
      },
      "source": "hand calculation in content.mdx: B is 0.5 × I, so A × B halves every entry of A; decimals are exact"
    }
  ],
  "sources": [
    "NIST Digital Library of Mathematical Functions, §1.2(v) Matrices, Vectors, Scalar Products, and Norms, equation 1.2.34 (the row times column rule; an m × n matrix times an m′ × n′ matrix is defined only when n = m′; multiplication is not necessarily commutative). https://dlmf.nist.gov/1.2"
  ],
  "related": [
    "inverse-matrix",
    "slope-intercept"
  ],
  "changelog": [
    {
      "date": "2026-09-28",
      "note": "B has its own size, so a link whose sizes differ shows an error instead of a trimmed B."
    }
  ]
}
