matrixMultiply: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(48 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Command|Comments=
{{RV|type=command
____________________________________________________________________________________________


| arma3 |Game=
|game1= arma3
|version1= 1.92


|1.92|Game Version =
|gr1= Math
|gr2= Math - Vectors


|arg= |Multiplayer Arguments =
|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.


|eff=  |Multiplayer Effects =
|s1= matrix1 [[matrixMultiply]] matrix2


|serverExec= |Multiplayer Execution ("server" or empty)=
|p1= matrix1: [[Array]] of [[Array]] of [[Number]]s - matrix of the size {{hl|n}}''(rows)'' × {{hl|k}}''(columns)''


|gr1= Math |=GROUP1
|p2= matrix2: [[Array]] of [[Array]] of [[Number]]s - matrix of the size {{hl|k}}''(rows)'' × {{hl|m}}''(columns)''
____________________________________________________________________________________________


| Returns resulting matrix from the [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 <tt>columns</tt> matrix1 <nowiki>==</nowiki> <tt>rows</tt> matrix2. The resulting matrix will be of the size n ✕ m. If the shapes do not match, empty array [] will be returned.<br><br>
|r1= [[Array]] of [[Array]] of [[Number]]s - resulting matrix of the size {{hl|n}}''(rows)'' &times; {{hl|m}}''(columns)''
[[Image:matrixMultiply.jpg|600px]]|Description=
____________________________________________________________________________________________


| matrix1 [[matrixMultiply]] matrix2 |Syntax=
|x1= <sqf>
 
[
|p1=matrix1: [[Array]] - matrix of the size <tt>n</tt>''(rows)'' ✕ <tt>k</tt>''(columns)''
 
|p2=matrix2: [[Array]] - matrix of the size <tt>k</tt>''(rows)'' ✕ <tt>m</tt>''(columns)''
 
| [[Array]] - resulting matrix of the size <tt>n</tt>''(rows)'' ✕ <tt>m</tt>''(columns)''|Return Value=
____________________________________________________________________________________________
 
|x1= <code>[
[2],
[2],
[2]
[2]
]  
]  
[[matrixMultiply]]
matrixMultiply  
[  
[
[3]  
[3]  
]
]
Line 40: Line 31:
[6],
[6],
[6]
[6]
] */</code> |Example 1=
] */
|x2= <code>[
</sqf>
 
|x2= <sqf>
[
[-1,0,0],
[-1,0,0],
[0,-1,0]
[0,-1,0]
]  
]  
[[matrixMultiply]]
matrixMultiply  
[
[
[1,2],
[1,2],
Line 55: Line 49:
[-1,-2],
[-1,-2],
[-3,-1]
[-3,-1]
] */</code> |Example 2=
] */
____________________________________________________________________________________________
</sqf>


| [[matrixTranspose]], [[vectorAdd]], [[vectorMagnitude]], [[vectorNormalized]], [[vectorMultiply]], [[vectorDotProduct]], [[vectorCrossProduct]], [[vectorDistance]], [[vectorLinearConversion]], [[vectorCos]], [[vectorFromTo]], [[vectorModelToWorld]], [[vectorWorldToModel]], [[BIS_fnc_transformVectorDirAndUp]] |See Also=
|seealso= [[matrixTranspose]] [[vectorAdd]] [[vectorMagnitude]] [[vectorNormalized]] [[vectorMultiply]] [[vectorDotProduct]] [[vectorCrossProduct]] [[vectorDistance]] [[vectorLinearConversion]] [[vectorCos]] [[vectorFromTo]] [[vectorModelToWorld]] [[vectorWorldToModel]] [[BIS_fnc_transformVectorDirAndUp]]
}}
}}


<dl class="command_description">
{{Note
<!-- BEGIN Note Section -->
|user= oOKexOo
<dd class="notedate">Posted on 30 Jun, 2019
|timestamp= 20190630035300
<dt class="note">[[User:oOKexOo| oOKexOo]]<dd class="note">
|text= Note that this command won't automatically transform a 1D array into a column vector
Note that this command won't transform a 1D array automatically into a column vector
<sqf>
<code>
[[-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, 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]] &#91;[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]] [[matrixMultiply]] [[1], [2], [3]] // correct, will return [[-1], [-2], [-3]]
</sqf>
</code>
}}
<!-- END Note Section -->
</dl>
 
<h3 style="display:none">Bottom Section</h3>
<!-- Appropriate categories go here -->
 
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]

Latest revision as of 14:13, 15 June 2024

Hover & click on the images for description

Description

Description:
matrixMultiply.jpg
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
oOKexOo - c
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]]