<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://www.quanty.org/lib/exe/css.php?s=feed" type="text/css"?>
<rdf:RDF
    xmlns="http://purl.org/rss/1.0/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel rdf:about="https://www.quanty.org/feed.php">
        <title>Quanty - documentation:language_reference:objects:matrix:operations</title>
        <description></description>
        <link>https://www.quanty.org/</link>
        <image rdf:resource="https://www.quanty.org/_media/wiki/dokuwiki.svg" />
       <dc:date>2026-04-29T11:47:05+00:00</dc:date>
        <items>
            <rdf:Seq>
                <rdf:li rdf:resource="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/add?rev=1763608833&amp;do=diff"/>
                <rdf:li rdf:resource="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/div?rev=1763608832&amp;do=diff"/>
                <rdf:li rdf:resource="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/eq?rev=1763608834&amp;do=diff"/>
                <rdf:li rdf:resource="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/index?rev=1763608833&amp;do=diff"/>
                <rdf:li rdf:resource="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/len?rev=1763608832&amp;do=diff"/>
                <rdf:li rdf:resource="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/mul?rev=1763608834&amp;do=diff"/>
                <rdf:li rdf:resource="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/newindex?rev=1763608832&amp;do=diff"/>
                <rdf:li rdf:resource="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/pow?rev=1763608834&amp;do=diff"/>
                <rdf:li rdf:resource="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/start?rev=1763608834&amp;do=diff"/>
                <rdf:li rdf:resource="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/sub?rev=1763608833&amp;do=diff"/>
                <rdf:li rdf:resource="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/tostring?rev=1763608833&amp;do=diff"/>
                <rdf:li rdf:resource="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/unm?rev=1763608833&amp;do=diff"/>
            </rdf:Seq>
        </items>
    </channel>
    <image rdf:about="https://www.quanty.org/_media/wiki/dokuwiki.svg">
        <title>Quanty</title>
        <link>https://www.quanty.org/</link>
        <url>https://www.quanty.org/_media/wiki/dokuwiki.svg</url>
    </image>
    <item rdf:about="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/add?rev=1763608833&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-11-20T03:20:33+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Add</title>
        <link>https://www.quanty.org/documentation/language_reference/objects/matrix/operations/add?rev=1763608833&amp;do=diff</link>
        <description>Add
One can add two matrices element by element
Example


A = Matrix.New({{1,2},{3,4}})
B = Matrix.New({{5,6},{7,8}})
C = A + B
print(C)


Result


{ {  6      ,  8      } ,
  {  10     ,  12     } }


Table of contents
matrix index</description>
    </item>
    <item rdf:about="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/div?rev=1763608832&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-11-20T03:20:32+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Div</title>
        <link>https://www.quanty.org/documentation/language_reference/objects/matrix/operations/div?rev=1763608832&amp;do=diff</link>
        <description>Div
One can divide a matrix by a number, but also a number by a matrix or a matrix by a matrix. A matrix divided by a number is done element wise. A number divided by a matrix yields the matrix inverse and a matrix divided by a matrix yields the product of the first matrix times the matrix inverse of the second matrix.matrix index</description>
    </item>
    <item rdf:about="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/eq?rev=1763608834&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-11-20T03:20:34+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Eq</title>
        <link>https://www.quanty.org/documentation/language_reference/objects/matrix/operations/eq?rev=1763608834&amp;do=diff</link>
        <description>Eq
We can compare two matrices with the == operator. One needs to be careful though as matrices stored as tables + meta methods are always different from matrices stored as user date. Comparison is done element by element.
Example

Input


A = Matrix.New({{1,2},{3,4}})
B = Matrix.New({{1,2},{3,4}})
C = Matrix.New({{5,6},{7,8}})

D = {{1,2},{3,4}}
setmetatable(D, MatrixMeta)
E = {{1,2},{3,4}}
setmetatable(E, MatrixMeta)
F = {{5,6},{7,8}}
setmetatable(F, MatrixMeta)

print(&quot;Matrix as Userdata comp…</description>
    </item>
    <item rdf:about="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/index?rev=1763608833&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-11-20T03:20:33+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Index</title>
        <link>https://www.quanty.org/documentation/language_reference/objects/matrix/operations/index?rev=1763608833&amp;do=diff</link>
        <description>Index
You can index matrices in the same way one indexes Lua tables
Example

Input


A = Matrix.New({{1,2},{3,4}})
B = A[2]
print(&quot;A[2] = &quot;,B)
C = A[2][1]
print(&quot;A[2][1] = &quot;,C)


Result


A[2] = 	 {  3      ,  4      }

A[2][1] = 	3


Table of contents
matrix index</description>
    </item>
    <item rdf:about="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/len?rev=1763608832&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-11-20T03:20:32+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Len</title>
        <link>https://www.quanty.org/documentation/language_reference/objects/matrix/operations/len?rev=1763608832&amp;do=diff</link>
        <description>Len
You can use the # operator to get the number of rows and columns of a matrix
Example

Input


A = Matrix.New({{1,2},{3,4},{5,6}})

print(&quot;number of rows in A = &quot;,#A)
print(&quot;number of cols in A = &quot;,#A[1])


Result


number of rows in A = 	3
number of cols in A = 	2

matrix index</description>
    </item>
    <item rdf:about="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/mul?rev=1763608834&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-11-20T03:20:34+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Mul</title>
        <link>https://www.quanty.org/documentation/language_reference/objects/matrix/operations/mul?rev=1763608834&amp;do=diff</link>
        <description>Mul
You can multiply matrices with numbers or with other matrices. The latter is implemented as matrix multiplication
Example

Input


A = Matrix.New({{1,2},{3,4},{5,6}})
B = Matrix.New({{1,2},{3,4}})
C = A*B
D = 2*B
E = B*2

print(C)
print(D)
print(E)

matrix index</description>
    </item>
    <item rdf:about="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/newindex?rev=1763608832&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-11-20T03:20:32+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Newindex</title>
        <link>https://www.quanty.org/documentation/language_reference/objects/matrix/operations/newindex?rev=1763608832&amp;do=diff</link>
        <description>Newindex
We can change the value of single elements or rows of a matrix by assigning new values to the indexed elements
Example

Input


A = Matrix.New({{1,2},{3,4},{5,6}})
print(A)
A[2][2] = 0
print(A)
A[3] ={7,8}
print(A)


Result


{ {  1      ,  2      } ,
  {  3      ,  4      } ,
  {  5      ,  6      } }

{ {  1      ,  2      } ,
  {  3      ,  0      } ,
  {  5      ,  6      } }

{ {  1      ,  2      } ,
  {  3      ,  0      } ,
  {  7      ,  8      } }

matrix index</description>
    </item>
    <item rdf:about="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/pow?rev=1763608834&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-11-20T03:20:34+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Pow</title>
        <link>https://www.quanty.org/documentation/language_reference/objects/matrix/operations/pow?rev=1763608834&amp;do=diff</link>
        <description>Pow
We can calculate matrix to the power of an integer
Example

Input


A = Matrix.New({{1,2},{3,4}})
B = A^2
print(B)
print(B==A*A)
C = A^3
print(C)
print(C==A*A*A)


Result


{ {  7      ,  10     } ,
  {  15     ,  22     } }

true
{ {  37     ,  54     } ,
  {  81     ,  118    } }

true

matrix index</description>
    </item>
    <item rdf:about="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/start?rev=1763608834&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-11-20T03:20:34+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Operations</title>
        <link>https://www.quanty.org/documentation/language_reference/objects/matrix/operations/start?rev=1763608834&amp;do=diff</link>
        <description>Operations
Quanty defines several operations like plus, minus, times, exponent, etc. Here you can find a list of the implemented operations
Table of contents
operations index</description>
    </item>
    <item rdf:about="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/sub?rev=1763608833&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-11-20T03:20:33+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Sub</title>
        <link>https://www.quanty.org/documentation/language_reference/objects/matrix/operations/sub?rev=1763608833&amp;do=diff</link>
        <description>Sub
One can subtract two matrices element by element
Example


A = Matrix.New({{1,2},{3,4}})
B = Matrix.New({{5,6},{7,8}})
C = B - A
print(C)


Result


{ {  4      ,  4      } ,
  {  4      ,  4      } }


Table of contents
matrix index</description>
    </item>
    <item rdf:about="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/tostring?rev=1763608833&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-11-20T03:20:33+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Tostring</title>
        <link>https://www.quanty.org/documentation/language_reference/objects/matrix/operations/tostring?rev=1763608833&amp;do=diff</link>
        <description>Tostring
We can turn matrix objects to strings. This allows one to print matrices. One can however also change the format of the string before printing a matrix
Example
Here we change the curly brackets {,} to straight brackets [,].
Input


A = Matrix.New({{1,2},{3,4}})
AStr = tostring(A)
print(AStr)
BStr = string.gsub(AStr, &quot;{&quot;, &quot;[&quot;)
BStr = string.gsub(BStr, &quot;}&quot;, &quot;]&quot;)
print(BStr)

matrix index</description>
    </item>
    <item rdf:about="https://www.quanty.org/documentation/language_reference/objects/matrix/operations/unm?rev=1763608833&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2025-11-20T03:20:33+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>Unm</title>
        <link>https://www.quanty.org/documentation/language_reference/objects/matrix/operations/unm?rev=1763608833&amp;do=diff</link>
        <description>Unm
We can take the negative of a matrix. This takes the negative value of each element of the matrix
Example

Input


A = Matrix.New({{1,2},{3,4}})
B = -A
print(B)


Result


{ { -1      , -2      } ,
  { -3      , -4      } }


Table of contents
matrix index</description>
    </item>
</rdf:RDF>
