summaryrefslogtreecommitdiff
path: root/macros/luatex/latex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-02-10 03:01:41 +0000
committerNorbert Preining <norbert@preining.info>2023-02-10 03:01:41 +0000
commite10a52ebe817fe7ff0235c066d83f51f39d3e023 (patch)
tree9148206ad017e5947e391d1eb4f3858feb493648 /macros/luatex/latex
parentffdef3cddca5a0b9133dd928291b000452777ad8 (diff)
CTAN sync 202302100301
Diffstat (limited to 'macros/luatex/latex')
-rw-r--r--macros/luatex/latex/lualinalg/2dvec.jpgbin0 -> 17528 bytes
-rw-r--r--macros/luatex/latex/lualinalg/3dvec.jpgbin0 -> 17920 bytes
-rw-r--r--macros/luatex/latex/lualinalg/README.txt24
-rw-r--r--macros/luatex/latex/lualinalg/luacomplex.lua298
-rw-r--r--macros/luatex/latex/lualinalg/lualinalg.pdfbin0 -> 345798 bytes
-rw-r--r--macros/luatex/latex/lualinalg/lualinalg.sty1685
-rw-r--r--macros/luatex/latex/lualinalg/lualinalg.tex1084
7 files changed, 3091 insertions, 0 deletions
diff --git a/macros/luatex/latex/lualinalg/2dvec.jpg b/macros/luatex/latex/lualinalg/2dvec.jpg
new file mode 100644
index 0000000000..7b857ab6d0
--- /dev/null
+++ b/macros/luatex/latex/lualinalg/2dvec.jpg
Binary files differ
diff --git a/macros/luatex/latex/lualinalg/3dvec.jpg b/macros/luatex/latex/lualinalg/3dvec.jpg
new file mode 100644
index 0000000000..1f84c4044f
--- /dev/null
+++ b/macros/luatex/latex/lualinalg/3dvec.jpg
Binary files differ
diff --git a/macros/luatex/latex/lualinalg/README.txt b/macros/luatex/latex/lualinalg/README.txt
new file mode 100644
index 0000000000..fc33bfedec
--- /dev/null
+++ b/macros/luatex/latex/lualinalg/README.txt
@@ -0,0 +1,24 @@
+# Introduction
+The lualinalg package is developed to perform operations on vectors and matrices defined over the field of real or complex numbers inside LaTeX documents.
+It provides flexible ways for defining and displaying vectors and matrices.
+No particular environment of LaTeX is required to use commands in the package.
+The package is written in Lua, and tex file is to be compiled with the LuaLaTeX engine.
+The time required for calculations is not an issue while compiling with LuaLaTeX.
+There is no need to install Lua on the user's system as TeX distributions (TeXLive or MikTeX) come bundled with LuaLaTeX.
+It may also save users' efforts to copy vectors and matrices from other software (which may not be in latex-compatible format) and to use them in a tex file.
+The vectors and matrices of reasonable size can be handled with ease.
+The package can be modified or extended by writing custom Lua programs.
+
+# License
+The \verb|lualinalg| package is released under the LaTeX Project Public License v1.3c or later.
+The complete license text is available at \url{http://www.latex-project.org/lppl.txt}.
+It is developed in Lua. Lua is available as a certified open-source software.
+Its license is simple and liberal, which is compatible with GPL.
+The package makes use of \verb|complex.lua| file which is available on \url{https://github.com/davidm/lua-matrix/blob/master/lua/matrix.lua}.
+It is available under the same licensing as that of Lua.
+The package also loads the luamaths package, which is available under the LaTeX Project Public License v1.3c or later.
+This package is loaded to use the standard mathematical functions and for computations on real numbers while performing operations on vectors and matrices.
+
+#Installation and Inclusion
+The installation of lualinalg package is similar to plain latex package, where the .sty file is in LaTeX directory of texmf tree.
+The package can be included with \usepackage{lualinalg} command in the preamble of the LaTeX document. \ No newline at end of file
diff --git a/macros/luatex/latex/lualinalg/luacomplex.lua b/macros/luatex/latex/lualinalg/luacomplex.lua
new file mode 100644
index 0000000000..b817ce66b6
--- /dev/null
+++ b/macros/luatex/latex/lualinalg/luacomplex.lua
@@ -0,0 +1,298 @@
+
+--Version=1.0, Date=31-Jan-2023
+-- provides module for complex numbers
+
+--Contains a modified version of the file complex.lua. It is availalbe on the link https://github.com/davidm/lua-matrix/blob/master/lua/matrix.lua. This is licensed under the same terms as Lua itself. This license allows to freely copy, modify and distribute the file for any purpose and without any restrictions.
+
+--Licensed under the same terms as Lua itself. This license allows to freely copy, modify and distribute the file for any purpose and without any restrictions.
+
+
+
+complex = {}
+
+local complex_meta = {}
+
+local function parse_scalar(s, pos0)
+ local x, n, pos = s:match('^([+-]?[%d%.]+)(.?)()', pos0)
+ if not x then return end
+ if n == 'e' or n == 'E' then
+ local x2, n2, pos2 = s:match('^([+-]?%d+)(.?)()', pos)
+ if not x2 then error 'number format error' end
+ x = tonumber(x..n..x2)
+ if not x then error 'number format error' end
+ return x, n2, pos2
+ else
+ x = tonumber(x)
+ if not x then error 'number format error' end
+ return x, n, pos
+ end
+end
+local function parse_component(s, pos0)
+ local x, n, pos = parse_scalar(s, pos0)
+ if not x then
+ local x2, n2, pos2 = s:match('^([+-]?)(i)()$', pos0)
+ if not x2 then error 'number format error' end
+ return (x2=='-' and -1 or 1), n2, pos2
+ end
+ if n == '/' then
+ local x2, n2, pos2 = parse_scalar(s, pos)
+ x = x / x2
+ return x, n2, pos2
+ end
+ return x, n, pos
+end
+local function parse_complex(s)
+ local x, n, pos = parse_component(s, 1)
+ if n == '+' or n == '-' then
+ local x2, n2, pos2 = parse_component(s, pos)
+ if n2 ~= 'i' or pos2 ~= #s+1 then error 'number format error' end
+ if n == '-' then x2 = - x2 end
+ return x, x2
+ elseif n == '' then
+ return x, 0
+ elseif n == 'i' then
+ if pos ~= #s+1 then error 'number format error' end
+ return 0, x
+ else
+ error 'number format error'
+ end
+end
+
+function complex.to( num )
+ -- check for table type
+ if type( num ) == "table" then
+ -- check for a complex number
+ if getmetatable( num ) == complex_meta then
+ return num
+ end
+ local real,imag = tonumber( num[1] ),tonumber( num[2] )
+ if real and imag then
+ return setmetatable( { real,imag }, complex_meta )
+ end
+ return
+ end
+ local isnum = tonumber( num )
+ if isnum then
+ return setmetatable( { isnum,0 }, complex_meta )
+ end
+ if type( num ) == "string" then
+ local real, imag = parse_complex(num)
+ return setmetatable( { real, imag }, complex_meta )
+ end
+end
+
+setmetatable( complex, { __call = function( _,num ) return complex.to( num ) end } )
+
+
+function complex.new( ... )
+ return setmetatable( { ... }, complex_meta )
+end
+
+
+function complex.type( arg )
+ if getmetatable( arg ) == complex_meta then
+ return "complex"
+ end
+end
+
+
+function complex.convpolar( radius, phi )
+ return setmetatable( { radius * math.cos( phi ), radius * math.sin( phi ) }, complex_meta )
+end
+
+function complex.convpolardeg( radius, phi )
+ phi = phi/180 * math.pi
+ return setmetatable( { radius * math.cos( phi ), radius * math.sin( phi ) }, complex_meta )
+end
+
+function complex.tostring( cx,formatstr )
+ local real,imag = cx[1],cx[2]
+ if formatstr then
+ if imag == 0 then
+ return string.format( formatstr, real )
+ elseif real == 0 then
+ return string.format( formatstr, imag ).."i"
+ elseif imag > 0 then
+ return string.format( formatstr, real ).."+"..string.format( formatstr, imag ).."i"
+ end
+ return string.format( formatstr, real )..string.format( formatstr, imag ).."i"
+ end
+ if imag == 0 then
+ return real
+ elseif real == 0 then
+ return ((imag==1 and "") or (imag==-1 and "-") or imag).."i"
+ elseif imag > 0 then
+ return real.."+"..(imag==1 and "" or imag).."i"
+ end
+ return real..(imag==-1 and "-" or imag).."i"
+end
+
+function complex.print( ... )
+ print( complex.tostring( ... ) )
+end
+
+function complex.polar( cx )
+ return math.sqrt( cx[1]^2 + cx[2]^2 ), math.atan2( cx[2], cx[1] )
+end
+
+function complex.polardeg( cx )
+ return math.sqrt( cx[1]^2 + cx[2]^2 ), math.atan2( cx[2], cx[1] ) / math.pi * 180
+end
+
+function complex.norm2( cx )
+ return cx[1]^2 + cx[2]^2
+end
+
+function complex.abs( cx )
+ return math.sqrt( cx[1]^2 + cx[2]^2 )
+end
+
+function complex.get( cx )
+ return cx[1],cx[2]
+end
+
+
+function complex.set( cx,real,imag )
+ cx[1],cx[2] = real,imag
+end
+
+function complex.is( cx,real,imag )
+ if cx[1] == real and cx[2] == imag then
+ return true
+ end
+ return false
+end
+
+
+function complex.copy( cx )
+ return setmetatable( { cx[1],cx[2] }, complex_meta )
+end
+
+
+function complex.add( cx1,cx2 )
+ return setmetatable( { cx1[1]+cx2[1], cx1[2]+cx2[2] }, complex_meta )
+end
+
+
+function complex.sub( cx1,cx2 )
+ return setmetatable( { cx1[1]-cx2[1], cx1[2]-cx2[2] }, complex_meta )
+end
+
+function complex.mul( cx1,cx2 )
+ return setmetatable( { cx1[1]*cx2[1] - cx1[2]*cx2[2],cx1[1]*cx2[2] + cx1[2]*cx2[1] }, complex_meta )
+end
+
+
+function complex.mulnum( cx,num )
+ return setmetatable( { cx[1]*num,cx[2]*num }, complex_meta )
+end
+
+function complex.div( cx1,cx2 )
+ local val = cx2[1]^2 + cx2[2]^2
+ return setmetatable( { (cx1[1]*cx2[1]+cx1[2]*cx2[2])/val,(cx1[2]*cx2[1]-cx1[1]*cx2[2])/val }, complex_meta )
+end
+
+function complex.divnum( cx,num )
+ return setmetatable( { cx[1]/num,cx[2]/num }, complex_meta )
+end
+
+
+function complex.pow( cx,num )
+ if math.floor( num ) == num then
+ if num < 0 then
+ local val = cx[1]^2 + cx[2]^2
+ cx = { cx[1]/val,-cx[2]/val }
+ num = -num
+ end
+ local real,imag = cx[1],cx[2]
+ for i = 2,num do
+ real,imag = real*cx[1] - imag*cx[2],real*cx[2] + imag*cx[1]
+ end
+ return setmetatable( { real,imag }, complex_meta )
+ end
+ local length,phi = math.sqrt( cx[1]^2 + cx[2]^2 )^num, math.atan2( cx[2], cx[1] )*num
+ return setmetatable( { length * math.cos( phi ), length * math.sin( phi ) }, complex_meta )
+end
+
+function complex.sqrt( cx )
+ local len = math.sqrt( cx[1]^2+cx[2]^2 )
+ local sign = (cx[2]<0 and -1) or 1
+ return setmetatable( { math.sqrt((cx[1]+len)/2), sign*math.sqrt((len-cx[1])/2) }, complex_meta )
+end
+
+
+function complex.ln( cx )
+ return setmetatable( { math.log(math.sqrt( cx[1]^2 + cx[2]^2 )),
+ math.atan2( cx[2], cx[1] ) }, complex_meta )
+end
+
+function complex.exp( cx )
+ local expreal = math.exp(cx[1])
+ return setmetatable( { expreal*math.cos(cx[2]), expreal*math.sin(cx[2]) }, complex_meta )
+end
+
+
+function complex.conjugate( cx )
+ return setmetatable( { cx[1], -cx[2] }, complex_meta )
+end
+
+function complex.round( cx,idp )
+ local mult = 10^( idp or 0 )
+ return setmetatable( { math.floor( cx[1] * mult + 0.5 ) / mult,
+ math.floor( cx[2] * mult + 0.5 ) / mult }, complex_meta )
+end
+
+
+complex.zero = complex.new(0, 0)
+complex.one = complex.new(1, 0)
+
+
+
+complex_meta.__add = function( cx1,cx2 )
+ local cx1,cx2 = complex.to( cx1 ),complex.to( cx2 )
+ return complex.add( cx1,cx2 )
+end
+complex_meta.__sub = function( cx1,cx2 )
+ local cx1,cx2 = complex.to( cx1 ),complex.to( cx2 )
+ return complex.sub( cx1,cx2 )
+end
+complex_meta.__mul = function( cx1,cx2 )
+ local cx1,cx2 = complex.to( cx1 ),complex.to( cx2 )
+ return complex.mul( cx1,cx2 )
+end
+complex_meta.__div = function( cx1,cx2 )
+ local cx1,cx2 = complex.to( cx1 ),complex.to( cx2 )
+ return complex.div( cx1,cx2 )
+end
+complex_meta.__pow = function( cx,num )
+ if num == "*" then
+ return complex.conjugate( cx )
+ end
+ return complex.pow( cx,num )
+end
+complex_meta.__unm = function( cx )
+ return setmetatable( { -cx[1], -cx[2] }, complex_meta )
+end
+complex_meta.__eq = function( cx1,cx2 )
+ if cx1[1] == cx2[1] and cx1[2] == cx2[2] then
+ return true
+ end
+ return false
+end
+complex_meta.__tostring = function( cx )
+ return tostring( complex.tostring( cx ) )
+end
+complex_meta.__concat = function( cx,cx2 )
+ return tostring(cx)..tostring(cx2)
+end
+-- cx( cx, formatstr )
+complex_meta.__call = function( ... )
+ print( complex.tostring( ... ) )
+end
+complex_meta.__index = {}
+for k,v in pairs( complex ) do
+ complex_meta.__index[k] = v
+end
+
+return complex
+
diff --git a/macros/luatex/latex/lualinalg/lualinalg.pdf b/macros/luatex/latex/lualinalg/lualinalg.pdf
new file mode 100644
index 0000000000..bdc2769722
--- /dev/null
+++ b/macros/luatex/latex/lualinalg/lualinalg.pdf
Binary files differ
diff --git a/macros/luatex/latex/lualinalg/lualinalg.sty b/macros/luatex/latex/lualinalg/lualinalg.sty
new file mode 100644
index 0000000000..53fe7fd688
--- /dev/null
+++ b/macros/luatex/latex/lualinalg/lualinalg.sty
@@ -0,0 +1,1685 @@
+
+% The lualinalg package
+% Authors: Chetan Shirore and Ajit Kumar
+% version 1.0
+% Licensed under LaTeX Project Public License v1.3c or later. The complete license text is available at http://www.latex-project.org/lppl.txt.
+
+
+\ProvidesPackage{lualinalg}[1.0]
+\RequirePackage{xkeyval}
+\RequirePackage{amsmath}
+\RequirePackage{luamaths}
+\RequirePackage{luacode}
+\begin{luacode*}
+local complex = require "luacomplex"
+
+-- matrices part
+matrices = {}
+
+matrix = {} --module
+
+local matrix_meta = {}
+
+function matrix.new(matrix, rows, columns)
+ if type(rows) == "table" then
+ for i = 1, #rows do
+ if #rows[1] ~= #rows[i] then
+ error("Check input matrix.")
+ end
+ end
+ return setmetatable(rows, matrix_meta)
+ end
+ local mtx = {}
+ if columns == "I" then
+ for i = 1, rows do
+ mtx[i] = {}
+ for j = 1, rows do
+ if i == j then
+ mtx[i][j] = 1
+ else
+ mtx[i][j] = 0
+ end
+ end
+ end
+ return setmetatable(mtx, matrix_meta)
+ end
+end
+
+setmetatable(
+ matrix,
+ {__call = function(...)
+ return matrix.new(...)
+ end}
+)
+
+function matrix.add(m1, m2)
+ local mtx = {}
+ for i = 1, #m1 do
+ local m3i = {}
+ mtx[i] = m3i
+ for j = 1, #m1[1] do
+ m3i[j] = m1[i][j] + m2[i][j]
+ end
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+function matrix.sub(m1, m2)
+ local mtx = {}
+ for i = 1, #m1 do
+ local m3i = {}
+ mtx[i] = m3i
+ for j = 1, #m1[1] do
+ m3i[j] = m1[i][j] - m2[i][j]
+ end
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+function matrix.mulnum(m1, num)
+ local mtx = {}
+ -- multiply elements with number
+ for i = 1, #m1 do
+ mtx[i] = {}
+ for j = 1, #m1[1] do
+ mtx[i][j] = m1[i][j] * num
+ end
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+function matrix.mul(m1, m2)
+ local mtx = {}
+ for i = 1, #m1 do
+ mtx[i] = {}
+ for j = 1, #m2[1] do
+ local num = m1[i][1] * m2[1][j]
+ for n = 2, #m1[1] do
+ num = num + m1[i][n] * m2[n][j]
+ end
+ mtx[i][j] = num
+ end
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+function matrix.swapRows(m1, p, q)
+ local mtx = {}
+ for i = 1, #m1 do
+ mtx[i] = {}
+ for j = 1, #m1[1] do
+ mtx[i][j] = m1[i][j]
+ end
+ end
+ for j = 1, #m1[1] do
+ rowHold = m1[p][j]
+ mtx[p][j] = m1[q][j]
+ mtx[q][j] = rowHold
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+function matrix.swapCols(m1, p, q)
+ local mtx = {}
+ for i = 1, #m1 do
+ mtx[i] = {}
+ for j = 1, #m1[1] do
+ mtx[i][j] = m1[i][j]
+ end
+ end
+ for j = 1, #m1 do
+ rowHold = m1[j][p]
+ mtx[j][p] = m1[j][q]
+ mtx[j][q] = rowHold
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+function matrix.mulRow(m1, p, k)
+ local mtx = {}
+ for i = 1, #m1 do
+ mtx[i] = {}
+ for j = 1, #m1[1] do
+ mtx[i][j] = m1[i][j]
+ end
+ end
+ for j = 1, #m1[1] do
+ mtx[p][j] = k * m1[p][j]
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+function matrix.mulAddRow(m1, k, p, q)
+ if p == q then
+ error("Can't operate on same row.")
+ end
+ local mtx = {}
+ for i = 1, #m1 do
+ mtx[i] = {}
+ for j = 1, #m1[1] do
+ mtx[i][j] = m1[i][j]
+ end
+ end
+ for j = 1, #m1[1] do
+ mtx[q][j] = k * (mtx[p][j]) + mtx[q][j]
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+function matrix.mulCol(m1, p, k)
+ local mtx = {}
+ for i = 1, #m1 do
+ mtx[i] = {}
+ for j = 1, #m1[1] do
+ mtx[i][j] = m1[i][j]
+ end
+ end
+ for j = 1, #m1 do
+ mtx[j][p] = k * m1[j][p]
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+function matrix.mulAddCol(m1, k, p, q)
+ if p == q then
+ error("Can't operate on same column.")
+ end
+ local mtx = {}
+ for i = 1, #m1 do
+ mtx[i] = {}
+ for j = 1, #m1[1] do
+ mtx[i][j] = m1[i][j]
+ end
+ end
+ for j = 1, #m1 do
+ mtx[j][q] = k * mtx[j][p] + mtx[j][q]
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+function matrix.transpose(m1)
+ local mtx = {}
+ for i = 1, #m1[1] do
+ mtx[i] = {}
+ for j = 1, #m1 do
+ mtx[i][j] = m1[j][i]
+ end
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+function matrix.subm(m1, i1, j1, i2, j2)
+ local mtx = {}
+ for i = i1, i2 do
+ local _i = i - i1 + 1
+ mtx[_i] = {}
+ for j = j1, j2 do
+ local _j = j - j1 + 1
+ mtx[_i][_j] = m1[i][j]
+ end
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+function matrix.concath(m1, m2)
+ if #m1 ~= #m2 then
+ error("No. of rows must be equal.")
+ end
+ local mtx = {}
+ local offset = #m1[1]
+ for i = 1, #m1 do
+ mtx[i] = {}
+ for j = 1, offset do
+ mtx[i][j] = m1[i][j]
+ end
+ for j = 1, #m2[1] do
+ mtx[i][j + offset] = m2[i][j]
+ end
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+function matrix.concatv(m1, m2)
+ if #m1[1] ~= #m2[1] then
+ error("No. of columns must be equal.")
+ end
+ local mtx = {}
+ for i = 1, #m1 do
+ mtx[i] = {}
+ for j = 1, #m1[1] do
+ mtx[i][j] = m1[i][j]
+ end
+ end
+ local offset = #mtx
+ for i = 1, #m2 do
+ local _i = i + offset
+ mtx[_i] = {}
+ for j = 1, #m2[1] do
+ mtx[_i][j] = m2[i][j]
+ end
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+function matrix.rows(mtx)
+ return #mtx
+end
+
+function matrix.columns(mtx)
+ return #mtx[1]
+end
+
+setmetatable(
+ matrix,
+ {__call = function(...)
+ return matrix.new(...)
+ end}
+)
+
+function matrix.getelement(mtx, i, j)
+ if mtx[i] and mtx[i][j] then
+ return mtx[i][j]
+ end
+end
+
+function matrix.setelement(mtx, i, j, value)
+ if matrix.getelement(mtx, i, j) then
+ mtx[i][j] = value
+ return value
+ end
+end
+
+function matrix.invert(m1)
+ if #m1 ~= #m1[1] then
+ error("matrix not square")
+ end
+ if matrix.det(m1) == 0 then
+ error("matrix not invertible")
+ end
+ local mtx = {}
+ local idnt = matrix(#m1, "I")
+ mtx = matrix.subm(matrix.rref(matrix.concath(m1, idnt)), 1, #m1 + 1, #m1, #m1 + #m1)
+ return mtx
+end
+
+function matrix.trace(m1)
+ if #m1 ~= #m1[1] then
+ error("matrix not square")
+ end
+ local sum = 0
+
+ for i = 1, #m1 do
+ for j = 1, #m1[1] do
+ if i == j then
+ sum = sum + m1[i][j]
+ end
+ end
+ end
+
+ return sum
+end
+
+function matrix.normF(mtx)
+ local result = 0
+ for i = 1, #mtx do
+ for j = 1, #mtx[1] do
+ local e = mtx[i][j]
+ result = result + complex.abs(complex(e)) ^ 2
+ end
+ end
+ return complex.sqrt(complex(result))
+end
+
+function matrix.normmax(mtx)
+ local result = 0
+ for i = 1, #mtx do
+ for j = 1, #mtx[1] do
+ local e = complex.abs(complex(mtx[i][j]))
+ if e > result then
+ result = e
+ end
+ end
+ end
+ return result
+end
+
+function matrix.norminfty(mtx)
+ local e = 0
+ local result = 0
+ for i = 1, #mtx do
+ local e = 0
+ for j = 1, #mtx[1] do
+ e = e + complex.abs(complex(mtx[i][j]))
+ end
+ if e > result then
+ result = e
+ end
+ end
+ return result
+end
+
+function matrix.norm1(mtx)
+ local e = 0
+ local result = 0
+ for i = 1, #mtx[1] do
+ local e = 0
+ for j = 1, #mtx do
+ e = e + complex.abs(complex(mtx[j][i]))
+ end
+ if e > result then
+ result = e
+ end
+ end
+ return result
+end
+
+function matrix.conjugate(m1)
+ local mtx = matrix.copy(m1)
+ for i = 1, #mtx do
+ for j = 1, #mtx[1] do
+ mtx[i][j] = complex.conjugate(complex(mtx[i][j]))
+ end
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+function matrix.conjugateT(m1)
+ local mtx = {}
+ for i = 1, #m1[1] do
+ mtx[i] = {}
+ for j = 1, #m1 do
+ mtx[i][j] = complex.conjugate(complex(m1[j][i]))
+ end
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+function copy(x)
+ return type(x) == "table" and x.copy(x) or x
+end
+
+function matrix.pow(m1, num)
+ assert(num == math.floor(num), "exponent not an integer")
+ if num == 0 then
+ return matrix:new(#m1, "I")
+ end
+ if num < 0 then
+ local rank
+ m1, rank = matrix.invert(m1)
+ if not m1 then
+ return m1, rank
+ end -- singular
+ num = -num
+ end
+ local mtx = matrix.copy(m1)
+ for i = 2, num do
+ mtx = matrix.mul(mtx, m1)
+ end
+ return mtx
+end
+
+function matrix.createrandom(nrow, ncol, start, stop)
+ mtx = {}
+ for i = 1, nrow do
+ mtx[i] = {}
+ for j = 1, ncol do
+ mtx[i][j] = math.random(start, stop)
+ mtx[i][j] = mtx[i][j] + math.min(math.random(), math.abs(mtx[i][j] - start), math.abs(stop - mtx[i][j]))
+ end
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+function matrix.process(m1)
+ --m1=load("return "..m1)()
+ return matrix.mulnum(m1, 1.0)
+end
+
+function matrix.det(m1)
+ assert(#m1 == #m1[1], "matrix not square")
+
+ local size = #m1
+
+ if size == 1 then
+ return m1[1][1]
+ end
+
+ if size == 2 then
+ return m1[1][1] * m1[2][2] - m1[2][1] * m1[1][2]
+ end
+
+ if size == 3 then
+ return (m1[1][1] * m1[2][2] * m1[3][3] + m1[1][2] * m1[2][3] * m1[3][1] + m1[1][3] * m1[2][1] * m1[3][2] -
+ m1[1][3] * m1[2][2] * m1[3][1] -
+ m1[1][1] * m1[2][3] * m1[3][2] -
+ m1[1][2] * m1[2][1] * m1[3][3])
+ end
+
+ local e = m1[1][1]
+ local zero = type(e) == "table" and e.zero or 0
+ local norm2 = type(e) == "table" and e.norm2 or number_norm2
+
+ local mtx = matrix.copy(m1)
+ local det = 1
+
+ for j = 1, #mtx[1] do
+ local rows = #mtx
+ local subdet, xrow
+ for i = 1, rows do
+ local e = mtx[i][j]
+ if not subdet then
+ if e ~= zero then
+ subdet, xrow = e, i
+ end
+ elseif e ~= zero and math.abs(norm2(e) - 1) < math.abs(norm2(subdet) - 1) then
+ subdet, xrow = e, i
+ end
+ end
+ if subdet then
+ if xrow ~= rows then
+ mtx[rows], mtx[xrow] = mtx[xrow], mtx[rows]
+ det = -det
+ end
+
+ for i = 1, rows - 1 do
+ if mtx[i][j] ~= zero then
+ local factor = mtx[i][j] / subdet
+ for n = j + 1, #mtx[1] do
+ mtx[i][n] = mtx[i][n] - factor * mtx[rows][n]
+ end
+ end
+ end
+ if math.fmod(rows, 2) == 0 then
+ det = -det
+ end
+ det = det * subdet
+ table.remove(mtx)
+ else
+ return det * 0
+ end
+ end
+
+ return det
+end
+
+function matrix.copy(m1)
+ local mtx = {}
+ for i = 1, #m1 do
+ mtx[i] = {}
+ for j = 1, #m1[1] do
+ mtx[i][j] = m1[i][j]
+ end
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+norm2 = type(e) == "table" and e.norm2 or number_norm2
+
+function number_norm2(x)
+ return x * x
+end
+
+function matrix.op(exp)
+ return load("return " .. exp, exp, "t", matrices)()
+end
+
+function matrix.rref(mtx)
+ local mtx = matrix.copy(mtx)
+ step = 1
+ lead = 1
+ rowCount = #mtx
+ columnCount = #mtx[1]
+ for r = 1, rowCount do
+ if lead > columnCount then
+ return mtx
+ end
+ i = r
+ while (mtx[i][lead] == 0) do
+ i = i + 1
+ if (i - 1 == rowCount) then
+ i = r
+ if (columnCount == lead) then
+ return mtx
+ end
+ lead = lead + 1
+ end
+ end
+
+ if i ~= r then
+ mtx = matrix.swapRows(mtx, i, r)
+ end
+
+ local m = mtx[r][lead]
+ if (mtx[r][lead] ~= 0) then
+ for u = 1, columnCount do
+ mtx[r][u] = mtx[r][u] / m
+ end
+ end
+ for i = 1, rowCount do
+ local m = mtx[i][lead]
+ if (i ~= r) then
+ for v = 1, columnCount do
+ mtx[i][v] = mtx[i][v] - m * mtx[r][v]
+ end
+ end
+ end
+ lead = lead + 1
+ end
+ return mtx
+end
+
+function matrix.rref0E(mtx, fom, dignum)
+ local strng = ""
+ truncate = truncate or 6
+ local mtx = matrix.copy(mtx)
+ step = 1
+ lead = 1
+ stepCnt = 0
+ rowCount = #mtx
+ columnCount = #mtx[1]
+ for r = 1, rowCount do
+ if lead > columnCount then
+ return mtx
+ end
+ i = r
+ while (mtx[i][lead] == 0) do
+ i = i + 1
+ if (i - 1 == rowCount) then
+ i = r
+ if (columnCount == lead) then
+ if stepCnt == 0 then
+ stepCnt = stepCnt + 1
+ strng = strng .. "Step " .. tostring(stepCnt) ".$$" .. tostring(matrix.show(mtx, fom, dignum))
+ return strng
+ end
+ return strng
+ end
+ lead = lead + 1
+ end
+ end
+
+ if i ~= r then
+ mtx = matrix.swapRows(mtx, i, r)
+ stepCnt = stepCnt + 1
+ strng =
+ strng ..
+ "Step " ..
+ tostring(stepCnt) ..
+ ": Interchange rows " ..
+ tostring(i) ..
+ " and " .. tostring(r) .. ".$$" .. tostring(matrix.show(mtx, fom, dignum)) .. "$$"
+ end
+
+ local m = mtx[r][lead]
+ if (mtx[r][lead] ~= 0) then
+ for u = 1, columnCount do
+ mtx[r][u] = mtx[r][u] / m
+ end
+ if m ~= 1.0 then
+ if m ~= complex("1.0") then
+ stepCnt = stepCnt + 1
+ strng =
+ strng ..
+ "Step " ..
+ tostring(stepCnt) ..
+ ": Divide row " ..
+ tostring(r) ..
+ " by " ..
+ tostring(complex.round(complex(m), dignum)) ..
+ ".$$" .. tostring(matrix.show(mtx, fom, dignum)) .. "$$"
+ end
+ end
+ end
+ for i = 1, rowCount do
+ local m = mtx[i][lead]
+ if (i ~= r) then
+ for v = 1, columnCount do
+ mtx[i][v] = mtx[i][v] - m * mtx[r][v]
+ end
+ if m ~= 0 then
+ if m ~= complex("0.0") then
+ stepCnt = stepCnt + 1
+ strng =
+ strng ..
+ "Step " ..
+ tostring(stepCnt) ..
+ ": Multiply row " ..
+ tostring(r) ..
+ " by " ..
+ tostring(complex.round(complex(m), dignum)) ..
+ " and subtract it from row " ..
+ tostring(i) ..
+ ".$$" .. tostring(matrix.show(mtx, fom, dignum)) .. "$$"
+ end
+ end
+ end
+ end
+ lead = lead + 1
+ end
+ return strng
+end
+
+function matrix.GaussJordan(mtx, augmt)
+ local mtx = matrix.copy(mtx)
+ local augmt = matrix.copy(augmt)
+ step = 1
+ lead = 1
+ rowCount = #mtx
+ columnCount = #mtx[1]
+ for r = 1, rowCount do
+ if lead > columnCount then
+ return matrix.concath(mtx, augmt)
+ end
+ i = r
+ while (mtx[i][lead] == 0) do
+ i = i + 1
+ if (i - 1 == rowCount) then
+ i = r
+ if (columnCount == lead) then
+ return matrix.concath(mtx, augmt)
+ end
+ lead = lead + 1
+ end
+ end
+
+ if i ~= r then
+ mtx = matrix.swapRows(mtx, i, r)
+ augmt = matrix.swapRows(augmt, i, r)
+ end
+
+ local m = mtx[r][lead]
+ if (mtx[r][lead] ~= 0) then
+ for u = 1, columnCount do
+ mtx[r][u] = mtx[r][u] / m
+ end
+ augmt[r][1] = augmt[r][1] / m
+ end
+ for i = 1, rowCount do
+ local m = mtx[i][lead]
+ if (i ~= r) then
+ for v = 1, columnCount do
+ mtx[i][v] = mtx[i][v] - m * mtx[r][v]
+ end
+ augmt[i][1] = augmt[i][1] - m * augmt[r][1]
+ end
+ end
+ lead = lead + 1
+ end
+ return matrix.concath(mtx, augmt)
+end
+
+function matrix.gauss0E(mtx, augmt, fom, dignum)
+ local strng = ""
+ truncate = truncate or 6
+ local mtx = matrix.copy(mtx)
+ local augmt = matrix.copy(augmt)
+ if matrix.columns(augmt) ~= 1 then
+ error("The second matrix should have only 1 column.")
+ end
+ step = 1
+ lead = 1
+ stepCnt = 0
+ rowCount = #mtx
+ columnCount = #mtx[1]
+ for r = 1, rowCount do
+ if lead > columnCount then
+ return mtx
+ end
+ i = r
+ while (mtx[i][lead] == 0) do
+ i = i + 1
+ if (i - 1 == rowCount) then
+ i = r
+ if (columnCount == lead) then
+ if stepCnt == 0 then
+ stepCnt = stepCnt + 1
+ strng =
+ strng ..
+ "Step " ..
+ tostring(stepCnt) ".$$" ..
+ tostring(matrix.show(matrix.concath(mtx, augmt), fom, dignum))
+ return strng
+ end
+ return strng
+ end
+ lead = lead + 1
+ end
+ end
+
+ if i ~= r then
+ mtx = matrix.swapRows(mtx, i, r)
+ augmt = matrix.swapRows(augmt, i, r)
+ stepCnt = stepCnt + 1
+ strng =
+ strng ..
+ "Step " ..
+ tostring(stepCnt) ..
+ ": Interchange rows " ..
+ tostring(i) ..
+ " and " .. tostring(r) .. ".$$" .. tostring(matrix.show(mtx, fom, dignum)) .. "$$"
+ end
+
+ local m = mtx[r][lead]
+ if (mtx[r][lead] ~= 0) then
+ for u = 1, columnCount do
+ mtx[r][u] = mtx[r][u] / m
+ end
+ augmt[r][1] = augmt[r][1] / m
+ if m ~= 1.0 then
+ if m ~= complex("1.0") then
+ stepCnt = stepCnt + 1
+ strng =
+ strng ..
+ "Step " ..
+ tostring(stepCnt) ..
+ ": Divide row " ..
+ tostring(r) ..
+ " by " ..
+ tostring(complex.round(complex(m), dignum)) ..
+ ".$$" ..
+ tostring(matrix.show(matrix.concath(mtx, augmt), fom, dignum)) ..
+ "$$"
+ end
+ end
+ end
+ for i = 1, rowCount do
+ local m = mtx[i][lead]
+ if (i ~= r) then
+ for v = 1, columnCount do
+ mtx[i][v] = mtx[i][v] - m * mtx[r][v]
+ end
+ augmt[i][1] = augmt[i][1] - m * augmt[r][1]
+ if m ~= 0 then
+ if m ~= complex("0.0") then
+ stepCnt = stepCnt + 1
+ strng =
+ strng ..
+ "Step " ..
+ tostring(stepCnt) ..
+ ": Multiply row " ..
+ tostring(r) ..
+ " by " ..
+ tostring(complex.round(complex(m), dignum)) ..
+ " and subtract it from row " ..
+ tostring(i) ..
+ ".$$" ..
+ tostring(
+ matrix.show(matrix.concath(mtx, augmt), fom, dignum)
+ ) ..
+ "$$"
+ end
+ end
+ end
+ end
+ lead = lead + 1
+ end
+ return strng
+end
+
+function matrix.rank(m1)
+ local mtx = {}
+ mtx = matrix.rref(m1)
+ rank = #mtx
+ for i = 1, #mtx do
+ if CheckEqual(mtx[i], 0) then
+ rank = rank - 1
+ end
+ end
+ return rank
+end
+
+function CheckEqual(Values, Number)
+ local CheckEqual = true
+ local i = 1
+
+ while (CheckEqual and (i <= #Values)) do
+ if Values[i] == Number then
+ i = i + 1
+ else
+ CheckEqual = false
+ end
+ end
+
+ return CheckEqual
+end
+
+function matrix.replace(m1, func, ...)
+ local mtx = {}
+ for i = 1, #m1 do
+ local m1i = m1[i]
+ local mtxi = {}
+ for j = 1, #m1i do
+ mtxi[j] = func(m1i[j], ...)
+ end
+ mtx[i] = mtxi
+ end
+ return setmetatable(mtx, matrix_meta)
+end
+
+function matrix.show(mtx, format, dig)
+ mtx = matrix.process(mtx)
+ local format = format or "bmatrix"
+ local dig = dig or 6
+ local str = "\\begin{" .. format .. "}"
+ for i = 1, #mtx do
+ str = str .. "\t" .. complex.round(complex(mtx[i][1]), dig)
+ for j = 2, #mtx[1] do
+ str = str .. " & " .. complex.round(complex(mtx[i][j]), dig)
+ end
+ if i == #mtx then
+ str = str .. " \\\\ "
+ else
+ str = str .. " \\\\ "
+ end
+ end
+ return str .. "\\end{" .. format .. "} "
+end
+
+matrix_meta.__tostring = function(...)
+ return matrix.show(...)
+end
+
+matrix_meta.__add = function(...)
+ return matrix.add(...)
+end
+
+matrix_meta.__sub = function(...)
+ return matrix.sub(...)
+end
+
+matrix_meta.__mul = function(m1, m2)
+ if getmetatable(m1) ~= matrix_meta then
+ return matrix.mulnum(m2, m1)
+ elseif getmetatable(m2) ~= matrix_meta then
+ return matrix.mulnum(m1, m2)
+ end
+ return matrix.mul(m1, m2)
+end
+
+matrix_meta.__div = function(m1, m2)
+ if getmetatable(m1) ~= matrix_meta then
+ return matrix.mulnum(matrix.invert(m2), m1)
+ elseif getmetatable(m2) ~= matrix_meta then
+ return matrix.divnum(m1, m2)
+ end
+ return matrix.div(m1, m2)
+end
+
+matrix_meta.__unm = function(mtx)
+ return matrix.mulnum(mtx, -1)
+end
+
+local option = {
+ ["*"] = function(m1)
+ return matrix.conjugate(m1)
+ end,
+ ["T"] = function(m1)
+ return matrix.transpose(m1)
+ end
+}
+matrix_meta.__pow = function(m1, opt)
+ return option[opt] and option[opt](m1) or matrix.pow(m1, opt)
+end
+
+-- vector part
+
+vectors = {}
+
+vector = {} --module
+
+local vector_meta = {}
+
+function vector.new(vector, rows, columns, n)
+ if columns ~= "e" then
+ local tbl = {}
+ for i = 1, #rows do
+ tbl[i] = rows[i]
+ end
+ return setmetatable(tbl, vector_meta)
+ end
+ local vec = {}
+ if columns == "e" then
+ for i = 1, rows do
+ if i == n then
+ vec[i] = 1
+ else
+ vec[i] = 0
+ end
+ end
+ return setmetatable(vec, vector_meta)
+ end
+end
+
+setmetatable(
+ vector,
+ {__call = function(...)
+ return vector.new(...)
+ end}
+)
+
+function vector.add(v1, v2)
+ if #v1 ~= #v2 then
+ return error("Vectors should be of same dimension.")
+ end
+ local vec = {}
+ for i = 1, #v1 do
+ vec[i] = v1[i] + v2[i]
+ end
+ return setmetatable(vec, vector_meta)
+end
+
+function vector.sub(v1, v2)
+ if #v1 ~= #v2 then
+ return error("Vectors should be of same dimension.")
+ end
+ local vec = {}
+ for i = 1, #v1 do
+ vec[i] = v1[i] - v2[i]
+ end
+ return setmetatable(vec, vector_meta)
+end
+
+function vector.dot(v1, v2)
+ if #v1 ~= #v2 then
+ return error("Vectors should be of same dimension")
+ end
+ local sum = 0
+ for i = 1, #v1 do
+ sum = sum + v1[i] * complex.conjugate(complex(v2[i]))
+ end
+ return sum
+end
+
+function vector.mulnum(v1, num)
+ local vec = {}
+ -- multiply elements with number
+ for i = 1, #v1 do
+ vec[i] = v1[i] * num
+ end
+ return setmetatable(vec, vector_meta)
+end
+
+function vector.sumnorm(v1)
+ local norm = 0
+ for i = 1, #v1 do
+ norm = norm + complex.abs(complex(v1[i]))
+ end
+ return norm
+end
+
+function vector.euclidnorm(v1)
+ return complex.sqrt(vector.dot(v1, v1))
+end
+
+function vector.pnorm(v1, p)
+ if math.floor(p) ~= math.abs(p) or p <= 1 then
+ return error("Invalid value of p")
+ end
+ local sum = 0
+ for i = 1, #v1 do
+ sum = sum + complex.abs(complex(v1[i])) ^ p
+ end
+ return sum ^ (1 / p)
+end
+
+function vector.supnorm(v1)
+ local result = 0
+ for i = 1, #v1 do
+ local e = complex.abs(complex(v1[i]))
+ if e > result then
+ result = e
+ end
+ end
+ return result
+end
+
+function vector.cross(v1, v2)
+ if #v1 ~= 3 or #v2 ~= 3 then
+ return error("Vectors should be of dimension 3")
+ end
+ local vec = {}
+ vec[1] = v1[2] * v2[3] - v1[3] * v2[2]
+ vec[2] = v1[3] * v2[1] - v1[1] * v2[3]
+ vec[3] = v1[1] * v2[2] - v1[2] * v2[1]
+ return setmetatable(vec, vector_meta)
+end
+
+function vector.createrandom(n, start, stop)
+ start = start or 0
+ stop = stop or 10
+ vec = {}
+ for i = 1, n do
+ vec[i] = math.random(start, stop)
+ vec[i] = vec[i] + math.min(math.random(), math.abs(vec[i] - start), math.abs(stop - vec[i]))
+ end
+ return setmetatable(vec, vector_meta)
+end
+
+function vector.getcoordinate(vec, i)
+ if vec[i] then
+ return vec[i]
+ end
+end
+
+function vector.setcoordinate(vec, i, val)
+ if vec[i] then
+ vec[i] = val
+ return val
+ end
+end
+
+function vector.getangle(v1, v2)
+ if #v1 ~= #v2 then
+ return error("Vectors should be of same dimension")
+ end
+ local x = complex.get(vector.dot(v1, v2) / (vector.euclidnorm(v1) * vector.euclidnorm(v2)))
+ return math.acos(mathround(x, 15))
+end
+
+function vector.copy(v1)
+ local vec = {}
+ for i = 1, #v1 do
+ vec[i] = v1[i]
+ end
+ return setmetatable(vec, vector_meta)
+end
+
+function vector.op(exp)
+ return load("return " .. exp, exp, "t", vectors)()
+end
+
+function vector.process(v1)
+ --v1=load("return "..v1)()
+ return vector.mulnum(v1, 1.0)
+end
+
+function vector.show(vec, dig)
+ vec = vector.process(vec)
+ local dig = dig or 6
+ local str = ""
+ for i = 1, #vec do
+ if i == 1 then
+ str = str .. complex.round(complex(vec[i]), dig)
+ else
+ str = str .. "," .. complex.round(complex(vec[i]), dig)
+ end
+ end
+ return str .. ""
+end
+
+function vector.parse(vec)
+ local tbl = {}
+ for i = 1, #vec do
+ tbl[i] = vec[i]
+ end
+ return "(" .. table.concat(tbl, ",") .. ")"
+end
+
+function vector.gs(inptTbl, brckt, dignum)
+ local brcktR = ""
+ brckt = brckt or "round"
+ if brckt == "round" then
+ brcktL = "("
+ brcktR = ")"
+ end
+ if brckt == "square" then
+ brcktL = "["
+ brcktR = "]"
+ end
+ if brckt == "curly" then
+ brcktL = "\\{"
+ brcktR = "\\}"
+ end
+
+ local tbl = {}
+ local str = ""
+ k = #inptTbl
+
+ if vector.euclidnorm(inptTbl[1]) ~= complex(0.0) then
+ tbl[1] = vector.mulnum(inptTbl[1], 1 / vector.euclidnorm(inptTbl[1]))
+ else
+ tbl[1] = vector.mulnum(inptTbl[1], 1.0)
+ end
+ setmetatable(tbl[1], vector_meta)
+ str = str .. "$\\left" .. brcktL .. vector.show(tbl[1], dignum) .. "\\right" .. brcktR
+ for i = 2, k do
+ tbl[i] = inptTbl[i]
+ setmetatable(tbl[i], vector_meta)
+ for j = 1, i - 1 do
+ setmetatable(tbl[j], vector_meta)
+ tbl[i] = vector.sub(tbl[i], vector.mulnum(tbl[j], vector.dot(tbl[i], tbl[j])))
+ end
+ if vector.euclidnorm(tbl[i]) ~= complex(0.0) then
+ tbl[i] = vector.mulnum(tbl[i], 1 / vector.euclidnorm(tbl[i]))
+ end
+ tbl[i] = vector.mulnum(tbl[i], 1.0)
+ str = str .. ",\\left" .. brcktL .. vector.show(tbl[i], dignum) .. "\\right" .. brcktR
+ end
+ str = str .. "$"
+ return str
+end
+
+function vector.gsX(inptTbl, brckt, dignum)
+ local brcktR = ""
+ local cnt = 1
+ brckt = brckt or "round"
+ if brckt == "round" then
+ brcktL = "\\left("
+ brcktR = "\\right)$$"
+ end
+ if brckt == "square" then
+ brcktL = "\\left["
+ brcktR = "\\right]$$"
+ end
+ if brckt == "curly" then
+ brcktL = "\\left\\{"
+ brcktR = "\\right\\}$$"
+ end
+
+ local tbl = {}
+ local tmpTbl = {}
+ local str = ""
+ k = #inptTbl
+ str = str .. "\\ \\newline Take given vectors as $v_1,\\ldots, v_" .. k .. "$ in order."
+
+ if vector.euclidnorm(inptTbl[1]) ~= complex(0.0) then
+ tbl[1] = vector.mulnum(inptTbl[1], 1 / vector.euclidnorm(inptTbl[1]))
+ else
+ tbl[1] = vector.mulnum(inptTbl[1], 1.0)
+ end
+ setmetatable(tbl[1], vector_meta)
+ str = str .. "\\ \\newline Step " .. cnt .. ": $$ u_" .. cnt .. "=v_" .. cnt .. "="
+ str = str .. brcktL .. vector.show(inptTbl[1], dignum) .. brcktR
+ str = str .. " $$ e_" .. cnt .. "="
+ if vector.euclidnorm(tbl[1]) ~= complex(0.0) then
+ str = str .. "\\frac{u_{" .. cnt .. "}}" .. "{||u_{" .. cnt .. "}||} ="
+ end
+ str = str .. brcktL .. vector.show(tbl[1], dignum) .. brcktR
+ for i = 2, k do
+ tbl[i] = inptTbl[i]
+ setmetatable(tbl[i], vector_meta)
+ for j = 1, i - 1 do
+ setmetatable(tbl[j], vector_meta)
+ tmpTbl[i] = vector.sub(tbl[i], vector.mulnum(tbl[j], vector.dot(tbl[i], tbl[j])))
+ tbl[i] = vector.sub(tbl[i], vector.mulnum(tbl[j], vector.dot(tbl[i], tbl[j])))
+ end
+ if vector.euclidnorm(tbl[i]) ~= complex(0.0) then
+ tbl[i] = vector.mulnum(tbl[i], 1 / vector.euclidnorm(tbl[i]))
+ else
+ tbl[i] = vector.mulnum(tbl[i], 1.0)
+ end
+
+ cnt = cnt + 1
+ str = str .. " Step " .. cnt
+ str = str .. ": $$ u_" .. cnt .. "="
+ str = str .. "v_" .. cnt .. "-\\sum_{j=1}^{" .. (cnt - 1) .. "}{{proj_{u_j}(v_" .. cnt .. ")}}="
+ str = str .. brcktL .. vector.show(tmpTbl[i], dignum) .. brcktR
+ str = str .. " $$ e_" .. cnt .. "="
+ if vector.euclidnorm(tbl[i]) ~= complex(0.0) then
+ str = str .. "\\frac{u_{" .. cnt .. "}}" .. "{||u_{" .. cnt .. "}||} ="
+ end
+ str = str .. brcktL .. vector.show(tbl[i], dignum) .. brcktR
+ end
+
+ return str
+end
+
+vector_meta.__tostring = function(...)
+ return vector.show(...)
+end
+
+vector_meta.__add = function(...)
+ return vector.add(...)
+end
+
+vector_meta.__sub = function(...)
+ return vector.sub(...)
+end
+
+vector_meta.__unm = function(vec)
+ return vector.mulnum(vec, -1)
+end
+
+vector_meta.__mul = function(v1, v2)
+ if getmetatable(v1) ~= vector_meta then
+ return vector.mulnum(v2, v1)
+ elseif getmetatable(v2) ~= vector_meta then
+ return vector.mulnum(v1, v2)
+ end
+ return vector.dot(v1, v2)
+end
+
+function mathround(num, numDecimalPlaces)
+ local mult = 10 ^ (numDecimalPlaces or 0)
+ return math.floor(num * mult + 0.5) / mult
+end
+
+
+\end{luacode*}
+
+% matrix latex commands
+
+\newcommand\matrixNew[2]{%
+ \directlua{%
+ matrices['#1'] = matrix(#2)
+ }%
+}
+
+% ========= KEY DEFINITIONS =========
+\define@key{matrixop}{type}{\def\mop@type{#1}}
+\define@key{matrixop}{truncate}{\def\mop@truncate{#1}}
+
+% ========= KEY DEFAULTS =========
+\setkeys{matrixop}{type=bmatrix,truncate=6}%
+
+\newcommand{\matrixPrint}[2][]{%
+ \begingroup%
+ \setkeys{matrixop}{#1}
+ \directlua{tex.sprint(matrix.show(matrices['#2'],"\mop@type",\mop@truncate))}
+ %
+ \endgroup%
+}
+
+\newcommand\matrixOp[2]{%
+ \directlua{%
+ matrices['#1'] = matrix.op('#2')
+ }%
+}
+
+
+\newcommand\matrixAdd[3]{%
+ \directlua{%
+ matrices['#1'] = matrix.add(matrices['#2'],matrices['#3'])
+ }%
+}
+
+\newcommand\matrixSub[3]{%
+ \directlua{%
+ matrices['#1'] = matrix.sub(matrices['#2'],matrices['#3'])
+ }%
+}
+
+\newcommand\matrixMulNum[3]{%
+ \directlua{%
+ matrices['#1'] = matrix.mulnum(matrices['#3'],#2)
+ }%
+}
+
+\newcommand\matrixMul[3]{%
+ \directlua{%
+ matrices['#1'] = matrix.mul(matrices['#2'],matrices['#3'])
+ }%
+}
+
+\newcommand\matrixSwapRows[4]{%
+ \directlua{%
+ matrices['#1'] = matrix.swapRows(matrices['#2'],#3,#4)
+ }%
+}
+
+\newcommand\matrixSwapCols[4]{%
+ \directlua{%
+ matrices['#1'] = matrix.swapCols(matrices['#2'],#3,#4)
+ }%
+}
+
+\newcommand\matrixMulRow[4]{%
+ \directlua{%
+ matrices['#1'] = matrix.mulRow(matrices['#2'],#3,#4)
+ }%
+}
+
+\newcommand\matrixMulCol[4]{%
+ \directlua{%
+ matrices['#1'] = matrix.mulCol(matrices['#2'],#3,#4)
+ }%
+}
+
+\newcommand\matrixMulAddRow[5]{%
+ \directlua{%
+ matrices['#1'] = matrix.mulAddRow(matrices['#2'],#4,#3,#5)
+ }%
+}
+
+\newcommand\matrixMulAddCol[5]{%
+ \directlua{%
+ matrices['#1'] = matrix.mulAddCol(matrices['#2'],#4,#3,#5)
+ }%
+}
+
+\newcommand\matrixTranspose[2]{%
+ \directlua{%
+ matrices['#1'] = matrix.transpose(matrices['#2'])
+ }%
+}
+
+\newcommand\matrixSubmatrix[6]{%
+ \directlua{%
+ matrices['#1'] = matrix.subm(matrices['#2'],#3,#4,#5,#6)
+ }%
+}
+
+\newcommand\matrixConcatH[3]{%
+ \directlua{%
+ matrices['#1'] = matrix.concath(matrices['#2'],matrices['#3'])
+ }%
+}
+
+\newcommand\matrixConcatV[3]{%
+ \directlua{%
+ matrices['#1'] = matrix.concatv(matrices['#2'],matrices['#3'])
+ }%
+}
+
+\newcommand\matrixNumRows[1]{%
+ \directlua{%
+ tex.sprint(tostring(matrix.rows(matrices['#1'])))
+ }%
+}
+
+\newcommand\matrixNumCols[1]{%
+ \directlua{%
+ tex.sprint(tostring(matrix.columns(matrices['#1'])))
+ }%
+}
+
+\newcommand\matrixGetElement[3]{%
+ \directlua{%
+ tex.sprint(tostring(matrix.getelement(matrices['#1'],#2,#3)))
+ }%
+}
+
+\newcommand\matrixSetElement[4]{%
+ \directlua{%
+ matrix.setelement(matrices['#1'],#2,#3,#4)
+ }%
+}
+
+\newcommand\matrixInvert[2]{%
+ \directlua{%
+ matrices['#1'] = matrix.invert(matrices['#2'])
+ }%
+}
+
+\newcommand\matrixPow[3]{%
+ \directlua{%
+ matrices['#1'] = matrix.pow(matrices['#2'],#3)
+ }%
+}
+
+\newcommand\matrixCreateRandom[5]{%
+ \directlua{%
+ matrices['#1'] = matrix.createrandom(#2,#3,#4,#5)
+ }%
+}
+
+\newcommand\matrixDet[1]{%
+ \directlua{%
+ tex.sprint(tostring(matrix.det(matrices['#1'])))
+ }%
+}
+
+\newcommand\matrixTrace[1]{%
+ \directlua{%
+ tex.sprint(tostring(matrix.trace(matrices['#1'])))
+ }%
+}
+
+\newcommand\matrixNormOne[1]{%
+ \directlua{%
+ tex.sprint(tostring(matrix.norm1(matrices['#1'])))
+ }%
+}
+
+\newcommand\matrixNormInfty[1]{%
+ \directlua{%
+ tex.sprint(tostring(matrix.norminfty(matrices['#1'])))
+ }%
+}
+
+\newcommand\matrixNormMax[1]{%
+ \directlua{%
+ tex.sprint(tostring(matrix.normmax(matrices['#1'])))
+ }%
+}
+
+\newcommand\matrixNormF[1]{%
+ \directlua{%
+ tex.sprint(tostring(matrix.normF(matrices['#1'])))
+ }%
+}
+
+\newcommand\matrixCopy[2]{%
+ \directlua{%
+ matrices['#1'] = matrix.copy(matrices['#2'])
+ }%
+}
+
+\newcommand\matrixRREF[2]{%
+ \directlua{%
+ matrices['#1'] = matrix.rref(matrices['#2'])
+ }%
+}
+
+\newcommand\matrixConjugate[2]{%
+ \directlua{%
+ matrices['#1'] = matrix.conjugate(matrices['#2'])
+ }%
+}
+
+\newcommand\matrixConjugateT[2]{%
+ \directlua{%
+ matrices['#1'] = matrix.conjugateT(matrices['#2'])
+ }%
+}
+
+\newcommand\matrixRank[1]{%
+ \directlua{%
+ tex.sprint(tostring(matrix.rank(matrices['#1'])))
+ }%
+}
+
+\newcommand\matrixRREFERR[1]{%
+ \directlua{%
+ tex.sprint(tostring(matrix.rref0E(matrices['#1'])))
+ }%
+}
+
+\newcommand\matrixRREFE[1]{%
+ \directlua{%
+ tex.sprint(tostring(matrix.rref0E(matrices['#1'])))
+ }%
+}
+
+% ========= KEY DEFINITIONS =========
+\define@key{matrixrr}{type}{\def\moprr@type{#1}}
+\define@key{matrixrr}{truncate}{\def\moprr@truncate{#1}}
+
+% ========= KEY DEFAULTS =========
+\setkeys{matrixrr}{type=bmatrix,truncate=6}%
+
+\newcommand{\matrixRREFSteps}[2][]{%
+ \begingroup%
+ \setkeys{matrixrr}{#1}
+ \directlua{%
+ tex.sprint(matrix.rref0E(matrices['#2'],"\moprr@type",\moprr@truncate))}
+ %
+ \endgroup%
+}
+
+\newcommand\matrixGaussJordan[3]{%
+ \directlua{%
+ matrices['#1'] = matrix.GaussJordan(matrices['#2'],matrices['#3'])
+ }%
+}
+
+\newcommand{\matrixGaussJordanSteps}[3][]{%
+ \begingroup%
+ \setkeys{matrixrr}{#1}
+ \directlua{%
+ tex.sprint(matrix.gauss0E(matrices['#2'],matrices['#3'],"\moprr@type",\moprr@truncate))}
+ %
+ \endgroup%
+}
+
+% vector latex commands
+
+\newcommand\vectorNew[2]{%
+ \directlua{%
+ vectors['#1'] = vector(#2)
+ }%
+}
+
+% ========= KEY DEFINITIONS =========
+\define@key{vectorop}{truncate}{\def\vop@truncate{#1}}
+
+% ========= KEY DEFAULTS =========
+\setkeys{vectorop}{truncate=6}%
+
+\newcommand{\vectorPrint}[2][]{%
+ \begingroup%
+ \setkeys{vectorop}{#1}
+ \directlua{tex.sprint(vector.show(vectors['#2'],\vop@truncate))}
+ %
+ \endgroup%
+}
+
+\newcommand\vectorParse[1]{%
+ \directlua{%
+ tex.sprint(tostring(vector.parse(vectors['#1'])))
+ }%
+}
+
+\newcommand\vectorOp[2]{%
+ \directlua{%
+ vectors['#1'] = vector.op('#2')
+ }%
+}
+
+\newcommand\vectorAdd[3]{%
+ \directlua{%
+ vectors['#1'] = vector.add(vectors['#2'],vectors['#3'])
+ }%
+}
+
+\newcommand\vectorSub[3]{%
+ \directlua{%
+ vectors['#1'] = vector.sub(vectors['#2'],vectors['#3'])
+ }%
+}
+
+\newcommand\vectorDot[2]{%
+ \directlua{%
+ tex.sprint(tostring(vector.dot(vectors['#1'],vectors['#2'])))
+ }%
+}
+
+\newcommand\vectorMulNum[3]{%
+ \directlua{%
+ vectors['#1'] = vector.mulnum(vectors['#2'],#3)
+ }%
+}
+
+\newcommand\vectorCross[3]{%
+ \directlua{%
+ vectors['#1'] = vector.cross(vectors['#2'],vectors['#3'])
+ }%
+}
+
+\newcommand\vectorSumNorm[1]{%
+ \directlua{%
+ tex.sprint(tostring(vector.sumnorm(vectors['#1'])))
+ }%
+}
+
+\newcommand\vectorEuclidNorm[1]{%
+ \directlua{%
+ tex.sprint(tostring(vector.euclidnorm(vectors['#1'])))
+ }%
+}
+
+\newcommand\vectorSupNorm[1]{%
+ \directlua{%
+ tex.sprint(tostring(vector.supnorm(vectors['#1'])))
+ }%
+}
+
+\newcommand\vectorpNorm[2]{%
+ \directlua{%
+ tex.sprint(tostring(vector.pnorm(vectors['#1'],#2)))
+ }%
+}
+
+\newcommand\vectorCreateRandom[4]{%
+ \directlua{%
+ vectors['#1'] = vector.createrandom(#2,#3,#4)
+ }%
+}
+
+\newcommand\vectorCopy[2]{%
+ \directlua{%
+ vectors['#1'] = vector.copy(vectors['#2'])
+ }%
+}
+
+\newcommand\vectorGetCoordinate[2]{%
+ \directlua{%
+ tex.sprint(tostring(vector.getcoordinate(vectors['#1'],#2)))
+ }%
+}
+
+\newcommand\vectorSetCoordinate[3]{%
+ \directlua{%
+ tex.sprint(tostring(vector.setcoordinate(vectors['#1'],#2,#3)))
+ }%
+}
+
+\newcommand\vectorGetAngle[2]{%
+ \directlua{%
+ tex.sprint(tostring(vector.getangle(vectors['#1'],vectors['#2'])))
+ }%
+}
+
+\newcommand\complexRound[2]{%
+ \directlua{%
+ tex.sprint(tostring(complex.round(complex('#1'),#2)))
+ }%
+}
+
+% ========= KEY DEFINITIONS =========
+\define@key{vecrr}{brckt}{\def\voprr@brckt{#1}}
+\define@key{vecrr}{truncate}{\def\voprr@truncate{#1}}
+
+% ========= KEY DEFAULTS =========
+\setkeys{vecrr}{brckt=round,truncate=6}%
+\newcommand{\vectorGramSchmidt}[2][]{%
+ \begingroup%
+ \setkeys{vecrr}{#1}
+ \directlua{%
+ local tbl = #2
+ local outTbl={}
+ local sum = 0
+ for i=1,table.getn(tbl) do
+ outTbl[i] = vectors[tbl[i]]
+ end
+
+ tex.sprint(vector.gs(outTbl,"\voprr@brckt",\voprr@truncate))}
+ %
+ \endgroup%
+}
+
+\newcommand{\vectorGramSchmidtSteps}[2][]{%
+ \begingroup%
+ \setkeys{vecrr}{#1}
+ \directlua{%
+ local tbl = #2
+ local outTbl={}
+ local sum = 0
+ for i=1,table.getn(tbl) do
+ outTbl[i] = vectors[tbl[i]]
+ end
+ tex.sprint(vector.gsX(outTbl,"\voprr@brckt",\voprr@truncate))}
+ %
+ \endgroup%
+}
+
+\endinput
diff --git a/macros/luatex/latex/lualinalg/lualinalg.tex b/macros/luatex/latex/lualinalg/lualinalg.tex
new file mode 100644
index 0000000000..fa7c9fa4ea
--- /dev/null
+++ b/macros/luatex/latex/lualinalg/lualinalg.tex
@@ -0,0 +1,1084 @@
+\documentclass{article}
+\usepackage{listings,color,parskip,booktabs,longtable,array,
+hyperref,multirow,multicol,url,amsmath,amssymb,framed,graphicx}
+\usepackage[top=1.1in, bottom=1.1in, left=1in, right=1in]{geometry}
+\hypersetup{colorlinks,urlcolor=blue}
+\lstset{frame=none,
+ language=[LaTeX]{TeX},
+ aboveskip=3mm,
+ belowskip=3mm,
+ showstringspaces=false,
+ columns=flexible,
+ basicstyle={\ttfamily},
+ numbers=none,
+ numberstyle=\tiny\color{gray},
+ stringstyle=\color{mauve},
+ breaklines=true,
+ breakatwhitespace=true,
+ tabsize=1,
+ upquote=true
+}
+\begin{document}
+\title{The lualinalg Package}
+\author{Chetan Shirore and Ajit Kumar}
+\maketitle
+
+\section{Introduction}
+
+The \verb|lualinalg| package is developed to perform operations on vectors and matrices defined over the field of real or complex numbers inside LaTeX documents. It provides flexible ways for defining and displaying vectors and matrices. No particular environment of LaTeX is required to use commands in the package. The package is written in Lua, and tex file is to be compiled with the LuaLaTeX engine. The time required for calculations is not an issue while compiling with LuaLaTeX. There is no need to install Lua on the user's system as TeX distributions (TeXLive or MikTeX) come bundled with LuaLaTeX. It may also save users' efforts to copy vectors and matrices from other software (which may not be in latex-compatible format) and to use them in a tex file. The vectors and matrices of reasonable size can be handled with ease. The package can be modified or extended by writing custom Lua programs (Section \ref{customuse}).
+
+\section{Installation and License}
+The installation of the \verb|lualinalg| package is similar to the plain latex package, where the \verb|.sty| file is in the LaTeX directory of the texmf tree. The package can be included with \verb|\usepackage{lualinalg}| command in the preamble of the LaTeX document.
+
+The \verb|lualinalg| package is released under the LaTeX Project Public License v1.3c or later. The complete license text is available at \url{http://www.latex-project.org/lppl.txt}. It is developed in Lua. Lua is available as a certified open-source software. Its license is simple and liberal, which is compatible with GPL. The package makes use of \verb|complex.lua| file which is available on \url{https://github.com/davidm/lua-matrix/blob/master/lua/matrix.lua}. It is available under the same licensing as that of Lua. The package also loads the \href{https://ctan.org/pkg/luamaths}{luamaths} package, which is available under the LaTeX Project Public License v1.3c or later. This package is loaded to use the standard mathematical functions and for computations on real numbers while performing operations on vectors and matrices.
+\section{Defining vectors and performing operations on vectors}
+\subsection{Defining Vectors} Vectors are defined with the \verb|\vectornew| command.
+\begin{verbatim}
+\vectorNew{vector name}{coordinates}
+\end{verbatim}
+ This command has two compulsory arguments: \verb|vector name| and \verb|coordinates|. Coordinates of vectors are enclosed in curly braces. A comma separates coordinates. The complex numbers are to be enclosed in single or double quotes inside the \verb|complex()| function. The following are a few valid ways of defining vectors.
+\begin{lstlisting}
+\vectorNew{v1}{{1,2,3,4,5,6}}
+\vectorNew{v2}{{3,6,complex('6+6i')}}
+\end{lstlisting}
+The standard vector of dimension \(n \) with \(i^{th}\) coordinate \(1\) can be produced by using the following command.
+\begin{lstlisting}
+\vectorNew{e}{n,'e',i}
+\end{lstlisting}
+For example, the following commands
+\begin{lstlisting}
+\vectorNew{e_1}{3,'e',1}
+\(e_1=\left(\vectorPrint{e}\right)\)
+\end{lstlisting}
+output to \(e_1 = \left(1.0,0.0,0.0\right) \).
+\subsection{Commands for operations on vectors}
+Table \ref{tbl:luavector} lists commands for operations on vectors.
+\begin{longtable}{m{7cm}m{7cm}}
+\toprule
+\multicolumn{1}{c}{\textcolor{blue}{Command Format}} & \multicolumn{1}{c}{\textcolor{blue}{Description}} \\
+\toprule
+\begin{lstlisting}
+\vectorPrint[truncate]{vector}
+\end{lstlisting} & Prints vector. Accepts one \emph{optional} argument: \verb|truncate|. It specifies the number of digits up to which vector coordinates must be truncated. The value of \verb|truncate| may be 0,1,2,\ldots\\
+\midrule
+\begin{lstlisting}
+\vectorGetCoordinate{vector}{i}
+\end{lstlisting}
+&
+Gives the \(i^{th}\) coordinate of vector. \\
+\midrule
+ \begin{lstlisting}
+\vectorSetCoordinate
+{vector}{i}{val}
+\end{lstlisting}
+&
+Sets the \(i^{th}\) coordinate of vector as \verb|val|. \\
+\midrule
+\begin{lstlisting}
+\vectorCopy{v}{w}
+\end{lstlisting}&
+Defines a new vector \(v\) obtained by copying coordinates of vector \(w\). \\
+\midrule
+\begin{lstlisting}
+\vectorAdd{vector}{v1}{v2}
+\end{lstlisting}&
+Defines a new vector as the addition of vectors \(v1\) and \(v2\). Both vectors \(v1\) and \(v2\) should be of the same dimension. The addition is done coordinate-wise.\\
+\midrule
+ \begin{lstlisting}
+\vectorSub{vector}{v1}{v2}
+\end{lstlisting}&
+Defines a new vector as the subtraction of vectors \(v1\) and \(v2\). Both vectors \(v1\) and \(v2\) should be of the same dimension. The subtraction is done coordinate-wise. \\
+\midrule
+ \begin{lstlisting}
+\vectorMulNum{vector}{v}{num}
+\end{lstlisting}&
+Defines a new vector obtained by multiplying each coordinate of a vector by number \verb|num|. It can be a real or complex number (scalar). \\
+\midrule
+\begin{lstlisting}
+\vectorDot{v}{w}
+\end{lstlisting}&
+Gives the dot product of two vectors: \(v\) and \(w\). If \(v=\left(v_1, \ldots, v_n \right)\) and \(w =\left(w_1, \ldots, w_n \right)\) are defined over the field of real numbers, then it is evaluated as \(v_1\cdot w_1 + \cdots + v_n \cdot w_n\). If they are defined over the field of complex numbers, then it is evaluated as \(v_1\cdot \bar{w_1} + \cdots + v_n \cdot \bar{w_n}\). \(\bar{w_i}\) denotes the complex conjugate of complex number \(w_i\). \\
+\midrule
+\begin{lstlisting}
+\vectorCross{vector}{v}{w}
+\end{lstlisting}&
+Defines a new vector obtained by taking the cross product of vectors \(v\) and \(w\) of dimension 3. If \(v=\left(v_1, v_2, v_3 \right)\) and \(w =\left(w_1, w_2, w_3 \right)\), then the cross product of these two vectors is the vector \((v_2w_3-v_3w_2, v_3w_1-v_1w_3,\) \( v_1w_2-v_2w_1 ) \). \\
+\midrule
+ \begin{lstlisting}
+\vectorSumNorm{v}
+\end{lstlisting}&
+Calculates the sum norm of a vector \(v\). If \(v=\left(v_1, \ldots, v_n \right)\) then it is given by \(|v_1| + \cdots + |v_n| \). \\
+\midrule
+ \begin{lstlisting}
+\vectorEuclidNorm{v}
+\end{lstlisting}&
+Calculates the Euclidean norm of a vector \(v\). If \(v=\left(v_1, \ldots, v_n \right)\) then it is given by \(\sqrt{|v_1|^2 + \cdots + |v_n|^2} \). \\
+\midrule
+ \begin{lstlisting}
+\vectorpNorm{v}
+\end{lstlisting}&
+Calculates the \(p\) \((p > 1)\) norm of a vector \(v\). If \(v=\left(v_1, \ldots, v_n \right)\) then it is given by \(\sqrt[p]{|v_1|^2 + \cdots + |v_n|^2} \). \\
+\midrule
+\begin{lstlisting}
+\vectorSupNorm{v}
+\end{lstlisting}&
+Calculates the sup norm of a vector \(v\). If \(v=\left(v_1, \ldots, v_n \right)\) then it is given by \(\max\{|v_1| , \ldots , |v_n| \} \). \\
+\midrule
+ \begin{lstlisting}
+\vectorCreateRandom{v}{n}{a}{b}
+\end{lstlisting}&
+Creates a new vector \(v\) of dimension \(n\) with coordinates as random numbers from the interval \([a,b]\). \\
+\midrule
+\begin{lstlisting}
+\vectorOp{vector}{expression}
+\end{lstlisting}&
+Defines a new vector obtained by evaluating an expression. The expression supports all standard operations such as \(+,-,* \). \\
+\midrule
+ \begin{lstlisting}
+ \vectorGetAngle{v}{w}
+\end{lstlisting}&
+Gives the angle between two vectors \(v\) and \(w\) in radians. If \(v\) and \(w \) are defined over the field of real numbers, then it is evaluated as \(\cos^{-1}\left(\frac{v \cdot w}{|v| |w|}\right)\). If they are defined over the field of complex numbers, then it is evaluated as \(\cos^{-1}\left(\frac{Re (v \cdot w) }{|v| |w|}\right)\). Here \(v \cdot w\) denotes the dot product of vectors \(v\) and \(w\), \(Re (v \cdot w)\) denotes real part of the dot product \(v \cdot w\), and \(|v|\) and \(|w|\) denote Euclidean norms of vectors \(v\) and \(w\) respectively. \\
+\midrule
+ \begin{lstlisting}
+\vectorParse{vector}
+\end{lstlisting}&
+Parses the coordinates of a vector defined over the field of real numbers. The command helps to plot vectors with different packages. \\
+\midrule
+\begin{lstlisting}
+\vectorGramSchmidt[brckt,
+truncate]{list of vectors}
+\end{lstlisting} & Performs Gram Schmidt orthogonalisation process on a list of vectors. Accepts two \emph{optional} arguments: \verb|brckt| and \verb|truncate|. The \verb|brckt| is type of parenthesis to be used for displaying vectors. It can be `round', `square' or `curly'. The truncate is number of digits up to which vector coordinates are to be truncated. The value of \verb|truncate| can be 0,1,2,\ldots\\
+\midrule
+\begin{lstlisting}
+\vectorGramSchmidtSteps[brckt,
+truncate]{list of vectors}
+\end{lstlisting} & Performs Gram Schmidt orthogonalisation process on a list of vectors in a step-by-step manner. Accepts two \emph{optional} arguments: \verb|brckt| and \verb|truncate|. The \verb|brckt| is type of parenthesis to be used for displaying vectors. It can be `round', `square' or `curly'. The truncate is number of digits up to which vector coordinates are to be truncated. The value of \verb|truncate| can be 0,1,2,\ldots\\
+\bottomrule \\
+\caption{Commands for operations on vectors}
+\label{tbl:luavector}
+\end{longtable}
+\subsection{Illustrations of commands for operations on vectors}
+The following commands define vectors \(v,w,x,\) and \(y\).
+\begin{lstlisting}
+\vectorNew{v}{{1,2,complex('3+3i')}}
+\vectorNew{w}{{3,6,complex('6+6i')}}
+\vectorNew{x}{{1.12345678,6,complex('6+6i')}}
+\vectorNew{y}{{1,2,3}}
+\end{lstlisting}
+Table \ref{tbl:illluavector} illustrates various operations on vectors \(v,w,x\) and \(y\).
+\begin{longtable}{lc}
+\toprule
+Commands & Output Produced\\
+\toprule
+\begin{lstlisting}
+\(v=\left(\vectorPrint{v}\right)\)
+\(w=\left(\vectorPrint{w}\right)\)
+\end{lstlisting} &
+\(v=\left(1.0,2.0,3.0+3.0i\right)\) \\
+&
+\(w=\left(3.0,6.0,6.0+6.0i\right)\)
+\\
+\midrule
+\begin{lstlisting}
+\(x=\left(\vectorPrint
+[truncate=3]{x}\right)\)
+\end{lstlisting} &
+\(x=\left(1.123,6.0,6.0+6.0i\right)\)
+\\
+\midrule
+\begin{lstlisting}
+third coordinate of vector
+\(v = \vectorGetCoordinate{v}{3}\)
+\end{lstlisting} &
+third coordinate of vector \(v = 3 + 3i\)
+\\
+\midrule
+\begin{lstlisting}
+\(y = \vectorCopy{y}{w}\)
+\(\left(\vectorPrint{y}\right)\)
+\end{lstlisting} &
+\(y = \left( 3.0,6.0,6.0+6.0i\right)\)
+\\
+\midrule
+\begin{lstlisting}
+new third coordinate of vector
+\(y = \vectorSetCoordinate{y}{3}{9.3}\)
+\(y=\left(\vectorPrint{y}\right)\)
+\end{lstlisting} &
+new third coordinate of vector \(y = 9.3\) \\
+& \(y = \left( 3.0,6.0,9.3\right)\)
+\\
+\midrule
+\begin{lstlisting}
+\vectorAdd{v1}{v}{w}
+\(v1 = v+w =\left(\vectorPrint{v1}\right)\)
+\end{lstlisting} &
+\(v1 = v+w =\left(4.0, 8.0, 9.0 + 9.0i\right)\)
+\\
+\midrule
+\begin{lstlisting}
+\vectorSub{v2}{v}{w}
+\(v2 = v-w =\left(\vectorPrint{v2}\right)\)
+\end{lstlisting} &
+\(v2 = v-w =\left(-2.0, -4.0, -3.0 -3.0i\right)\)
+\\
+\midrule
+\begin{lstlisting}
+\vectorMulNum{v3}{v}{complex('3+i')}
+\(v3 = 3v =\left(\vectorPrint{v3}\right)\)
+\end{lstlisting} &
+\(v3 = 3v =\left(3.0 + i, 6.0 + 2.0i, 6.0 + 12.0i\right)\)
+\\
+\midrule
+\begin{lstlisting}
+\vectorDot{v}{w}
+\(v \cdot w =\vectorDot{v}{w}\)
+\end{lstlisting} &
+\(v \cdot w = 51\)
+\\
+\midrule
+\begin{lstlisting}
+\vectorCross{v4}{v}{w}
+\(v \times w =\left(\vectorPrint{v4}\right)\)
+\end{lstlisting} &
+\(v \times w = \left(-6.0 - 6.0i, 3.0 + 3.0i, 0.0\right)\)
+\\
+\midrule
+\begin{lstlisting}
+ Sum norm of a vector \(v = \vectorSumNorm{v}\)
+\end{lstlisting} &
+ Sum norm of a vector \(v = 7.2426406871193\)
+\\
+\midrule
+\begin{lstlisting}
+Euclidean norm of a vector
+ \(v = \vectorEuclidNorm{v}\)
+\end{lstlisting} &
+Euclidean norm of a vector \(v = 4.7958315233127\)
+\\
+\midrule
+\begin{lstlisting}
+p norm of a vector \(v = \vectorpNorm{v}{3}\)
+\end{lstlisting} &
+p norm of a vector \(v = 4.4031577258332\)
+\\
+\midrule
+\begin{lstlisting}
+Sup norm of a vector \(v = \vectorSupNorm{v}\)
+\end{lstlisting} &
+Sup norm of a vector \(v = 4.2426406871193\)
+\\
+\midrule
+\begin{lstlisting}
+\vectorCreateRandom{v5}{3}{9}{90}
+\(v5 =\left(\vectorPrint{v5}\right)\)
+\end{lstlisting} &
+\(v5 =\left(18.290405, 23.356018, 49.966278\right)\)
+\\
+\midrule
+\begin{lstlisting}
+\vectorOp{v6}{v+w-2*v}
+\(v6 =\left(\vectorPrint{v7}\right)\)
+\end{lstlisting} &
+\(v6=\left(2.0, 4.0, 27.0 + 27.0i \right)\)
+\\
+\midrule
+\begin{lstlisting}
+ angle between vector \(v\) and \(w\) is
+ \( \vectorGetAngle{v}{w}\).
+\end{lstlisting} &
+angle between vector \(v\) and \(w\) is
+ \( 0.32823410158508\).
+\\
+\midrule
+\begin{lstlisting}
+\vectorParse{y}
+\end{lstlisting} &
+\(\left(1,2,3 \right)\)
+\\
+\bottomrule \\
+\caption{Illustration of commands for operations on vectors}
+\label{tbl:illluavector}
+\end{longtable}
+The package has commands for performing Gram Schmidt Orthogonalisation process. It can also produce the computations in a step-by step manner.
+\begin{framed}
+\begin{lstlisting}[label={code:luavecgs}, caption={Gram Schmidt Orthogonalisation process in the lualinalgpackage}]
+\vectorNew{v1}{{1,2,3}}
+\vectorNew{v2}{{4,5,6}}
+\vectorNew{v3}{{7,8,90}}
+\[v1=\left(\vectorPrint{v1}\right)\]
+\[v2=\left(\vectorPrint{v2}\right)\]
+\[v3=\left(\vectorPrint{v3}\right)\]
+Gram Schmidt on \(v1,v2,v3\): \vectorGramSchmidt[brckt=round,truncate=3]{{'v1','v2','v3'}}
+\vectorGramSchmidtSteps[brckt=round,truncate=3]{{'v1','v2','v3'}}
+\end{lstlisting}
+\end{framed}
+Listing \ref{code:luavecgs} outputs the following.
+\begin{framed}
+\[v1=\left(1,2,3\right)\]
+\[v2=\left(4,5,6\right)\]
+\[v3=\left(7,8,90\right)\]
+Gram Schmidt on \(v1,v2,v3\): $\left(0.267,0.535,0.802\right),\left(0.873,0.218,-0.436\right),\left(0.408,-0.816,0.408\right)$
+
+Take given vectors as $v_1,\ldots, v_3$ in order.\ \newline Step 1: $$ u_1=v_1=\left(1.0,2.0,3.0\right)$$ $$ e_1=\frac{u_{1}}{||u_{1}||} =\left(0.267,0.535,0.802\right)$$ Step 2: $$ u_2=v_2-\sum_{j=1}^{1}{{proj_{u_j}(v_2)}}=\left(1.714,0.429,-0.857\right)$$ $$ e_2=\frac{u_{2}}{||u_{2}||} =\left(0.873,0.218,-0.436\right)$$ Step 3: $$ u_3=v_3-\sum_{j=1}^{2}{{proj_{u_j}(v_3)}}=\left(13.5,-27.0,13.5\right)$$ $$ e_3=\frac{u_{3}}{||u_{3}||} =\left(0.408,-0.816,0.408\right)$$
+\end{framed}
+
+In addition to \verb|\mathRound|, the command \verb|complexRound| is also available. It has the following syntax.
+\begin{verbatim}
+\complexRound{complex number}{number of decimal places}
+\end{verbatim}
+
+This command has two compulsory arguments. The complex number and number of decimal places to which number should be rounded off. For example,
+ \verb| \complexRound{3.3333666+6.777666i}{3}| outputs to \(3.333+6.778i\). This command can be nested with other commands in the package.
+
+\subsection{Plotting vectors}
+The \verb|lualinalg| package can be used with other packages that have facility to plot vectors defined over the field of real numbers in 2 or 3 dimensions. Listing \ref{code:luavecplot} illustrates plotting of vectors in 2-D plane by using \verb|lualinalg| and \verb|tikz| package.
+\begin{lstlisting}[label={code:luavecplot}, caption={Plotting vectors in 2-dimensions with the lualinalg and tikz packages}]
+\begin{document}
+\tdplotsetmaincoords{0}{0}
+\begin{tikzpicture}[scale=1,
+ tdplot_main_coords,
+ axis/.style={->,blue,thick},
+ vector/.style={-stealth,red,very thick},
+ vector guide/.style={dashed,red,thick}]
+\vectorNew{o}{{0,0}}
+\vectorNew{e1}{{4,0}}
+\vectorNew{e2}{{0,4}}
+\vectorNew{f}{{2,1}}
+\vectorNew{g}{{1,2}}
+% Axes
+\draw [axis] \vectorParse{o}-- \vectorParse{e1} node [below left] {$x$};
+\draw [axis] \vectorParse{o}-- \vectorParse{e2} node [right] {$y$};
+% Plotting Vectors
+\draw [vector] \vectorParse{o} --\vectorParse{f};
+\draw [vector] \vectorParse{o} --\vectorParse{g};
+\vectorOp{h}{f+g}
+\draw [vector] \vectorParse{o} --\vectorParse{h};
+\draw [vector,dashed,black] \vectorParse{f} --\vectorParse{h};
+\draw [vector,dashed,black] \vectorParse{g} --\vectorParse{h};
+% Labels
+ \node [below right] at \vectorParse{f} {$f$};
+ \node [above left] at \vectorParse{g} {$g$};
+\node [above left] at \vectorParse{h} {$f+g$};
+ \draw[vector guide, black] \vectorParse{h} -- (\vectorGetCoordinate{h}{1},0) node [below] {$x=\vectorGetCoordinate{h}{1}$};
+ \draw[vector guide, black] \vectorParse{h} -- (0,\vectorGetCoordinate{h}{2}) node [left] {$y=\vectorGetCoordinate{h}{2}$};
+\end{tikzpicture}
+\end{document}
+\end{lstlisting}
+Listing \ref{code:luavecplot} produces figure \ref{fig:2dvecplot}.
+\begin{figure}[!ht] % or [H] to turn off float
+ \centering
+ \includegraphics[scale=0.9]{2dvec.jpg}
+ \caption{Plotting of 3-D Vectors with lualinalg and tikz packages}
+ \label{fig:2dvecplot}
+\end{figure}
+Listing \ref{code:luavecplot2} illustrates plotting of vectors in 3-D plane by using \verb|lualinalg| and \verb|tikz| package.
+\begin{lstlisting}[label={code:luavecplot2}, caption={Plotting vectors in 3-dimensions with the lualinalg and tikz packages}]
+\documentclass{article}
+\usepackage{tikz,tikz-3dplot,lualinalg}
+\begin{document}
+\tdplotsetmaincoords{60}{120}
+\begin{tikzpicture}[scale=1,
+ tdplot_main_coords,
+ axis/.style={->,blue,thick},
+ vector/.style={-stealth,red,very thick},
+ vector guide/.style={dashed,red,thick}]
+\vectorNew{o}{{0,0,0}}
+\vectorNew{e1}{{3,0,0}}
+\vectorNew{e2}{{0,5,0}}
+\vectorNew{e3}{{0,0,4}}
+\vectorNew{f}{{2,2,0}}
+\vectorNew{g}{{-1,2,2}}
+% Axes
+\draw [axis] \vectorParse{o}-- \vectorParse{e1} node [below left] {$x$};
+\draw [axis] \vectorParse{o}-- \vectorParse{e2} node [right] {$y$};
+\draw [axis] \vectorParse{o}-- \vectorParse{e3} node [above] {$z$};
+% Plotting Vectors
+\draw [vector] \vectorParse{o} --\vectorParse{f};
+\draw [vector] \vectorParse{o} --\vectorParse{g};
+\vectorOp{h}{f+g}
+\draw [vector] \vectorParse{o} --\vectorParse{h};
+% Labels
+ \node [below right] at \vectorParse{f} {$f$};
+ \node [above left] at \vectorParse{g} {$g$};
+\node [right] at \vectorParse{h} {$f+g$};
+ \draw[vector guide, black] \vectorParse{h} -- (\vectorGetCoordinate{h}{1},0,0) node [left] {$x=\vectorGetCoordinate{h}{1}$};
+ \draw[vector guide, black] \vectorParse{h} -- (0,\vectorGetCoordinate{h}{2},0) node [below] {$y=\vectorGetCoordinate{h}{2}$};
+ \draw[vector guide, black] \vectorParse{h} -- (0,0,\vectorGetCoordinate{h}{3}) node [left] {$z=\vectorGetCoordinate{h}{3}$};
+\end{tikzpicture}
+\end{document}
+\end{lstlisting}
+
+Listing \ref{code:luavecplot2} produces figure \ref{fig:3dvecplot}.
+\begin{figure}[!ht] % or [H] to turn off float
+ \centering
+ \includegraphics[scale=0.9]{3dvec.jpg}
+ \caption{Plotting of Vectors with lualinalg and tikz packages}
+ \label{fig:3dvecplot}
+\end{figure}
+
+\section{Defining matrices and operations on matrices}
+Matrices are defined with the \verb|\matrixNew| command.
+\begin{lstlisting}
+\matrixNew{matrix name}{row entries}
+\end{lstlisting}
+This command has two compulsory arguments: \verb|matrix name| and \verb|row entries|. Each row of the matrix is enclosed in curly brackets. A comma separates numbers in rows. Rows are also separated by a comma. The whole matrix is then enclosed in curly brackets. The complex numbers are to be enclosed in single or double quotes inside the parenthesis of the \verb|complex()| function. The following are a few valid ways of defining matrices.
+
+\begin{lstlisting}
+\def\n{{{1,2,3},{4,5,6},{7,8,complex('9+3i')}}}
+\def\s{{{1,2,3},{4,5,6},{7,8,10}}}
+\matrixNew{m}{\n}
+\matrixNew{n}{\s}
+% an alternative way
+\matrixNew{m}{{{1,2,3},{4,5,6},{7,8,complex('9+3i')}}}
+\matrixNew{n}{{{1,2,3},{4,5,6},{7,8,10}}}
+\end{lstlisting}
+
+The identity matrix can be defined as well by using the \verb|\matrixNew| command. For example, the following commands
+\begin{lstlisting}
+\matrixNew{mtx}{3,'I'}
+I = \(\matrixPrint{mtx}\)
+\end{lstlisting}
+output to
+\[I = \begin{bmatrix} 1.0 & 0.0 & 0.0 \\ 0.0 & 1.0 & 0.0 \\ 0.0 & 0.0 & 1.0\\\end{bmatrix} \]
+
+\subsection{Commands for operations on matrices}
+Table \ref{tbl:luamtxcmd} lists all commands for operations on matrices in the \verb|lualinalg| package.
+\begin{longtable}{m{7cm}m{7cm}}
+\toprule
+ \multicolumn{1}{c}{\textcolor{blue}{Command Format}} & \multicolumn{1}{c}{\textcolor{blue}{Description}} \\
+\toprule
+\multicolumn{2}{c}{Printing Matrices}\\
+\midrule
+\begin{lstlisting}
+\matrixPrint[type,truncate]{mtx}
+\end{lstlisting} & Prints matrix. Accepts two \emph{optional} arguments: \verb|type| and \verb|truncate|. The \verb|type| may be one of the values \verb|pmatrix,bmatrix, vmatrix,Vmatrix|.
+The default type is \verb|bmatrix|. The \verb|truncate| specifies the number of digits up to which matrix entries are to be truncated. The value of \verb|truncate| may be 0,1,2,\ldots.\\
+\midrule
+\multicolumn{2}{c}{Some parameters of defined matrices} \\
+\midrule
+\begin{lstlisting}
+\matrixNumRows{matrix}
+\end{lstlisting} &
+Gives the number of rows in a matrix.\\
+\midrule
+\begin{lstlisting}
+\matrixNumCols{matrix}
+\end{lstlisting}&
+Gives the number of columns in a matrix.\\
+\midrule
+\begin{lstlisting}
+\matrixGetElement{matrix}{i}{j}
+\end{lstlisting}
+&
+Gives an entry of matrix in the \(i^{th} \) row and the \(j^{th} \) column. \\
+\midrule
+\multicolumn{2}{c}{Algebraic operations on matrices} \\
+\midrule
+ \begin{lstlisting}
+\matrixAdd{matrix}{m1}{m2}
+\end{lstlisting}&
+Defines a new matrix as the addition of matrices m1 and m2. The second matrix may have more rows and\textbackslash or columns.\\
+\midrule
+ \begin{lstlisting}
+\matrixSub{matrix}{m1}{m2}
+\end{lstlisting}&
+Defines a new matrix as the subtraction of matrices m1 and m2. The second matrix may have more rows and\textbackslash or columns.\\
+\midrule
+ \begin{lstlisting}
+\matrixMulNum{matrix}{number}{m1}
+\end{lstlisting}&
+Defines a new matrix obtained by multiplying each entry of matrix m1 by s real or complex number. \\
+\midrule
+\begin{lstlisting}
+\matrixMul{matrix}{m1}{m2}
+\end{lstlisting}&
+Defines a new matrix obtained by multiplying matrix m1 by matrix m2. The number of rows in matrix m2 must equal the number of columns in matrix m1.\\
+\midrule
+ \begin{lstlisting}
+\matrixPow{matrix}{m1}{power}
+\end{lstlisting}&
+Defines a new matrix obtained by taking the \(i^{th}\) power of matrix m11 (multiplying matrix1 \(i\) times with itself). \\
+\midrule
+ \begin{lstlisting}
+\matrixInvert{matrix}{matrix1}
+\end{lstlisting}&
+Defines a new matrix obtained by taking the inverse of matrix1. It throws an error if matrix is not invertible. \\
+\midrule
+\begin{lstlisting}
+\matrixTrace{matrix}
+\end{lstlisting}&
+Gives the trace (sum of diagonal entries) of a square matrix. It throws an error if the matrix is not square. \\
+\midrule
+
+\begin{lstlisting}
+\matrixConjugate{matrix}{m1}
+\end{lstlisting}&
+Defines a new matrix obtained by taking the complex conjugate of each entry of matrix m1. \\
+\midrule
+ \begin{lstlisting}
+\matrixConjugateT{matrix}{m1}
+\end{lstlisting}&
+Defines a new matrix obtained by taking the transpose of matrix m1 and then the complex conjugate of each matrix entry. \\
+\midrule
+\begin{lstlisting}
+\matrixNormOne{matrix}
+\end{lstlisting}&
+Calculates the norm1 of a matrix. For matrix \(A\) of size \(m \times n\), it is given by
+\[ \|A\|_{1}=\max _{1 \leqslant j \leqslant n} \sum_{i=1}^{m}\left|a_{i j}\right| \] \\
+\midrule
+\begin{lstlisting}
+\matrixNormInfty{matrix}
+\end{lstlisting}&
+Calculates the infinity norm of a matrix. For matrix \(A\) of size \(m \times n\), it is given by
+\[ \|A\|_{\infty}=\max _{1 \leqslant i \leqslant m} \sum_{j=1}^{n}\left|a_{i j}\right| \] \\
+\midrule
+\begin{lstlisting}
+\matrixNormMax{matrix}
+\end{lstlisting}&
+Calculates the max norm of a matrix. For matrix \(A\) of size \(m \times n\), it is given by
+\[ \|A\|_{\max }=\max _{i,j}\left|a_{i j}\right| \] \\
+\midrule
+ \begin{lstlisting}
+\matrixNormF{matrix}
+\end{lstlisting}&
+Calculates the Frobenius norm of a matrix. For matrix \(A\) of size \(m \times n\), it is given by
+\[\|A\|_{F}=\sqrt{\sum_{i=1}^{m} \sum_{j=1}^{n}\left|a_{i j}\right|^{2}} \] \\
+\midrule
+ \begin{lstlisting}
+\matrixRank{matrix}
+\end{lstlisting}&
+Gives the rank of matrix \(m\). It also supports matrices of complex numbers. \\
+\midrule
+ \begin{lstlisting}
+\matrixDet{matrix}
+\end{lstlisting}&
+Gives the determinant of matrix \(m\). It also supports matrices of complex numbers. \\
+\midrule
+ \begin{lstlisting}
+\matrixTranspose{matrix}{m1}
+\end{lstlisting}&
+Defines a new matrix obtained by taking the transpose of matrix m1. \\
+\midrule
+ \begin{lstlisting}
+\matrixSetElement{matrix}{i}{j}{val}
+\end{lstlisting}
+&
+Set entry of a matrix in the \(i^{th} \) row and \(j^{th} \) column as \verb|val|. \\
+\midrule
+ \begin{lstlisting}
+\matrixSubmatrix{sm}{m}{i}{j}{k}{l}
+\end{lstlisting}&
+Defines a new matrix sm obtained by taking a submatrix of matrix m. Here \(i,j\) denotes the start row and start column, and \(k,l\) denotes the end row and end column for obtaining the submatrix. \\
+\midrule
+ \begin{lstlisting}
+\matrixConcatH{matrix}{m1}{m2}
+\end{lstlisting}&
+Defines a new matrix obtained by augmenting matrix m1 with matrix m2 horizontally. \\
+\midrule
+ \begin{lstlisting}
+\matrixConcatV{matrix}{m1}{m2}
+\end{lstlisting}&
+Defines a new matrix obtained by augmenting matrix m1 with matrix m2 vertically. \\
+\midrule
+\begin{lstlisting}
+\matrixOp{matrix}{expression}
+\end{lstlisting}&
+Defines a new matrix obtained by evaluating an expression. The expression supports all standard operations such as \(+,*, \) \^ \ . \\
+\midrule
+\begin{lstlisting}
+\matrixCopy{matrix}{matrix1}
+\end{lstlisting}&
+Defines a new matrix obtained by copying values from matrix1. \\
+\midrule
+ \begin{lstlisting}
+\matrixCreateRandom
+{m}{i}{j}{k}{l}
+\end{lstlisting}&
+Creates a new matrix m with random numbers. Here \(i,j\) denotes the number of rows and columns, and \(k, l\) denotes the start and end integers between which random numbers are generated. \\
+\midrule
+\multicolumn{2}{c}{Elementary row operations on matrices} \\
+\midrule
+ \begin{lstlisting}
+\matrixSwapRows{mtx}{m1}{i}{j}
+\end{lstlisting}&
+Defines a new matrix mtx obtained by swapping the \(i^{th}\) and \(j^{th}\) rows of matrix m1. \\
+\midrule
+ \begin{lstlisting}
+\matrixMulRow{matrix}{m}{i}{no}
+\end{lstlisting}&
+Defines a new matrix obtained by multiplying the \(i^{th}\) row of matrix1 by a real or complex number. \\
+\midrule
+\begin{lstlisting}
+\matrixMulAddRow{mtx}{m}{i}{no}{j}
+\end{lstlisting}&
+Defines a new matrix mtx obtained by multiplying the \(i^{th}\) row of matrix1 by a real or complex number and adding it to the \(j^{th}\) row. \\
+\midrule
+\multicolumn{2}{c}{Elementary column operations on matrices} \\
+\midrule
+\begin{lstlisting}
+\matrixSwapCols{mtx}{m}{i}{j}
+\end{lstlisting}&
+Defines a new matrix mtx obtained by swapping the \(i^{th}\) and \(j^{th}\) columns of matrix m. \\
+\midrule
+\begin{lstlisting}
+\matrixMulCol{matrix}{m}{i}{no}
+\end{lstlisting}&
+Defines a new matrix obtained by multiplying the \(i^{th}\) column of matrix1 by a real or complex number. \\
+\midrule
+ \begin{lstlisting}
+\matrixMulAddCol{mtx}{m}{i}{no}{j}
+\end{lstlisting}&
+Defines a new matrix mtx obtained by multiplying the \(i^{th}\) column of matrix1 by a real or complex number and adding it to the \(j^{th}\) column. \\
+\midrule
+\multicolumn{2}{c}{Reduced row echelon form of matrix} \\
+\midrule
+ \begin{lstlisting}
+\matrixRREF{matrix}{matrix1}
+\end{lstlisting}&
+Defines a new matrix obtained by taking the reduced row echelon form of matrix1. It supports matrices of complex numbers as well. \\
+\midrule
+\begin{lstlisting}
+\matrixRREFSteps[type,truncate]
+{matrix}
+\end{lstlisting}&
+Obtains reduced row echelon form of matrix in a step-by-step manner. The command has two optional parameters \verb|type| and \verb|truncate|. It supports matrices with complex numbers as well. \verb|type| may be one of the values \verb|pmatrix,bmatrix, vmatrix,Vmatrix|.
+The default type is \verb|bmatrix|. \verb|truncate| specifies number of digits up to which matrix entries are to be truncated. \verb|truncate| may be 0,1,2,\ldots. \\
+\midrule
+\multicolumn{2}{c}{Gauss-Jordan Elimination} \\
+\midrule
+\begin{lstlisting}
+\matrixGaussJordan{matrix}
+{m1}{m2}
+\end{lstlisting}&
+Defines new matrix obtained by performing Gauss-Jordan elimination on augmented matrix \(m1|m2\). \\
+\midrule
+\begin{lstlisting}
+\matrixGaussJordanSteps[type,truncate]
+{matrix}{m1}{m2}
+\end{lstlisting}&
+Defines new matrix obtained by performing Gauss-Jordan elimination on augmented matrix \(m1|m2\) in a step-by-step manner. The command has two optional parameters \verb|type| and \verb|truncate|. \verb|type| may be one of the values \verb|pmatrix, bmatrix, vmatrix,| \verb |Vmatrix|. The default type is \verb|bmatrix|. \verb|truncate| specifies number of digits up to which matrix entries are to be truncated. \verb|truncate| may be 0,1,2,\ldots. \\
+\bottomrule \\
+\caption{Commands for operations on matrices}
+\label{tbl:luamtxcmd}
+\end{longtable}
+\subsection{Illustrations of matrix operations}
+The following commands define matrices \(m,n,\) and \(r\).
+\begin{lstlisting}
+\def\r{{{1,2,3},{4,5,6},{7,8,complex('9+3i')}}}
+\def\s{{{1,2,3},{4,5,6},{7,8,10}}}
+\def\t{{{1,2,3},{4,5,6},{7,8,9}}}
+\def\u{{{1},{2},{3}}}
+
+\matrixNew{m}{\r}
+\matrixNew{n}{\s}
+\matrixNew{p}{\t}
+\matrixNew{q}{\u}
+\end{lstlisting}
+Table \ref{tbl:illluamatrix} illustrates various operations on matrices \(m,n,p,\) and \(q\).
+\begin{center}
+\begin{longtable}{lc}
+\toprule
+Commands & Output Produced\\
+\toprule
+\multicolumn{2}{c}{Printing matrices}\\
+\midrule
+\begin{lstlisting}
+\(m=\matrixPrint{\m}\)
+\end{lstlisting} &
+\(m=\begin{bmatrix} 1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 7.0 & 8.0 & 9.0+3.0i\end{bmatrix}\)
+\\
+\midrule
+\begin{lstlisting}
+\(m=\matrixPrint[type=pmatrix]{\m}\)
+\end{lstlisting} &
+\(m=\begin{pmatrix} 1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 7.0 & 8.0 & 9.0+3.0i\end{pmatrix}\)
+\\
+\midrule
+\multicolumn{2}{c}{Some parameters of defined matrices}\\
+\midrule
+\begin{lstlisting}
+\(No. or rows in matrix m
+= \matrixNumRows{m}\)
+\end{lstlisting} &
+No. or rows in matrix \(m = 3\)\\
+\midrule
+\begin{lstlisting}
+\(No. or columns in matrix m
+= \matrixNumCols{m}\)
+\end{lstlisting} &
+No. or columns in matrix \(m = 3\)\\
+\midrule
+\begin{lstlisting}
+\(Element of matrix m at (3,3) =
+ \matrixGetElement{m}{3}{3}\)
+\end{lstlisting} &
+\(9+3i\)\\
+\midrule
+\multicolumn{2}{c}{Algebraic operations on matrices}\\
+\midrule
+\begin{lstlisting}
+\matrixAdd{m1}{m}{p}
+\(m1 = \matrixPrint{m1}\)
+\end{lstlisting} &
+\(m1 = \begin{bmatrix} 2.0 & 4.0 & 6.0 \\ 8.0 & 10.0 & 12.0 \\ 14.0 & 16.0 & 18.0+3.0i\end{bmatrix}
+\)\\
+\midrule
+\begin{lstlisting}
+\matrixSub{m2}{m}{p}
+\(m2 = \matrixPrint{m2}\)
+\end{lstlisting} &
+\(m2 = \begin{bmatrix} 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 0.0 \\ 0.0 & 0.0 & 3.0i \end{bmatrix}
+\)\\
+\midrule
+\begin{lstlisting}
+\matrixMulNum{m3}{3}{m}
+\(m3 = \matrixPrint{m3}\)
+\end{lstlisting} &
+\(m3 = \begin{bmatrix} 3.0 & 6.0 & 9.0 \\ 12.0 & 15.0 & 18.0 \\ 21.0 & 24.0 & 27.0+9.0i\end{bmatrix}
+\)\\
+\midrule
+\begin{lstlisting}
+\matrixMul{m4}{m}{p}
+\(m4 = \matrixPrint{m4}\)
+\end{lstlisting} &
+\(m4 = \begin{bmatrix} 30.0 & 36.0 & 42.0 \\ 66.0 & 81.0 & 96.0 \\ 102.0+21.0i & 126.0+24.0i & 150.0+27.0i\end{bmatrix}
+\)\\
+\midrule
+\begin{lstlisting}
+\matrixPow{m5}{m}{2}
+\(m5 = \matrixPrint{m5}\)
+\end{lstlisting} &
+\(m5 = \begin{bmatrix} 30.0 & 36.0 & 42.0+9.0i \\ 66.0 & 81.0 & 96.0+18.0i \\ 102.0+21.0i & 126.0+24.0i & 141.0+54.0i\end{bmatrix}
+\)\\
+\midrule
+\begin{lstlisting}
+\matrixInvert{m6}{m}
+\(m6 = \matrixPrint[truncate=4]{m6}\)
+\end{lstlisting} &
+\(m6 = \begin{bmatrix} -1.6667-0.3333i & 0.6667+0.6667i & -0.3333i \\ 1.3333+0.6667i & -0.3333-1.3333i & 0.6667i \\ -0.3333i & 0.6667i & -0.3333i\end{bmatrix}
+\)\\
+\midrule
+
+\begin{lstlisting}
+Rank of matrix \(m =\matrixRank{m}\)
+
+\end{lstlisting} &
+Rank of matrix \(m = 3\)\\
+\midrule
+\begin{lstlisting}
+Determinant of matrix \(m =\matrixDet{m}\)
+\end{lstlisting} &
+Determinant of matrix \(m = -9i\)\\
+\midrule
+\begin{lstlisting}
+\matrixTranspose{m7}{m}
+\(m7 = \matrixPrint{m7}\)
+\end{lstlisting} &
+\(m7 = \begin{bmatrix}1.0 & 4.0 & 7.0 \\ 2.0 & 5.0 & 8.0 \\ 3.0 & 6.0 & 9.0+3.0i\end{bmatrix}
+\)\\
+\midrule
+\begin{lstlisting}
+\matrixSetElement{n}{3}{3}{300}
+\(n= \matrixPrint{n}\)
+\end{lstlisting} &
+\(n = \begin{bmatrix}1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 7.0 & 8.0 & 300.0\end{bmatrix}
+\)\\
+\midrule
+
+\begin{lstlisting}
+\matrixSubmatrix{m8}{m}{1}{2}{2}{3}
+\(m8 = \matrixPrint{m8}\)
+\end{lstlisting} &
+\(m8 = \begin{bmatrix} 2.0 & 3.0 \\ 5.0 & 6.0\end{bmatrix}
+\)\\
+\midrule
+\begin{lstlisting}
+\matrixConcatH{m9}{m}{q}
+\(m9= \matrixPrint{m9}\)
+\end{lstlisting} &
+\(m9 = \begin{bmatrix}1.0 & 2.0 & 3.0 & 1.0 \\ 4.0 & 5.0 & 6.0 & 2.0 \\ 7.0 & 8.0 & 9.0+3.0i & 3.0\end{bmatrix}
+\)\\
+\midrule
+\begin{lstlisting}
+\matrixConcatV{m10}{m}{n}
+\(m10= \matrixPrint{m10}\)
+\end{lstlisting} &
+\(m10= \begin{bmatrix} 1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 7.0 & 8.0 & 9.0+3.0i \\ 1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 7.0 & 8.0 & 300.0\end{bmatrix}
+\)\\
+\midrule
+\begin{lstlisting}
+\matrixOp{m11}{m*m+2*m}
+\(\matrixPrint[truncate=4]{m11}\)
+\end{lstlisting} &
+\(m11 = \begin{bmatrix} 32.0 & 40.0 & 48.0+9.0i \\ 74.0 & 91.0 & 108.0+18.0i \\ 116.0+21.0i & 142.0+24.0i & 159.0+60.0i\end{bmatrix}
+\)\\
+\midrule
+\begin{lstlisting}
+\matrixCopy{m12}{m}
+\(m12 = \matrixPrint{m12}\)
+\end{lstlisting} &
+\(m12 = \begin{bmatrix}1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 7.0 & 8.0 & 9.0+3.0i\end{bmatrix}
+\)\\
+
+\midrule
+\begin{lstlisting}
+trace of matrix \( m = \matrixTrace{m}\)
+\end{lstlisting} &
+trace of matrix \( m = 15+3i\) \\
+
+\midrule
+\begin{lstlisting}
+\matrixConjugate{mc}{m}
+\(mc = \matrixPrint{mc}\)
+\end{lstlisting} &
+\(mc = \begin{bmatrix} 1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 7.0 & 8.0 & 9.0-3.0i\end{bmatrix}
+\)\\
+\midrule
+
+\begin{lstlisting}
+\matrixConjugateT{mct}{m}
+\(mct = \matrixPrint{mct}\)
+\end{lstlisting} &
+\(mct = \begin{bmatrix} 1.0 & 4.0 & 7.0 \\ 2.0 & 5.0 & 8.0 \\ 3.0 & 6.0 & 9.0-3.0i\end{bmatrix}
+\)\\
+\midrule
+
+\begin{lstlisting}
+ \(\matrixNormOne{m}\)
+\end{lstlisting} &
+ \(18.486832980505\) \\
+
+\midrule
+\begin{lstlisting}
+ \(\matrixNormInfty{m}\)
+\end{lstlisting} &
+ \(24.486832980505\) \\
+
+\midrule
+\begin{lstlisting}
+ \(\matrixNormMax{m}\)
+\end{lstlisting} &
+ \(9.4868329805051\) \\
+
+\midrule
+\begin{lstlisting}
+ \(\matrixNormF{m}\)
+\end{lstlisting} &
+\( 17.146428199482\) \\
+
+\midrule
+\multicolumn{2}{c}{Elementary row operations on matrices}\\
+\midrule
+\begin{lstlisting}
+\matrixSwapRows{m13}{m}{2}{3}
+\(m13 = \matrixPrint{m13}\)
+\end{lstlisting} &
+\(m13 = \begin{bmatrix}1.0 & 2.0 & 3.0 \\ 7.0 & 8.0 & 9.0+3.0i \\ 4.0 & 5.0 & 6.0\end{bmatrix}
+\)\\
+\midrule
+\begin{lstlisting}
+\matrixMulRow{m14}{m}{3}{300}
+\(m14 = \matrixPrint{m14}\)
+\end{lstlisting} &
+\(m14 = \begin{bmatrix}1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 2100.0 & 2400.0 & 2700.0+900.0i \end{bmatrix}
+\)\\
+\midrule
+\begin{lstlisting}
+\matrixMulAddRow{m15}{m}{2}{10}{3}
+\(m15 = \matrixPrint{m15}\)
+\end{lstlisting} &
+\(m15 = \begin{bmatrix}1.0 & 2.0 & 3.0 \\ 4.0 & 5.0 & 6.0 \\ 47.0 & 58.0 & 69.0+3.0i\end{bmatrix}
+\)\\
+\midrule
+\multicolumn{2}{c}{Elementary column operations on matrices}\\
+\midrule
+\begin{lstlisting}
+\matrixSwapCols{m16}{m}{2}{3}
+\(m16 = \matrixPrint{m16}\)
+\end{lstlisting} &
+\(m16 = \begin{bmatrix}1.0 & 3.0 & 2.0 \\ 4.0 & 6.0 & 5.0 \\ 7.0 & 9.0+3.0i & 8.0\end{bmatrix}
+\)\\
+\midrule
+\begin{lstlisting}
+\matrixMulCol{m17}{m}{3}{300}
+\(m17 = \matrixPrint{m17}\)
+\end{lstlisting} &
+\(m17 = \begin{bmatrix} 1.0 & 2.0 & 900.0 \\ 4.0 & 5.0 & 1800.0 \\ 7.0 & 8.0 & 2700.0+900.0i \end{bmatrix}
+\)\\
+\midrule
+
+\begin{lstlisting}
+\matrixMulAddCol{m18}{m}{2}{10}{3}
+\(m18 = \matrixPrint{m18}\)
+\end{lstlisting} &
+\(m18 = \begin{bmatrix}1.0 & 2.0 & 23.0 \\ 4.0 & 5.0 & 56.0 \\ 7.0 & 8.0 & 89.0+3.0i\end{bmatrix}
+\)\\
+\midrule
+
+\multicolumn{2}{c}{Reduced row echelon form of a matrix}\\
+\midrule
+\begin{lstlisting}
+\matrixRREF{m19}{p}
+\(m19 = \matrixPrint{m19}\)
+\end{lstlisting} &
+\(m19 = \begin{bmatrix}1.0 & 0.0 & -1.0 \\ 0.0 & 1.0 & 2.0 \\ 0.0 & 0.0 & 0.0\end{bmatrix}
+\)\\
+\midrule
+\begin{lstlisting}
+\matrixRREF{m20}{m}
+\(m20 = \matrixPrint{m20}\)
+\end{lstlisting} &
+\(m20 = \begin{bmatrix} 1.0 & 0.0 & 0.0 \\ 0.0 & 1.0 & 0.0 \\ 0.0 & 0.0 & 1.0\end{bmatrix}
+\)\\
+\bottomrule \\
+\caption{Illustration of commands for operations on matrices}
+\label{tbl:illluamatrix}
+\end{longtable}
+\end{center}
+
+The package has command \verb|\matrixRREFSteps| to produce step-by-step computation of reduced row echelon form of a matrix. The command \verb|\matrixRREFSteps{p}| outputs the following.
+\begin{framed}Step 1:Multiply row 1 by 4.0 and subtract it from row 2.$$\begin{bmatrix} 1.0 & 2.0 & 3.0 \\ 0.0 & -3.0 & -6.0 \\ 7.0 & 8.0 & 9.0 \\ \end{bmatrix} $$Step 2:Multiply row 1 by 7.0 and subtract it from row 3.$$\begin{bmatrix} 1.0 & 2.0 & 3.0 \\ 0.0 & -3.0 & -6.0 \\ 0.0 & -6.0 & -12.0 \\ \end{bmatrix} $$Step 3:Divide row 2 by -3.0.$$\begin{bmatrix} 1.0 & 2.0 & 3.0 \\ 0.0 & 1.0 & 2.0 \\ 0.0 & -6.0 & -12.0 \\ \end{bmatrix} $$Step 4:Multiply row 2 by 2.0 and subtract it from row 1.$$\begin{bmatrix} 1.0 & 0.0 & -1.0 \\ 0.0 & 1.0 & 2.0 \\ 0.0 & -6.0 & -12.0 \\ \end{bmatrix} $$Step 5:Multiply row 2 by -6.0 and subtract it from row 3.$$\begin{bmatrix} 1.0 & 0.0 & -1.0 \\ 0.0 & 1.0 & 2.0 \\ 0.0 & 0.0 & 0.0 \\ \end{bmatrix} $$
+\end{framed}
+
+The command \verb|\matrixGaussJordan| is used to obtain Gauss-Jordan elimination of an augmented matrix.
+
+\begin{lstlisting}
+\def\a{{{1,1,1},{2,-1,-1},{1,-1,1}}}
+\def\b{{{3},{3},{9}}}
+\matrixNew{S}{\a}
+\matrixNew{T}{\b}
+\matrixConcatH{W}{S}{T}
+$$W = \matrixPrint{W}$$
+\matrixGaussJordan{U}{S}{T}
+$$U = \matrixPrint{U}$$
+\end{lstlisting}
+
+The above code produces the following output.
+\begin{framed}
+$$W =\begin{bmatrix} 1.0 & 1.0 & 1.0 & 3.0 \\ 2.0 & -1.0 & -1.0 & 3.0 \\ 1.0 & -1.0 & 1.0 & 9.0 \\ \end{bmatrix} $$
+$$U = \begin{bmatrix} 1.0 & 0.0 & 0.0 & 2.0 \\ 0.0 & 1.0 & 0.0 & -3.0 \\ 0.0 & 0.0 & 1.0 & 4.0 \\ \end{bmatrix}$$
+\end{framed}
+
+The package also has a command \verb|\matrixGaussJordanSteps| to produce step-by-step computation of Gauss-Jordan elimination of an augmented matrix. The command \verb|\matrixGaussJordanSteps{S}{T}| produces the following output.
+
+\begin{framed}
+$$W =\begin{bmatrix} 1.0 & 1.0 & 1.0 & 3.0 \\ 2.0 & -1.0 & -1.0 & 3.0 \\ 1.0 & -1.0 & 1.0 & 9.0 \\ \end{bmatrix} $$
+Step 1:Multiply row 1 by 2.0 and subtract it from row 2.$$\begin{bmatrix} 1.0 & 1.0 & 1.0 & 3.0 \\ 0.0 & -3.0 & -3.0 & -3.0 \\ 1.0 & -1.0 & 1.0 & 9.0 \\ \end{bmatrix} $$Step 2:Multiply row 1 by 1.0 and subtract it from row 3.$$\begin{bmatrix} 1.0 & 1.0 & 1.0 & 3.0 \\ 0.0 & -3.0 & -3.0 & -3.0 \\ 0.0 & -2.0 & 0.0 & 6.0 \\ \end{bmatrix} $$Step 3:Divide row 2 by -3.0.$$\begin{bmatrix} 1.0 & 1.0 & 1.0 & 3.0 \\ 0.0 & 1.0 & 1.0 & 1.0 \\ 0.0 & -2.0 & 0.0 & 6.0 \\ \end{bmatrix} $$Step 4:Multiply row 2 by 1.0 and subtract it from row 1.$$\begin{bmatrix} 1.0 & 0.0 & 0.0 & 2.0 \\ 0.0 & 1.0 & 1.0 & 1.0 \\ 0.0 & -2.0 & 0.0 & 6.0 \\ \end{bmatrix} $$Step 5:Multiply row 2 by -2.0 and subtract it from row 3.$$\begin{bmatrix} 1.0 & 0.0 & 0.0 & 2.0 \\ 0.0 & 1.0 & 1.0 & 1.0 \\ 0.0 & 0.0 & 2.0 & 8.0 \\ \end{bmatrix} $$Step 6:Divide row 3 by 2.0.$$\begin{bmatrix} 1.0 & 0.0 & 0.0 & 2.0 \\ 0.0 & 1.0 & 1.0 & 1.0 \\ 0.0 & 0.0 & 1.0 & 4.0 \\ \end{bmatrix} $$Step 7:Multiply row 3 by 1.0 and subtract it from row 2.$$\begin{bmatrix} 1.0 & 0.0 & 0.0 & 2.0 \\ 0.0 & 1.0 & 0.0 & -3.0 \\ 0.0 & 0.0 & 1.0 & 4.0 \\ \end{bmatrix} $$
+\end{framed}
+
+\section{Customized usage}\label{customuse}
+The commands available in the package can be used for performing further operations on vectors and matrices. The command \verb|\vectorAdd| can be extended to add more than two vectors. The latex document (listing \ref{code:custluavec}) provides some instances of such usage.
+\begin{lstlisting}[label={code:custluavec}, caption={Customized usage of the lualinalg package}]
+\documentclass{article}
+\usepackage{lualinalg}
+\begin{document}
+\begin{luacode}
+function sumcoordinates(v1)
+local sum = 0
+for i = 1,#v1 do
+ sum = sum + v1[i]
+ end
+return sum
+end
+
+function vector.addmulti(...)
+ p=table.pack(...)
+ s=vector(p[1])
+ for i=2,#p do
+s=vector.add(s,vector(p[i]))
+end
+ return s
+end
+\end{luacode}
+\vectorNew{v}{{1,2,complex('3+3i')}}
+The sum of coordinates of vector
+ \(v = \directlua{tex.sprint(tostring( sumcoordinates(v)))}\).
+
+\newcommand\vectorAddmulti[2]{%
+ \directlua{%
+ vectors['#1'] = vector.addmulti(#2)
+ }%
+}
+
+\vectorNew{w}{{3,6,complex('6+6i')}}
+\vectorNew{x}{{9,12,complex('12+12i')}}
+\vectorAddmulti{y}{v,w,x}
+The sum of vectors \(v,w \text{ and } x =\left( \vectorPrint{y} \right)\).
+\end{document}
+\end{lstlisting}
+
+The latex document (listing \ref{code:custluavec}) outputs the following on compilation.
+\begin{framed}
+The sum of coordinates of vector \(v = 6 + 3i\).
+
+The sum of vectors \(v,w \text{ and } x = \left(13.0, 20.0, 21.0 + 21.0i \right) \).
+\end{framed}
+
+
+The command \verb|\matrixAdd| can be extended to add more than two matrices. The latex document (listing \ref{code:custluamtx}) provides some instances of such usage.
+
+\begin{lstlisting}[label={code:custluamtx}, caption={Customized usage of the lualinalg package}]
+\documentclass{article}
+\usepackage{lualinalg}
+\begin{document}
+\begin{luacode}
+function squareDiagEntries(m1)
+ if #m1 ~= #m1[1] then error( "matrix not square") end
+ local sum = 0
+for i = 1,#m1 do
+ for j = 1,#m1[1] do
+ if i == j then sum = sum + (m1[i][j])^2 end
+ end
+ end
+return sum
+end
+
+function matrix.addmulti(...)
+ p=table.pack(...)
+ s=matrix(p[1])
+ for i=2,#p do
+s=matrix.add(s,matrix(p[i]))
+end
+ return s
+end
+\end{luacode}
+
+\def\r{{{1,2,3},{4,5,6},{7,8,complex('9+3i')}}}
+\matrixNew{m}{\r}
+The sum of squares of diagonal entries of matrix
+ \(m = \directlua{tex.sprint(tostring(squareDiagEntries(m)))}\).
+
+\def\s{{{1,2,3},{4,5,complex('6+6i')}}}
+\def\t{{{10,20,30},{40,50,complex('60+60i')}}}
+\def\u{{{100,200,300},{400,500,complex('600+600i')}}}
+\matrixNew{m1}{\s}
+\matrixNew{m2}{\t}
+\matrixNew{m3}{\u}
+\newcommand\matrixAddmulti[2]{%
+ \directlua{%
+ matrices['#1'] = matrix.addmulti(#2)
+ }%
+}
+\matrixAddmulti{m4}{m1,m2,m3}
+The sum of matrices \(m1,m2 \text{ and } m3 = \matrixPrint{m4}\).
+\end{document}
+\end{lstlisting}
+
+The latex document (listing \ref{code:custluamtx}) outputs the following on compilation.
+\begin{framed}
+The sum of squares of diagonal entries of matrix \(m = 98.0 + 54i\).
+
+The sum of matrices \(m1,m2 \text{ and } m3 =\begin{bmatrix} 111.0 & 222.0 & 333.0 \\ 444.0 & 555.0 & 666.0+666.0i \end{bmatrix} \).
+\end{framed}
+
+\section{Known issues and limitations}
+\begin{itemize}
+\item The package supports small and big numbers. They can be input in the usual scientific notation. The math library in Lua defines constants with the maximum \verb|math.maxinteger| and the minimum \verb|math.mininteger| values for an integer. The result wraps around when there is a computational operation on integers that would result in a value smaller than the \verb|mininteger| or larger than the \verb|maxinteger|. It means that the computed result is the only number between the \verb|miniinteger| and \verb|maxinteger|.
+
+\item The package currently supports only numerical computations. The table in a Lua is a data type that implements an associative array. This feature is used in packages to define and store vectors and matrices. This approach is close to object-oriented programming. It will allow easy conversion of algorithms in packages for symbolic computations. Future package updates will consider algorithm conversions to support symbolic calculations.
+
+\item The error handling mechanism in the tool is not robust. There are some custom errors included in the package. However the package mostly depends on error handling mechanism of Lua. The error handling can be strengthened in future updates of the package.
+
+\end{itemize}
+\end{document} \ No newline at end of file