---
name: "matrixMultiply"
type: command
status: ok
groups: ["Math", "Math - Vectors"]
arma3_since: "1.92"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/matrixMultiply
revid: 364807
updated: 2024-06-15T13:13:13Z
---

# matrixMultiply

*Command · Math, Math - Vectors · Arma 3 v1.92*

## Description

Returns resulting matrix from the [multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication) of two matrices. First matrix must be of the size n × **k**, while the second must be of the size **k** × m, i.e `columns` matrix1 == `rows` matrix2. The resulting matrix will be of the size n × m. If the shapes do not match, empty array [] will be returned.

## Syntax

```sqf
matrix1 matrixMultiply matrix2
```

**Parameters:**

- `matrix1`: [Array](../topics/Array.md) of [Array](../topics/Array.md) of [Number](../topics/Number.md)s - matrix of the size `n`*(rows)* × `k`*(columns)*
- `matrix2`: [Array](../topics/Array.md) of [Array](../topics/Array.md) of [Number](../topics/Number.md)s - matrix of the size `k`*(rows)* × `m`*(columns)*

**Returns:** [Array](../topics/Array.md) of [Array](../topics/Array.md) of [Number](../topics/Number.md)s - resulting matrix of the size `n`*(rows)* × `m`*(columns)*

## Examples

### Example 1

```sqf
[
    [2],
    [2]
] 
matrixMultiply 
[
    [3] 
]
/* returns 
[
    [6],
    [6]
] */
```

### Example 2

```sqf
[
    [-1,0,0],
    [0,-1,0]
] 
matrixMultiply 
[
    [1,2],
    [3,1],
    [2,3]
] 
/* returns 
[
    [-1,-2],
    [-3,-1]
] */
```

## See also

[matrixTranspose](../commands/matrixTranspose.md) · [vectorAdd](../commands/vectorAdd.md) · [vectorMagnitude](../commands/vectorMagnitude.md) · [vectorNormalized](../commands/vectorNormalized.md) · [vectorMultiply](../commands/vectorMultiply.md) · [vectorDotProduct](../commands/vectorDotProduct.md) · [vectorCrossProduct](../commands/vectorCrossProduct.md) · [vectorDistance](../commands/vectorDistance.md) · [vectorLinearConversion](../commands/vectorLinearConversion.md) · [vectorCos](../commands/vectorCos.md) · [vectorFromTo](../commands/vectorFromTo.md) · [vectorModelToWorld](../commands/vectorModelToWorld.md) · [vectorWorldToModel](../commands/vectorWorldToModel.md) · [BIS_fnc_transformVectorDirAndUp](../functions/BIS_fnc_transformVectorDirAndUp.md)

## Community notes

**oOKexOo** — 2019-06-30

Note that this command won't automatically transform a 1D array into a column vector

```sqf
[[-1,0,0],[0,-1,0],[0,0,-1]] matrixMultiply [1,2,3] // wrong, syntax error
[[-1,0,0],[0,-1,0],[0,0,-1]] matrixMultiply [[1,2,3]] // wrong, will return []
[[-1,0,0],[0,-1,0],[0,0,-1]] matrixMultiply [[1], [2], [3]] // correct, will return [[-1], [-2], [-3]]
```

<sub>Source: [BI Community Wiki — matrixMultiply](https://community.bistudio.com/wiki/matrixMultiply) (revision 364807).</sub>
