matrixMultiply: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - " \| *(game[0-9]|version[0-9]|gr[0-9]|serverExec|mp|pr|descr|s[0-9]|p[0-9]{1,3}|r[0-9]|x1?[0-9]|seealso) *= +" to " |$1= ") |
BrettMayson (talk | contribs) mNo edit summary |
||
(20 intermediate revisions by 2 users not shown) | |||
Line 7: | Line 7: | ||
|gr2= Math - Vectors | |gr2= Math - Vectors | ||
|descr= Returns resulting matrix from the {{ | |descr= [[File:matrixMultiply.jpg|right|600px]] | ||
Returns resulting matrix from the {{Link|https://en.wikipedia.org/wiki/Matrix_multiplication|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 {{hl|columns}} matrix1 == {{hl|rows}} matrix2. The resulting matrix will be of the size n × m. If the shapes do not match, empty array [] will be returned. | |||
|s1= matrix1 [[matrixMultiply]] matrix2 | |s1= matrix1 [[matrixMultiply]] matrix2 | ||
|p1=matrix1: [[Array]] - matrix of the size | |p1= matrix1: [[Array]] of [[Array]] of [[Number]]s - matrix of the size {{hl|n}}''(rows)'' × {{hl|k}}''(columns)'' | ||
|p2=matrix2: [[Array]] - matrix of the size | |p2= matrix2: [[Array]] of [[Array]] of [[Number]]s - matrix of the size {{hl|k}}''(rows)'' × {{hl|m}}''(columns)'' | ||
|r1= [[Array]] - resulting matrix of the size | |r1= [[Array]] of [[Array]] of [[Number]]s - resulting matrix of the size {{hl|n}}''(rows)'' × {{hl|m}}''(columns)'' | ||
|x1= < | |x1= <sqf> | ||
[ | |||
[2], | [2], | ||
[2] | [2] | ||
] | ] | ||
matrixMultiply | |||
[ | [ | ||
[3] | [3] | ||
] | ] | ||
Line 30: | Line 31: | ||
[6], | [6], | ||
[6] | [6] | ||
] */</ | ] */ | ||
|x2= < | </sqf> | ||
|x2= <sqf> | |||
[ | |||
[-1,0,0], | [-1,0,0], | ||
[0,-1,0] | [0,-1,0] | ||
] | ] | ||
matrixMultiply | |||
[ | [ | ||
[1,2], | [1,2], | ||
Line 45: | Line 49: | ||
[-1,-2], | [-1,-2], | ||
[-3,-1] | [-3,-1] | ||
] */</ | ] */ | ||
</sqf> | |||
|seealso= [[matrixTranspose]] | |seealso= [[matrixTranspose]] [[vectorAdd]] [[vectorMagnitude]] [[vectorNormalized]] [[vectorMultiply]] [[vectorDotProduct]] [[vectorCrossProduct]] [[vectorDistance]] [[vectorLinearConversion]] [[vectorCos]] [[vectorFromTo]] [[vectorModelToWorld]] [[vectorWorldToModel]] [[BIS_fnc_transformVectorDirAndUp]] | ||
}} | }} | ||
{{Note | |||
|user= oOKexOo | |||
|timestamp= 20190630035300 | |||
|text= 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 | |||
Note that this command won't transform a 1D array | [[-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]] | ||
[[-1,0,0],[0,-1,0],[0,0,-1]] [ | </sqf> | ||
[[-1,0,0],[0,-1,0],[0,0,-1]] | }} | ||
</ | |||
Latest revision as of 14:13, 15 June 2024
Description
- Description:
- Returns resulting matrix from the 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.
- Groups:
- MathMath - Vectors
Syntax
- Syntax:
- matrix1 matrixMultiply matrix2
- Parameters:
- matrix1: Array of Array of Numbers - matrix of the size n(rows) × k(columns)
- matrix2: Array of Array of Numbers - matrix of the size k(rows) × m(columns)
- Return Value:
- Array of Array of Numbers - resulting matrix of the size n(rows) × m(columns)
Examples
- Example 1:
- [ [2], [2] ] matrixMultiply [ [3] ] /* returns [ [6], [6] ] */
- Example 2:
- [ [-1,0,0], [0,-1,0] ] matrixMultiply [ [1,2], [3,1], [2,3] ] /* returns [ [-1,-2], [-3,-1] ] */
Additional Information
- See also:
- matrixTranspose vectorAdd vectorMagnitude vectorNormalized vectorMultiply vectorDotProduct vectorCrossProduct vectorDistance vectorLinearConversion vectorCos vectorFromTo vectorModelToWorld vectorWorldToModel BIS_fnc_transformVectorDirAndUp
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
- Posted on Jun 30, 2019 - 03:53 (UTC)
-
Note that this command won't automatically transform a 1D array into a column vector
[[-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]]