# Differences

This shows you the differences between two versions of the page.

 documentation:language_reference:objects:matrix:start [2018/08/06 11:23]Simon Heinze created documentation:language_reference:objects:matrix:start [2018/09/25 14:53] (current)Simon Heinze Added Code Example 2018/09/25 14:53 Simon Heinze Added Code Example2018/09/25 11:32 Simon Heinze Added mentioning of MatrixMeta2018/08/06 11:23 Simon Heinze created Next revision Previous revision 2018/09/25 14:53 Simon Heinze Added Code Example2018/09/25 11:32 Simon Heinze Added mentioning of MatrixMeta2018/08/06 11:23 Simon Heinze created Line 3: Line 3: ### ### - The object Matrix defines matrices, i.e. Tables ​of Tables. + The object Matrix defines matrices, i.e. tables ​of tables, and defines the standard lua math operations (+,-,*,/,^) among other functionalities on them. When creating a table-table object in Lua one has to tell the language that this is supposed to be a matrix. This is done by setting the metatable MatrixMeta. + + + ​ + --This creates a table of tables + A = {{1,  14 }, + {33, 4.7}} + B = {{3,  1.6 }, + ​{5, ​ 7}} + --This defines functionalities like addition or multiplication on M + setmetatable(A,​ MatrixMeta) + setmetatable(B,​ MatrixMeta) + + print(""​) + print("​A + B") + print(A + B) + + print(""​) + print("​A - B") + print(A - B) + + print(""​) + print("​A * B") + print(A * B) + + --This is equivalent to A * Matrix.Inverse(B) + print(""​) + print("​A / B") + print(A / B) + + --This is equivalent to Matrix.Inverse(A) + print(""​) + print("​1 / A") + print(1 / A) + + print(""​) + print("​A^2"​) + print(A^2) + ​ ### ### + + ​ + A + B + { { 4 , 15.6 } , + { 38 , 11.7 } } + + A - B + { { -2 , 12.4 } , + { 28 , -2.3 } } + + A * B + { { 73 , 99.6 } , + { 122.5 , 85.7 } } + + A / B + { { -4.8461538461538 , 3.1076923076923 } , + { 15.961538461538 , -2.9769230769231 } } + + 1 / A + { { -0.010277717034769 , 0.030614476273781 } , + { 0.072162694073912 , -0.0021867483052701 } } + + A^2 + { { 463 , 79.8 } , + { 188.1 , 484.09 } } + +