{"name":"matrixMultiply","title":"matrixMultiply","type":"command","url":"https://community.bistudio.com/wiki/matrixMultiply","revid":364807,"updated":"2024-06-15T13:13:13Z","groups":["Math","Math - Vectors"],"status":"ok","games":{"arma3":"1.92"},"since":"arma3 1.92","arma3_since":"1.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.","syntaxes":[{"syntax":"matrix1 matrixMultiply matrix2","params":[{"name":"matrix1","type":"Array of Array of Numbers","description":"matrix of the size `n`*(rows)* × `k`*(columns)*","type_expr":"Array<Array<Number>>"},{"name":"matrix2","type":"Array of Array of Numbers","description":"matrix of the size `k`*(rows)* × `m`*(columns)*","type_expr":"Array<Array<Number>>"}],"returns":{"type":"Array of Array of Numbers","type_expr":"Array<Array<Number>>","description":"resulting matrix of the size `n`(rows) × `m`(columns)","text":"Array of Array of Numbers - resulting matrix of the size `n`*(rows)* × `m`*(columns)*"},"form":"binary","left":{"text":"matrix1"},"right":{"text":"matrix2"}}],"examples":[{"text":"```sqf\n[\n    [2],\n    [2]\n]\nmatrixMultiply\n[\n    [3]\n]\n/* returns\n[\n    [6],\n    [6]\n] */\n```","code":["[\n\t[2],\n\t[2]\n] \nmatrixMultiply \n[\n\t[3] \n]\n/* returns \n[\n\t[6],\n\t[6]\n] */"]},{"text":"```sqf\n[\n    [-1,0,0],\n    [0,-1,0]\n]\nmatrixMultiply\n[\n    [1,2],\n    [3,1],\n    [2,3]\n]\n/* returns\n[\n    [-1,-2],\n    [-3,-1]\n] */\n```","code":["[\n\t[-1,0,0],\n\t[0,-1,0]\n] \nmatrixMultiply \n[\n\t[1,2],\n\t[3,1],\n\t[2,3]\n] \n/* returns \n[\n\t[-1,-2],\n\t[-3,-1]\n] */"]}],"see_also":["matrixTranspose","vectorAdd","vectorMagnitude","vectorNormalized","vectorMultiply","vectorDotProduct","vectorCrossProduct","vectorDistance","vectorLinearConversion","vectorCos","vectorFromTo","vectorModelToWorld","vectorWorldToModel","BIS_fnc_transformVectorDirAndUp"],"notes":[{"user":"oOKexOo","date":"2019-06-30T03:53:00Z","text":"Note that this command won't automatically transform a 1D array into a column vector\n\n```sqf\n[[-1,0,0],[0,-1,0],[0,0,-1]] matrixMultiply [1,2,3] // wrong, syntax error\n[[-1,0,0],[0,-1,0],[0,0,-1]] matrixMultiply [[1,2,3]] // wrong, will return []\n[[-1,0,0],[0,-1,0],[0,0,-1]] matrixMultiply [[1], [2], [3]] // correct, will return [[-1], [-2], [-3]]\n```"}]}