{"name":"matrixMultiply","operator":null,"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","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"1.92"}],"since":{"game":"arma3","name":"Arma 3","version":"1.92"},"arma3_since":"1.92","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"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","since":null,"effect":null,"exec":null,"params":[{"name":"matrix1","type":"Array of Array of Numbers","optional":false,"default":null,"description":"matrix of the size `n`*(rows)* × `k`*(columns)*","types":["Array","Number"],"since":null,"text":"matrix1: Array of Array of Numbers - matrix of the size `n`*(rows)* × `k`*(columns)*"},{"name":"matrix2","type":"Array of Array of Numbers","optional":false,"default":null,"description":"matrix of the size `k`*(rows)* × `m`*(columns)*","types":["Array","Number"],"since":null,"text":"matrix2: Array of Array of Numbers - matrix of the size `k`*(rows)* × `m`*(columns)*"}],"returns":{"type":"Array of Array of Numbers","types":["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","operator":null,"left":{"text":"matrix1","types":["Array","Number"]},"right":{"text":"matrix2","types":["Array","Number"]}}],"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] */"]}],"multiplayer":null,"problems":null,"aliases":[],"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```"}],"categories":["Arma 3: New Scripting Commands","Arma 3: Scripting Commands","Command Group: Math","Command Group: Math - Vectors","Introduced with Arma 3 version 1.92","Scripting Commands"]}