summaryrefslogtreecommitdiff
path: root/macros/luatex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-08-04 03:01:07 +0000
committerNorbert Preining <norbert@preining.info>2023-08-04 03:01:07 +0000
commit319c90e45fc96ba6f15edcf00b24e484d9d92f2b (patch)
tree7011e82643aff6842597d83574783a350142063c /macros/luatex
parent63c1aaa794cb47fe36ebe8010257ec8ad322efbb (diff)
CTAN sync 202308040301
Diffstat (limited to 'macros/luatex')
-rw-r--r--macros/luatex/latex/lualinalg/2dvec.jpgbin17528 -> 0 bytes
-rw-r--r--macros/luatex/latex/lualinalg/3dvec.jpgbin17920 -> 0 bytes
-rw-r--r--macros/luatex/latex/lualinalg/README.txt5
-rw-r--r--macros/luatex/latex/lualinalg/lualinalg-complex.lua347
-rw-r--r--macros/luatex/latex/lualinalg/lualinalg-fractions.lua225
-rw-r--r--macros/luatex/latex/lualinalg/lualinalg.pdfbin345503 -> 269062 bytes
-rw-r--r--macros/luatex/latex/lualinalg/lualinalg.sty36
-rw-r--r--macros/luatex/latex/lualinalg/lualinalg.tex420
-rw-r--r--macros/luatex/latex/lualinalg/lualinalg_complex.lua298
-rw-r--r--macros/luatex/latex/luamaths/README.txt9
-rw-r--r--macros/luatex/latex/luamaths/luamaths-complex.lua347
-rw-r--r--macros/luatex/latex/luamaths/luamaths-fractions.lua225
-rw-r--r--macros/luatex/latex/luamaths/luamaths.pdfbin176909 -> 145138 bytes
-rw-r--r--macros/luatex/latex/luamaths/luamaths.sty24
-rw-r--r--macros/luatex/latex/luamaths/luamaths.tex140
15 files changed, 1556 insertions, 520 deletions
diff --git a/macros/luatex/latex/lualinalg/2dvec.jpg b/macros/luatex/latex/lualinalg/2dvec.jpg
deleted file mode 100644
index 7b857ab6d0..0000000000
--- a/macros/luatex/latex/lualinalg/2dvec.jpg
+++ /dev/null
Binary files differ
diff --git a/macros/luatex/latex/lualinalg/3dvec.jpg b/macros/luatex/latex/lualinalg/3dvec.jpg
deleted file mode 100644
index 1f84c4044f..0000000000
--- a/macros/luatex/latex/lualinalg/3dvec.jpg
+++ /dev/null
Binary files differ
diff --git a/macros/luatex/latex/lualinalg/README.txt b/macros/luatex/latex/lualinalg/README.txt
index 6b347a9417..03a71035cb 100644
--- a/macros/luatex/latex/lualinalg/README.txt
+++ b/macros/luatex/latex/lualinalg/README.txt
@@ -1,3 +1,8 @@
+# The lualinalg package
+# version 1.3
+# Authors: Chetan Shirore and Ajit Kumar
+# Email: mathsbeauty@gmail.com
+
# 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.
diff --git a/macros/luatex/latex/lualinalg/lualinalg-complex.lua b/macros/luatex/latex/lualinalg/lualinalg-complex.lua
new file mode 100644
index 0000000000..68fd055b5e
--- /dev/null
+++ b/macros/luatex/latex/lualinalg/lualinalg-complex.lua
@@ -0,0 +1,347 @@
+--Version=1.3, Date=30-July-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/complex.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.
+
+frac= require("luamaths-fractions")
+complex = {}
+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
+
+ if getmetatable( num) == frac_mt then
+ return setmetatable( { num, 0 }, complex_meta )
+ 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( x,y)
+ return setmetatable( {x,y}, complex_meta )
+end
+
+lcomplex = complex.new
+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 )
+ imunit = "\\imUnit"
+ local real,imag = cx[1],cx[2]
+ if type(cx[1]) ~= "table" and type(cx[2]) ~= "table" then
+ if imag == 0 then
+ return real
+ elseif real == 0 then
+ return ((imag==1 and "") or (imag==-1 and "-") or imag)..imunit
+ elseif imag > 0 then
+ return real.."+"..(imag==1 and "" or imag)..imunit
+ end
+ return real..(imag==-1 and "-" or imag)..imunit
+ end
+
+ if type(cx[1]) == "table" and type(cx[2]) ~= "table" then
+ if cx[2] == 0 then
+ return frac.tostring(cx[1])
+ end
+ if cx[2] > 0 then
+ return frac.tostring(cx[1]).. "+"..(imag==1 and "" or imag)..imunit
+ end
+ if cx[2] < 0 then
+ return frac.tostring(cx[1])..(imag==-1 and "-" or imag)..imunit
+ end
+
+ end
+
+ if type(cx[1]) ~= "table" and type(cx[2]) == "table" then
+ if frac.toFnumber(cx[2])==0 then return cx[1] end
+ return cx[1].."+"..frac.tostring(cx[2])..imunit
+ end
+
+ if type(cx[1]) == "table" and type(cx[2]) == "table" then
+ if frac.toFnumber(cx[1]) == 0 and frac.toFnumber(cx[2]) ~= 0 then
+ return frac.tostring(cx[2])..imunit
+ end
+
+ if frac.toFnumber(cx[2]) == 0 then
+ return frac.tostring(cx[1] + 0)
+ end
+
+ if cx[2].d == 1 then
+ if cx[2].n > 0 then
+ return frac.tostring(cx[1]).. "+"..(cx[2].n==1 and "" or math.floor(cx[2].n))..imunit
+ end
+ if cx[2].n < 0 then
+ return frac.tostring(cx[1])..(cx[2].n==-1 and "-" or math.floor(cx[2].n))..imunit
+ end
+ end
+ end
+ return frac.tostring(cx[1]).. "+"..frac.tostring(cx[2])..imunit
+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]*cx2[1] + cx2[2]*cx2[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 h
+ local k
+
+ if type(cx[1]) ~= "table" then h = cx[1] end
+ if type(cx[2]) ~= "table" then k = cx[2] end
+
+ if type(cx[1]) == "table" then h = frac.toFnumber(cx[1]) end
+ if type(cx[2]) == "table" then k = frac.toFnumber(cx[2]) end
+ local len = math.sqrt( h^2 + k^2 )
+ local sign = ( h<0 and -1) or 1
+ return setmetatable( { math.sqrt((h +len)/2), sign*math.sqrt((len-h)/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 Xround(num, numDecimalPlaces)
+ if type(num)=="number" then
+ if num==math.floor(num) then
+ return math.floor(num)
+ end
+ end
+ if type(num)=="number" then
+ local mult = 10^(numDecimalPlaces or 0)
+ return math.floor(num * mult + 0.5) / mult
+ end
+ return num
+end
+
+function complex.round( cx,idp )
+ local mult =10^( idp or 0 )
+ if type(cx[1]) ~= "table" and type(cx[2]) ~= "table" then
+ return setmetatable( {Xround(cx[1],idp), Xround(cx[2],idp)}, complex_meta )
+ end
+ if type(cx[1]) ~= "table" and type(cx[2]) == "table" then
+ return setmetatable( {Xround(cx[1],idp), cx[2]}, complex_meta )
+ end
+ if type(cx[1]) == "table" and type(cx[2]) ~= "table" then
+ return setmetatable({cx[1],Xround(cx[2],idp)}, complex_meta )
+ end
+ if type(cx[1]) == "table" and type(cx[2]) == "table" then
+ return setmetatable({cx[1],cx[2]}, complex_meta )
+ end
+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-fractions.lua b/macros/luatex/latex/lualinalg/lualinalg-fractions.lua
new file mode 100644
index 0000000000..e4ab7a2329
--- /dev/null
+++ b/macros/luatex/latex/lualinalg/lualinalg-fractions.lua
@@ -0,0 +1,225 @@
+-- The luafractions module
+-- Authors: Chetan Shirore and Ajit Kumar
+-- version 1.0, Date=03-Aug-2023
+-- Licensed under LaTeX Project Public License v1.3c or later. The complete license text is available at http://www.latex-project.org/lppl.txt.
+
+M = {} -- the module
+frac_mt = {} -- the metatable
+function M.new (n, d, mode)
+ mode = mode or 'fracs'
+ if mode == 'nofracs' then
+ return (n/d)
+ end
+ if mode == 'fracs' then
+ if n~=math.floor(n) or d~=math.floor(d) then
+ error('Only integers are expected.')
+ end
+ if d == 0 then
+ error('Invalid fraction')
+ end
+ local fr = {}
+ local g = M.lgcd(n,d)
+ fr = {n=n/g, d=d/g}
+ return setmetatable(fr,frac_mt)
+ end
+end
+lfrac = M.new
+
+function M.lgcd (a, b)
+ local r
+ while (b ~= 0) do
+ r = a % b
+ a = b
+ b = r
+ end
+ return a
+end
+
+function M.simp (num)
+ local cf = gcd(num[1], num[2])
+ return M.new(num[1] / cf, num2[2] / cf)
+end
+
+function M.toFnumber(c)
+ return c.n / c.d
+end
+
+function M.toFrac(x)
+ if type(x) == "number" then
+ if x==math.floor(x) then
+ return M.new(math.floor(x),1)
+ else
+ return x
+ end
+ end
+ return x
+end
+
+
+function addFracs (c1, c2)
+ return M.new(c1.n * c2.d + c1.d * c2.n, c1.d*c2.d)
+end
+
+function subFracs (c1, c2)
+ return M.new(c1.n * c2.d - c1.d * c2.n, c1.d*c2.d)
+end
+
+function mulFracs (c1, c2)
+ return M.new(c1.n * c2.n, c1.d*c2.d)
+end
+
+function divFracs (c1, c2)
+ return M.new(c1.n * c2.d, c1.d*c2.n)
+end
+
+function minusFracs (c1)
+ return M.new(-c1.n,c1.d)
+end
+
+function powerFracs (c1,m)
+ return M.new((c1.n)^m,(c1.d)^m)
+end
+
+
+function M.add(a, b)
+ if type(a) == "number" then
+ if a==math.floor(a) then
+ return addFracs(M.new(a,1),b)
+ else
+ return a + M.toFnumber(b)
+ end
+ end
+
+ if type(b) == "number" then
+ if b==math.floor(b) then
+ return addFracs(a,M.new(b,1))
+ else
+ return M.toFnumber(a) + b
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( a ) == frac_mt and getmetatable( b ) == complex_meta then
+ return setmetatable( { a+b[1], b[2] }, complex_meta )
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( b ) == frac_mt and getmetatable( a ) == complex_meta then
+ return setmetatable( { b+a[1], a[2] }, complex_meta )
+ end
+ end
+ return addFracs(a, b)
+end
+
+
+function M.sub(a, b)
+ if type(a) == "number" then
+ if a==math.floor(a) then
+ return subFracs(M.new(a,1),b)
+ else
+ return a - M.toFnumber(b)
+ end
+ end
+
+ if type(b) == "number" then
+ if b==math.floor(b) then
+ return subFracs(a,M.new(b,1))
+ else
+ return M.toFnumber(a) - b
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( a ) == frac_mt and getmetatable( b ) == complex_meta then
+ return setmetatable( { a-b[1], b[2] }, complex_meta )
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( b ) == frac_mt and getmetatable( a ) == complex_meta then
+ return setmetatable( { a[1]-b, a[2] }, complex_meta )
+ end
+ end
+ return subFracs(a, b)
+end
+
+
+function M.mul(a, b)
+ if type(a) == "number" then
+ if a==math.floor(a) then
+ return mulFracs(M.new(a,1),b)
+ else
+ return a * M.toFnumber(b)
+ end
+ end
+
+ if type(b) == "number" then
+ if b==math.floor(b) then
+ return mulFracs(a,M.new(b,1))
+ else
+ return M.toFnumber(a) * b
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( a ) == frac_mt and getmetatable( b ) == complex_meta then
+ return setmetatable( { a*b[1], a*b[2] }, complex_meta )
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( b ) == frac_mt and getmetatable( a ) == complex_meta then
+ return setmetatable( { b*a[1], b*a[2] }, complex_meta )
+ end
+ end
+ return mulFracs(a, b)
+end
+
+
+function M.div(a, b)
+ if type(a) == "number" then
+ if a==math.floor(a) then
+ return divFracs(M.new(a,1),b)
+ else
+ return a / M.toFnumber(b)
+ end
+ end
+
+ if type(b) == "number" then
+ if b==math.floor(b) then
+ return divFracs(a,M.new(b,1))
+ else
+ return M.toFnumber(a) / b
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( a ) == frac_mt and getmetatable( b ) == complex_meta then
+ b= setmetatable( { M.toFrac(b[1]), M.toFrac(b[2]) }, complex_meta )
+ return a*(1/b)
+ end
+ end
+ return divFracs(a, b)
+end
+
+function M.tostring (c)
+ if c.d == 1 then
+ return string.format("%g",c.n)
+ end
+ if c.d == -1 then
+ return string.format("%g",-c.n)
+ end
+ return string.format("\\frac{%g}{%g}", c.n, c.d)
+end
+
+--Setting Metatable operations.
+frac_mt.__add = M.add
+frac_mt.__sub = M.sub
+frac_mt.__mul = M.mul
+frac_mt.__div = M.div
+frac_mt.__unm = minusFracs
+frac_mt.__pow = powerFracs
+frac_mt.__tostring = M.tostring
+
+return M \ No newline at end of file
diff --git a/macros/luatex/latex/lualinalg/lualinalg.pdf b/macros/luatex/latex/lualinalg/lualinalg.pdf
index 8b277707bd..b164d33407 100644
--- a/macros/luatex/latex/lualinalg/lualinalg.pdf
+++ 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
index 5588fba0a0..de120d131a 100644
--- a/macros/luatex/latex/lualinalg/lualinalg.sty
+++ b/macros/luatex/latex/lualinalg/lualinalg.sty
@@ -1,17 +1,18 @@
% The lualinalg package
% Authors: Chetan Shirore and Ajit Kumar
-% version 1.2, Date=14-Feb-2023
+% version 1.3, Date=03-Aug-2023
% 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.2]
+\ProvidesPackage{lualinalg}[1.3]
\RequirePackage{xkeyval}
\RequirePackage{amsmath}
\RequirePackage{luamaths}
\RequirePackage{luacode}
\begin{luacode*}
-local complex = require "lualinalg_complex"
+local complex = require "lualinalg-complex"
+ local lfrac = require "lualinalg-fractions"
-- matrices part
matrices = {}
@@ -431,7 +432,7 @@ end
function matrix.process(m1)
--m1=load("return "..m1)()
- return matrix.mulnum(m1, 1.0)
+ return matrix.mulnum(m1, 1)
end
function matrix.det(m1)
@@ -558,7 +559,7 @@ function matrix.rref(mtx)
local m = mtx[i][lead]
if (i ~= r) then
for v = 1, columnCount do
- mtx[i][v] = mtx[i][v] - m * mtx[r][v]
+ mtx[i][v] = mtx[i][v] + ((-m) * (mtx[r][v]))
end
end
end
@@ -623,9 +624,9 @@ function matrix.rref0E(mtx, fom, dignum)
tostring(stepCnt) ..
": Divide row " ..
tostring(r) ..
- " by " ..
+ " by $" ..
tostring(complex.round(complex(m), dignum)) ..
- ".$$" .. tostring(matrix.show(mtx, fom, dignum)) .. "$$"
+ "$.$$" .. tostring(matrix.show(mtx, fom, dignum)) .. "$$"
end
end
end
@@ -633,7 +634,7 @@ function matrix.rref0E(mtx, fom, dignum)
local m = mtx[i][lead]
if (i ~= r) then
for v = 1, columnCount do
- mtx[i][v] = mtx[i][v] - m * mtx[r][v]
+ mtx[i][v] = mtx[i][v] + ((-m) * (mtx[r][v]))
end
if m ~= 0 then
if m ~= complex("0.0") then
@@ -644,9 +645,9 @@ function matrix.rref0E(mtx, fom, dignum)
tostring(stepCnt) ..
": Multiply row " ..
tostring(r) ..
- " by " ..
+ " by $" ..
tostring(complex.round(complex(m), dignum)) ..
- " and subtract it from row " ..
+ "$ and subtract it from row " ..
tostring(i) ..
".$$" .. tostring(matrix.show(mtx, fom, dignum)) .. "$$"
end
@@ -1089,7 +1090,7 @@ end
function vector.process(v1)
--v1=load("return "..v1)()
- return vector.mulnum(v1, 1.0)
+ return vector.mulnum(v1, 1)
end
function vector.show(vec, dig)
@@ -1137,7 +1138,7 @@ function vector.gs(inptTbl, brckt, dignum)
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)
+ tbl[1] = vector.mulnum(inptTbl[1], 1)
end
setmetatable(tbl[1], vector_meta)
str = str .. "$\\left" .. brcktL .. vector.show(tbl[1], dignum) .. "\\right" .. brcktR
@@ -1184,7 +1185,7 @@ function vector.gsX(inptTbl, brckt, dignum)
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)
+ tbl[1] = vector.mulnum(inptTbl[1], 1)
end
setmetatable(tbl[1], vector_meta)
str = str .. "\\ \\newline Step " .. cnt .. ": $$ u_" .. cnt .. "=v_" .. cnt .. "="
@@ -1205,7 +1206,7 @@ function vector.gsX(inptTbl, brckt, dignum)
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)
+ tbl[i] = vector.mulnum(tbl[i], 1)
end
cnt = cnt + 1
@@ -1267,7 +1268,6 @@ end
% ========= 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}%
@@ -1639,12 +1639,6 @@ end
}%
}
-\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}}
diff --git a/macros/luatex/latex/lualinalg/lualinalg.tex b/macros/luatex/latex/lualinalg/lualinalg.tex
index 99c01d06af..10b2d55c34 100644
--- a/macros/luatex/latex/lualinalg/lualinalg.tex
+++ b/macros/luatex/latex/lualinalg/lualinalg.tex
@@ -1,7 +1,8 @@
\documentclass{article}
\usepackage{listings,color,parskip,booktabs,longtable,array,
-hyperref,multirow,multicol,url,amsmath,amssymb,framed,graphicx,mismath}
-\usepackage[top=1.1in, bottom=1.1in, left=1in, right=1in]{geometry}
+hyperref,multirow,multicol,url,amsmath,amssymb,framed,graphicx,lualinalg,tikz,tikz-3dplot,float}
+\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
+\usetikzlibrary{calc,3d,arrows}
\hypersetup{colorlinks,urlcolor=blue}
\lstset{frame=none,
language=[LaTeX]{TeX},
@@ -20,26 +21,33 @@ hyperref,multirow,multicol,url,amsmath,amssymb,framed,graphicx,mismath}
}
\begin{document}
\title{The lualinalg Package}
-\author{Chetan Shirore and Ajit Kumar}
+\author{Chetan Shirore\thanks{Email id: mathsbeauty@gmail.com} \space 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}).
+The package supports fractions; numerators and denominators must be integers. A fraction can be specified with the Lua function: \verb|lfrac|. This function has the syntax \verb|lfrac(n,d,mode)|: \(n\) is an integer and \(d\) is a non-zero integer. The mode is optional. It can be \verb|fracs| or \verb|nofracs|. The default mode is \verb|fracs|. If fractions are input, the package will display vectors and matrices in fraction mode wherever possible. The package does not attempt to convert floats into fractions. If fractions are expected, then the input should contain fractions. If fractions are input and answers are expected in numbers, the mode can be specified as \verb|nofracs|.
+
+The Lua function \verb|lcomplex| defines the complex numbers. It has the syntax \verb|lcomplex(x,y)|, where \(x\) is a real part, and \(y\) is an imaginary part. \(x\) and \(y\) can also be fractions (numerators and denominators should be integers). The package has a command \verb|\imUnit| which provides typesetting for the imaginary unit. Its default value is \verb|\mathrm{i}|. It can be redefined. For example, one can redefine it as \verb|\renewcommand{\imUnit}{j}}|.
+
+
\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/complex.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}
+\begin{lstlisting}
\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.
+\end{lstlisting}
+
+ 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 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')}}
+\vectorNew{v2}{{3,6,lcomplex(6,6)}}
\end{lstlisting}
The standard vector of dimension \(n \) with \(i^{th}\) coordinate \(1\) can be produced by using the following command.
\begin{lstlisting}
@@ -50,10 +58,12 @@ For example, the following commands
\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) \).
+output to \vectorNew{e_1}{3,'e',1}
+\(e_1=\left(\vectorPrint{e_1}\right)\).
+
\subsection{Commands for operations on vectors}
Table \ref{tbl:luavector} lists commands for operations on vectors.
-\begin{longtable}{m{7cm}m{7cm}}
+\begin{longtable}{m{7cm}m{8.2cm}}
\toprule
\multicolumn{1}{c}{\textcolor{blue}{Command Format}} & \multicolumn{1}{c}{\textcolor{blue}{Description}} \\
\toprule
@@ -117,7 +127,7 @@ Calculates the Euclidean norm of a vector \(v\). If \(v=\left(v_1, \ldots, v_n
\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} \). \\
+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[\leftroot{-2}\uproot{2} p]{|v_1|^p + \cdots + |v_n|^p} \). \\
\midrule
\begin{lstlisting}
\vectorSupNorm{v}
@@ -157,16 +167,21 @@ truncate]{list of vectors}
\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{v}{{1,2,lcomplex(3,3)}}
+\vectorNew{w}{{3,6,lcomplex(6,6)}}
+\vectorNew{x}{{1.12345678,6,lcomplex(6,6)}}
\vectorNew{y}{{1,2,3}}
\end{lstlisting}
Table \ref{tbl:illluavector} illustrates various operations on vectors \(v,w,x\) and \(y\).
-\begin{longtable}{lc}
+\vectorNew{v}{{1,2,lcomplex(3,3)}}
+\vectorNew{w}{{3,6,lcomplex(6,6)}}
+\vectorNew{x}{{1.12345678,6,lcomplex(6,6)}}
+\vectorNew{y}{{1,2,3}}
+\begin{longtable}{lp{6.5cm}}
\toprule
Commands & Output Produced\\
\toprule
@@ -174,93 +189,100 @@ Commands & Output Produced\\
\(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)\)
+\(v=\left(\vectorPrint{v}\right)\) \newline
+\(w=\left(\vectorPrint{w}\right)\)
\\
\midrule
\begin{lstlisting}
\(x=\left(\vectorPrint
[truncate=3]{x}\right)\)
\end{lstlisting} &
-\(x=\left(1.123,6.0,6.0+6.0i\right)\)
+\(x=\left(\vectorPrint
+[truncate=3]{x}\right)\)
\\
\midrule
\begin{lstlisting}
third coordinate of vector
\(v = \vectorGetCoordinate{v}{3}\)
\end{lstlisting} &
-third coordinate of vector \(v = 3 + 3i\)
+third coordinate of vector
+\(v = \vectorGetCoordinate{v}{3}\)
\\
\midrule
\begin{lstlisting}
-\(y = \vectorCopy{y}{w}\)
-\(\left(\vectorPrint{y}\right)\)
+\(\vectorCopy{z}{w}\)
+\(z = \left(\vectorPrint{z}\right)\)
\end{lstlisting} &
-\(y = \left( 3.0,6.0,6.0+6.0i\right)\)
+\(\vectorCopy{z}{w}\)
+\(z = \left(\vectorPrint{z}\right)\)
\\
\midrule
\begin{lstlisting}
new third coordinate of vector
-\(y = \vectorSetCoordinate{y}{3}{9.3}\)
-\(y=\left(\vectorPrint{y}\right)\)
+\(z = \vectorSetCoordinate{z}{3}{9.3}\)
+\(z=\left(\vectorPrint{z}\right)\)
\end{lstlisting} &
-new third coordinate of vector \(y = 9.3\) \\
-& \(y = \left( 3.0,6.0,9.3\right)\)
+new third coordinate of vector
+\(z = \vectorSetCoordinate{z}{3}{9.3}\) \newline
+\(z=\left(\vectorPrint{z}\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)\)
+\vectorAdd{v1}{v}{w}
+\(v1 = v+w =\left(\vectorPrint{v1}\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)\)
+\vectorSub{v2}{v}{w}
+\(v2 = v-w =\left(\vectorPrint{v2}\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)\)
+\vectorMulNum{v3}{v}{complex('3+i')}
+\(v3 = 3v =\left(\vectorPrint{v3}\right)\)
\\
\midrule
\begin{lstlisting}
-\vectorDot{v}{w}
\(v \cdot w =\vectorDot{v}{w}\)
\end{lstlisting} &
-\(v \cdot w = 51\)
+\(v \cdot w =\vectorDot{v}{w}\)
\\
\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)\)
+\vectorCross{v4}{v}{w}
+\(v \times w =\left(\vectorPrint{v4}\right)\)
\\
\midrule
\begin{lstlisting}
Sum norm of a vector \(v = \vectorSumNorm{v}\)
\end{lstlisting} &
- Sum norm of a vector \(v = 7.2426406871193\)
+ Sum norm of a vector \(v = \vectorSumNorm{v}\)
\\
\midrule
\begin{lstlisting}
Euclidean norm of a vector
\(v = \vectorEuclidNorm{v}\)
\end{lstlisting} &
-Euclidean norm of a vector \(v = 4.7958315233127\)
+Euclidean norm of a vector
+ \(v = \vectorEuclidNorm{v}\)
\\
\midrule
\begin{lstlisting}
p norm of a vector \(v = \vectorpNorm{v}{3}\)
\end{lstlisting} &
-p norm of a vector \(v = 4.4031577258332\)
+p norm of a vector \(v = \vectorpNorm{v}{3}\)
\\
\midrule
\begin{lstlisting}
@@ -273,28 +295,30 @@ Sup norm of a vector \(v = 4.2426406871193\)
\vectorCreateRandom{v5}{3}{9}{90}
\(v5 =\left(\vectorPrint{v5}\right)\)
\end{lstlisting} &
-\(v5 =\left(18.290405, 23.356018, 49.966278\right)\)
+\vectorCreateRandom{v5}{3}{9}{90}
+\(v5 =\left(\vectorPrint{v5}\right)\)
\\
\midrule
\begin{lstlisting}
\vectorOp{v6}{v+w-2*v}
-\(v6 =\left(\vectorPrint{v7}\right)\)
+\(v6 =\left(\vectorPrint{v6}\right)\)
\end{lstlisting} &
-\(v6=\left(2.0, 4.0, 27.0 + 27.0i \right)\)
+\vectorOp{v6}{v+w-2*v}
+\(v6 =\left(\vectorPrint{v6}\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\).
+ angle between vector \(v\) and \(w\) is
+ \( \vectorGetAngle{v}{w}\).
\\
\midrule
\begin{lstlisting}
\vectorParse{y}
\end{lstlisting} &
-\(\left(1,2,3 \right)\)
+\vectorParse{y}
\\
\bottomrule \\
\caption{Illustration of commands for operations on vectors}
@@ -315,12 +339,14 @@ Gram Schmidt on \(v1,v2,v3\): \vectorGramSchmidt[brckt=round,truncate=3]{{'v1',
\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)$$
+\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{framed}
In addition to \verb|\mathRound|, the command \verb|complexRound| is also available. It has the following syntax.
@@ -329,12 +355,11 @@ In addition to \verb|\mathRound|, the command \verb|complexRound| is also availa
\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.
+ \verb| \complexRound{lcomplex(3.3333666, 6.777666)}{3}| outputs to \(\complexRound{lcomplex(3.3333666, 6.777666)}{3}\). 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,
@@ -363,15 +388,43 @@ The \verb|lualinalg| package can be used with other packages that have facility
\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
+\begin{figure}[H]
\centering
- \includegraphics[scale=0.9]{2dvec.jpg}
- \caption{Plotting of 3-D Vectors with lualinalg and tikz packages}
+ \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}
+ \caption{Plotting 2-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}
@@ -410,10 +463,38 @@ Listing \ref{code:luavecplot2} illustrates plotting of vectors in 3-D plane by u
\end{lstlisting}
Listing \ref{code:luavecplot2} produces figure \ref{fig:3dvecplot}.
-\begin{figure}[!ht] % or [H] to turn off float
+\begin{figure}[H]
\centering
- \includegraphics[scale=0.9]{3dvec.jpg}
- \caption{Plotting of Vectors with lualinalg and tikz packages}
+ \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}
+ \caption{Plotting 3-D Vectors with lualinalg and tikz packages}
\label{fig:3dvecplot}
\end{figure}
@@ -422,15 +503,15 @@ 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.
+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 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\n{{{1,2,3},{4,5,6},{7,8,lcomplex(9,3)}}}
\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{m}{{{1,2,3},{4,5,6},{7,8,lcomplex(9,3)}}}
\matrixNew{n}{{{1,2,3},{4,5,6},{7,8,10}}}
\end{lstlisting}
@@ -440,7 +521,8 @@ The identity matrix can be defined as well by using the \verb|\matrixNew| comm
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} \]
+\matrixNew{mtx}{3,'I'}
+I = \(\matrixPrint{mtx}\)
\subsection{Commands for operations on matrices}
Table \ref{tbl:luamtxcmd} lists all commands for operations on matrices in the \verb|lualinalg| package.
@@ -662,19 +744,35 @@ Defines new matrix obtained by performing Gauss-Jordan elimination on augmented
\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\r{{{1,2,3},{4,5,6},{7,8,lcomplex(9,3)}}}
\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}}}
+\def\z{{{lfrac(1,2),lcomplex(2,3),3},{4,5,6},{7,8,9}}}
\matrixNew{m}{\r}
\matrixNew{n}{\s}
\matrixNew{p}{\t}
\matrixNew{q}{\u}
+\matrixNew{r}{\z}
+
\end{lstlisting}
+
+\def\r{{{1,2,3},{4,5,6},{7,8,lcomplex(9,3)}}}
+\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}}}
+\def\z{{{lfrac(1,2),lcomplex(2,3),3},{4,5,6},{7,8,9}}}
+
+\matrixNew{m}{\r}
+\matrixNew{n}{\s}
+\matrixNew{p}{\t}
+\matrixNew{q}{\u}
+\matrixNew{r}{\z}
Table \ref{tbl:illluamatrix} illustrates various operations on matrices \(m,n,p,\) and \(q\).
\begin{center}
\begin{longtable}{lc}
@@ -684,36 +782,39 @@ Commands & Output Produced\\
\multicolumn{2}{c}{Printing matrices}\\
\midrule
\begin{lstlisting}
-\(m=\matrixPrint{\m}\)
+\(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}\)
+\(m=\matrixPrint{m}\)
\\
\midrule
\begin{lstlisting}
-\(m=\matrixPrint[type=pmatrix]{\m}\)
+\(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}\)
+\(m=\matrixPrint[type=pmatrix]{m}\)
\\
\midrule
\multicolumn{2}{c}{Some parameters of defined matrices}\\
\midrule
\begin{lstlisting}
-\(No. or rows in matrix m
+No. or rows in matrix \(m
= \matrixNumRows{m}\)
\end{lstlisting} &
-No. or rows in matrix \(m = 3\)\\
+No. or rows in matrix \(m
+= \matrixNumRows{m}\)\\
\midrule
\begin{lstlisting}
-\(No. or columns in matrix m
+No. or columns in matrix \(m
= \matrixNumCols{m}\)
\end{lstlisting} &
-No. or columns in matrix \(m = 3\)\\
+No. or columns in matrix \(m
+= \matrixNumCols{m}\)\\
\midrule
\begin{lstlisting}
-\(Element of matrix m at (3,3) =
+Element of matrix \(m\) at \((3,3) =
\matrixGetElement{m}{3}{3}\)
\end{lstlisting} &
-\(9+3i\)\\
+Element of matrix \(m\) at \((3,3) =
+ \matrixGetElement{m}{3}{3}\)\\
\midrule
\multicolumn{2}{c}{Algebraic operations on matrices}\\
\midrule
@@ -721,151 +822,152 @@ No. or columns in matrix \(m = 3\)\\
\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}
-\)\\
+\matrixAdd{m1}{m}{p}
+\matrixAdd{m1}{m}{p}
+\(m1 = \matrixPrint{m1}\)\\
\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}
-\)\\
+\matrixSub{m2}{m}{p}
+\(m2 = \matrixPrint{m2}\)\\
\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}
-\)\\
+\matrixMulNum{m3}{3}{m}
+\(m3 = \matrixPrint{m3}\)\\
\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}
-\)\\
+\matrixMul{m4}{m}{p}
+\(m4 = \matrixPrint{m4}\)\\
\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}
-\)\\
+\matrixPow{m5}{m}{2}
+\(m5 = \matrixPrint{m5}\)\\
\midrule
\begin{lstlisting}
\matrixInvert{m6}{m}
-\(m6 = \matrixPrint[truncate=4]{m6}\)
+\(m6 = \matrixPrint[truncate=2]{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}
-\)\\
+\matrixInvert{m6}{m}
+\(m6 = \matrixPrint[truncate=2]{m6}\)\\
\midrule
\begin{lstlisting}
Rank of matrix \(m =\matrixRank{m}\)
\end{lstlisting} &
-Rank of matrix \(m = 3\)\\
+Rank of matrix \(m =\matrixRank{m}\)\\
\midrule
\begin{lstlisting}
Determinant of matrix \(m =\matrixDet{m}\)
\end{lstlisting} &
-Determinant of matrix \(m = -9i\)\\
+Determinant of matrix \(m =\matrixDet{m}\)\\
\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}
-\)\\
+\matrixTranspose{m7}{m}
+\(m7 = \matrixPrint{m7}\)\\
\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}
-\)\\
+\matrixSetElement{n}{3}{3}{300}
+\(n= \matrixPrint{n}\)\\
\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}
-\)\\
+\matrixSubmatrix{m8}{m}{1}{2}{2}{3}
+\(m8 = \matrixPrint{m8}\)\\
\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}
-\)\\
+\matrixConcatH{m9}{m}{q}
+\(m9= \matrixPrint{m9}\)\\
\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}
-\)\\
+\matrixConcatV{m10}{m}{n}
+\(m10= \matrixPrint{m10}\)\\
\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}
-\)\\
+\matrixOp{m11}{m*m+2*m}
+\(\matrixPrint[truncate=4]{m11}\)\\
\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}
-\)\\
+\matrixCopy{m12}{m}
+\(m12 = \matrixPrint{m12}\)\\
\midrule
\begin{lstlisting}
trace of matrix \( m = \matrixTrace{m}\)
\end{lstlisting} &
-trace of matrix \( m = 15+3i\) \\
+trace of matrix \( m = \matrixTrace{m}\) \\
\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}
-\)\\
+\matrixConjugate{mc}{m}
+\(mc = \matrixPrint{mc}\)\\
\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}
-\)\\
+\matrixConjugateT{mct}{m}
+\(mct = \matrixPrint{mct}\)\\
\midrule
\begin{lstlisting}
\(\matrixNormOne{m}\)
\end{lstlisting} &
- \(18.486832980505\) \\
+ \(\matrixNormOne{m}\) \\
\midrule
\begin{lstlisting}
\(\matrixNormInfty{m}\)
\end{lstlisting} &
- \(24.486832980505\) \\
+ \(\matrixNormInfty{m}\) \\
\midrule
\begin{lstlisting}
\(\matrixNormMax{m}\)
\end{lstlisting} &
- \(9.4868329805051\) \\
+\(\matrixNormMax{m}\) \\
\midrule
\begin{lstlisting}
\(\matrixNormF{m}\)
\end{lstlisting} &
-\( 17.146428199482\) \\
+ \(\matrixNormF{m}\) \\
\midrule
\multicolumn{2}{c}{Elementary row operations on matrices}\\
@@ -874,22 +976,22 @@ trace of matrix \( m = 15+3i\) \\
\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}
-\)\\
+\matrixSwapRows{m13}{m}{2}{3}
+\(m13 = \matrixPrint{m13}\)\\
\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}
-\)\\
+\matrixMulRow{m14}{m}{3}{300}
+\(m14 = \matrixPrint{m14}\)\\
\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}
-\)\\
+\matrixMulAddRow{m15}{m}{2}{10}{3}
+\(m15 = \matrixPrint{m15}\)\\
\midrule
\multicolumn{2}{c}{Elementary column operations on matrices}\\
\midrule
@@ -897,23 +999,23 @@ trace of matrix \( m = 15+3i\) \\
\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}
-\)\\
+\matrixSwapCols{m16}{m}{2}{3}
+\(m16 = \matrixPrint{m16}\)\\
\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}
-\)\\
+\matrixMulCol{m17}{m}{3}{300}
+\(m17 = \matrixPrint{m17}\)\\
\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}
-\)\\
+\matrixMulAddCol{m18}{m}{2}{10}{3}
+\(m18 = \matrixPrint{m18}\)\\
\midrule
\multicolumn{2}{c}{Reduced row echelon form of a matrix}\\
@@ -922,27 +1024,27 @@ trace of matrix \( m = 15+3i\) \\
\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}
-\)\\
+\matrixRREF{m19}{p}
+\(m19 = \matrixPrint{m19}\)\\
\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}
-\)\\
+\matrixRREF{m20}{m}
+\(m20 = \matrixPrint{m20}\)\\
\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} $$
+The package has command \verb|\matrixRREFSteps| to produce step-by-step computation of reduced row echelon form of a matrix. The command \verb|\matrixRREFSteps{r}| outputs the following.
+\renewcommand*{\arraystretch}{1.5}
+\begin{framed}
+ \matrixRREFSteps{r}
\end{framed}
-
+\renewcommand*{\arraystretch}{1.0}
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}}}
@@ -953,27 +1055,28 @@ $$W = \matrixPrint{W}$$
\matrixGaussJordan{U}{S}{T}
$$U = \matrixPrint{U}$$
\end{lstlisting}
-
The above code produces the following output.
+\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}
\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}$$
+$$W = \matrixPrint{W}$$
+\matrixGaussJordan{U}{S}{T}
+$$U = \matrixPrint{U}$$
\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} $$
+\matrixGaussJordanSteps{S}{T}
\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}
+\begin{luacode*}
function sumcoordinates(v1)
local sum = 0
for i = 1,#v1 do
@@ -990,32 +1093,28 @@ s=vector.add(s,vector(p[i]))
end
return s
end
-\end{luacode}
-\vectorNew{v}{{1,2,complex('3+3i')}}
+\end{luacode*}
+\vectorNew{v}{{1,2,lcomplex(3,3)}}
The sum of coordinates of vector
- \(v = \directlua{tex.sprint(tostring( sumcoordinates(v)))}\).
+ \(v = \directlua{tex.sprint(tostring( sumcoordinates(vectors['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}
+\vectorNew{w}{{3,6,lcomplex(6,6)}}
+\vectorNew{x}{{9,12,lcomplex(12,12)}}
+\vectorAddmulti{y}{vectors['v'],vectors['w'],vectors['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 coordinates of vector \(v = 6 + 3\mathrm{i}\).
-The sum of vectors \(v,w \text{ and } x = \left(13.0, 20.0, 21.0 + 21.0i \right) \).
+The sum of vectors \(v,w \text{ and } x = \left(13, 20, 21 + 21\mathrm{i} \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}]
@@ -1031,7 +1130,7 @@ for i = 1,#m1 do
if i == j then sum = sum + (m1[i][j])^2 end
end
end
-return sum
+return complex.round(sum)
end
function matrix.addmulti(...)
@@ -1044,14 +1143,14 @@ end
end
\end{luacode}
-\def\r{{{1,2,3},{4,5,6},{7,8,complex('9+3i')}}}
+\def\r{{{1,2,3},{4,5,6},{7,8,lcomplex(9,3)}}}
\matrixNew{m}{\r}
The sum of squares of diagonal entries of matrix
- \(m = \directlua{tex.sprint(tostring(squareDiagEntries(m)))}\).
+ \(m = \directlua{tex.sprint(tostring(squareDiagEntries(matrices['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')}}}
+\def\s{{{1,2,3},{4,5,lcomplex(6,6)}}}
+\def\t{{{10,20,30},{40,50,lcomplex(60,60)}}}
+\def\u{{{100,200,300},{400,500,lcomplex(600,600)}}}
\matrixNew{m1}{\s}
\matrixNew{m2}{\t}
\matrixNew{m3}{\u}
@@ -1060,18 +1159,17 @@ The sum of squares of diagonal entries of matrix
matrices['#1'] = matrix.addmulti(#2)
}%
}
-\matrixAddmulti{m4}{m1,m2,m3}
+\matrixAddmulti{m4}{matrices['m1'],matrices['m2'],matrices['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 squares of diagonal entries of matrix \(m = 98 + 54\mathrm{i}\).
-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} \).
+The sum of matrices \(m1,m2 \text{ and } m3 =\begin{bmatrix} 111 & 222 & 333 \\ 444 & 555 & 666+666\mathrm{i} \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|.
diff --git a/macros/luatex/latex/lualinalg/lualinalg_complex.lua b/macros/luatex/latex/lualinalg/lualinalg_complex.lua
deleted file mode 100644
index 89f3fdf072..0000000000
--- a/macros/luatex/latex/lualinalg/lualinalg_complex.lua
+++ /dev/null
@@ -1,298 +0,0 @@
-
---Version=1.2, Date=14-Feb-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/complex.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/luamaths/README.txt b/macros/luatex/latex/luamaths/README.txt
index 02466225a8..926a94962c 100644
--- a/macros/luatex/latex/luamaths/README.txt
+++ b/macros/luatex/latex/luamaths/README.txt
@@ -1,10 +1,13 @@
+# The luamaths package
+# version 1.1
+# Authors: Chetan Shirore and Ajit Kumar
+# Email: mathsbeauty@gmail.com
+
# Introduction
The luamaths package is developed to perform standard mathematical operations inside LaTeX documents using Lua.
It provides an easy way to perform standard mathematical operations.
There is no particular environment in the package for performing mathematical operations.
-The package commands can be used in any environment (including the mathematics environment).
-
-
+
# License
The luamaths package is released under the LaTeX Project Public License v1.3c or later.
The complete license text is available at http://www.latex-project.org/lppl.txt.
diff --git a/macros/luatex/latex/luamaths/luamaths-complex.lua b/macros/luatex/latex/luamaths/luamaths-complex.lua
new file mode 100644
index 0000000000..68fd055b5e
--- /dev/null
+++ b/macros/luatex/latex/luamaths/luamaths-complex.lua
@@ -0,0 +1,347 @@
+--Version=1.3, Date=30-July-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/complex.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.
+
+frac= require("luamaths-fractions")
+complex = {}
+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
+
+ if getmetatable( num) == frac_mt then
+ return setmetatable( { num, 0 }, complex_meta )
+ 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( x,y)
+ return setmetatable( {x,y}, complex_meta )
+end
+
+lcomplex = complex.new
+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 )
+ imunit = "\\imUnit"
+ local real,imag = cx[1],cx[2]
+ if type(cx[1]) ~= "table" and type(cx[2]) ~= "table" then
+ if imag == 0 then
+ return real
+ elseif real == 0 then
+ return ((imag==1 and "") or (imag==-1 and "-") or imag)..imunit
+ elseif imag > 0 then
+ return real.."+"..(imag==1 and "" or imag)..imunit
+ end
+ return real..(imag==-1 and "-" or imag)..imunit
+ end
+
+ if type(cx[1]) == "table" and type(cx[2]) ~= "table" then
+ if cx[2] == 0 then
+ return frac.tostring(cx[1])
+ end
+ if cx[2] > 0 then
+ return frac.tostring(cx[1]).. "+"..(imag==1 and "" or imag)..imunit
+ end
+ if cx[2] < 0 then
+ return frac.tostring(cx[1])..(imag==-1 and "-" or imag)..imunit
+ end
+
+ end
+
+ if type(cx[1]) ~= "table" and type(cx[2]) == "table" then
+ if frac.toFnumber(cx[2])==0 then return cx[1] end
+ return cx[1].."+"..frac.tostring(cx[2])..imunit
+ end
+
+ if type(cx[1]) == "table" and type(cx[2]) == "table" then
+ if frac.toFnumber(cx[1]) == 0 and frac.toFnumber(cx[2]) ~= 0 then
+ return frac.tostring(cx[2])..imunit
+ end
+
+ if frac.toFnumber(cx[2]) == 0 then
+ return frac.tostring(cx[1] + 0)
+ end
+
+ if cx[2].d == 1 then
+ if cx[2].n > 0 then
+ return frac.tostring(cx[1]).. "+"..(cx[2].n==1 and "" or math.floor(cx[2].n))..imunit
+ end
+ if cx[2].n < 0 then
+ return frac.tostring(cx[1])..(cx[2].n==-1 and "-" or math.floor(cx[2].n))..imunit
+ end
+ end
+ end
+ return frac.tostring(cx[1]).. "+"..frac.tostring(cx[2])..imunit
+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]*cx2[1] + cx2[2]*cx2[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 h
+ local k
+
+ if type(cx[1]) ~= "table" then h = cx[1] end
+ if type(cx[2]) ~= "table" then k = cx[2] end
+
+ if type(cx[1]) == "table" then h = frac.toFnumber(cx[1]) end
+ if type(cx[2]) == "table" then k = frac.toFnumber(cx[2]) end
+ local len = math.sqrt( h^2 + k^2 )
+ local sign = ( h<0 and -1) or 1
+ return setmetatable( { math.sqrt((h +len)/2), sign*math.sqrt((len-h)/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 Xround(num, numDecimalPlaces)
+ if type(num)=="number" then
+ if num==math.floor(num) then
+ return math.floor(num)
+ end
+ end
+ if type(num)=="number" then
+ local mult = 10^(numDecimalPlaces or 0)
+ return math.floor(num * mult + 0.5) / mult
+ end
+ return num
+end
+
+function complex.round( cx,idp )
+ local mult =10^( idp or 0 )
+ if type(cx[1]) ~= "table" and type(cx[2]) ~= "table" then
+ return setmetatable( {Xround(cx[1],idp), Xround(cx[2],idp)}, complex_meta )
+ end
+ if type(cx[1]) ~= "table" and type(cx[2]) == "table" then
+ return setmetatable( {Xround(cx[1],idp), cx[2]}, complex_meta )
+ end
+ if type(cx[1]) == "table" and type(cx[2]) ~= "table" then
+ return setmetatable({cx[1],Xround(cx[2],idp)}, complex_meta )
+ end
+ if type(cx[1]) == "table" and type(cx[2]) == "table" then
+ return setmetatable({cx[1],cx[2]}, complex_meta )
+ end
+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/luamaths/luamaths-fractions.lua b/macros/luatex/latex/luamaths/luamaths-fractions.lua
new file mode 100644
index 0000000000..e4ab7a2329
--- /dev/null
+++ b/macros/luatex/latex/luamaths/luamaths-fractions.lua
@@ -0,0 +1,225 @@
+-- The luafractions module
+-- Authors: Chetan Shirore and Ajit Kumar
+-- version 1.0, Date=03-Aug-2023
+-- Licensed under LaTeX Project Public License v1.3c or later. The complete license text is available at http://www.latex-project.org/lppl.txt.
+
+M = {} -- the module
+frac_mt = {} -- the metatable
+function M.new (n, d, mode)
+ mode = mode or 'fracs'
+ if mode == 'nofracs' then
+ return (n/d)
+ end
+ if mode == 'fracs' then
+ if n~=math.floor(n) or d~=math.floor(d) then
+ error('Only integers are expected.')
+ end
+ if d == 0 then
+ error('Invalid fraction')
+ end
+ local fr = {}
+ local g = M.lgcd(n,d)
+ fr = {n=n/g, d=d/g}
+ return setmetatable(fr,frac_mt)
+ end
+end
+lfrac = M.new
+
+function M.lgcd (a, b)
+ local r
+ while (b ~= 0) do
+ r = a % b
+ a = b
+ b = r
+ end
+ return a
+end
+
+function M.simp (num)
+ local cf = gcd(num[1], num[2])
+ return M.new(num[1] / cf, num2[2] / cf)
+end
+
+function M.toFnumber(c)
+ return c.n / c.d
+end
+
+function M.toFrac(x)
+ if type(x) == "number" then
+ if x==math.floor(x) then
+ return M.new(math.floor(x),1)
+ else
+ return x
+ end
+ end
+ return x
+end
+
+
+function addFracs (c1, c2)
+ return M.new(c1.n * c2.d + c1.d * c2.n, c1.d*c2.d)
+end
+
+function subFracs (c1, c2)
+ return M.new(c1.n * c2.d - c1.d * c2.n, c1.d*c2.d)
+end
+
+function mulFracs (c1, c2)
+ return M.new(c1.n * c2.n, c1.d*c2.d)
+end
+
+function divFracs (c1, c2)
+ return M.new(c1.n * c2.d, c1.d*c2.n)
+end
+
+function minusFracs (c1)
+ return M.new(-c1.n,c1.d)
+end
+
+function powerFracs (c1,m)
+ return M.new((c1.n)^m,(c1.d)^m)
+end
+
+
+function M.add(a, b)
+ if type(a) == "number" then
+ if a==math.floor(a) then
+ return addFracs(M.new(a,1),b)
+ else
+ return a + M.toFnumber(b)
+ end
+ end
+
+ if type(b) == "number" then
+ if b==math.floor(b) then
+ return addFracs(a,M.new(b,1))
+ else
+ return M.toFnumber(a) + b
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( a ) == frac_mt and getmetatable( b ) == complex_meta then
+ return setmetatable( { a+b[1], b[2] }, complex_meta )
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( b ) == frac_mt and getmetatable( a ) == complex_meta then
+ return setmetatable( { b+a[1], a[2] }, complex_meta )
+ end
+ end
+ return addFracs(a, b)
+end
+
+
+function M.sub(a, b)
+ if type(a) == "number" then
+ if a==math.floor(a) then
+ return subFracs(M.new(a,1),b)
+ else
+ return a - M.toFnumber(b)
+ end
+ end
+
+ if type(b) == "number" then
+ if b==math.floor(b) then
+ return subFracs(a,M.new(b,1))
+ else
+ return M.toFnumber(a) - b
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( a ) == frac_mt and getmetatable( b ) == complex_meta then
+ return setmetatable( { a-b[1], b[2] }, complex_meta )
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( b ) == frac_mt and getmetatable( a ) == complex_meta then
+ return setmetatable( { a[1]-b, a[2] }, complex_meta )
+ end
+ end
+ return subFracs(a, b)
+end
+
+
+function M.mul(a, b)
+ if type(a) == "number" then
+ if a==math.floor(a) then
+ return mulFracs(M.new(a,1),b)
+ else
+ return a * M.toFnumber(b)
+ end
+ end
+
+ if type(b) == "number" then
+ if b==math.floor(b) then
+ return mulFracs(a,M.new(b,1))
+ else
+ return M.toFnumber(a) * b
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( a ) == frac_mt and getmetatable( b ) == complex_meta then
+ return setmetatable( { a*b[1], a*b[2] }, complex_meta )
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( b ) == frac_mt and getmetatable( a ) == complex_meta then
+ return setmetatable( { b*a[1], b*a[2] }, complex_meta )
+ end
+ end
+ return mulFracs(a, b)
+end
+
+
+function M.div(a, b)
+ if type(a) == "number" then
+ if a==math.floor(a) then
+ return divFracs(M.new(a,1),b)
+ else
+ return a / M.toFnumber(b)
+ end
+ end
+
+ if type(b) == "number" then
+ if b==math.floor(b) then
+ return divFracs(a,M.new(b,1))
+ else
+ return M.toFnumber(a) / b
+ end
+ end
+
+ if type( a ) == "table" and type(b) =="table" then
+ if getmetatable( a ) == frac_mt and getmetatable( b ) == complex_meta then
+ b= setmetatable( { M.toFrac(b[1]), M.toFrac(b[2]) }, complex_meta )
+ return a*(1/b)
+ end
+ end
+ return divFracs(a, b)
+end
+
+function M.tostring (c)
+ if c.d == 1 then
+ return string.format("%g",c.n)
+ end
+ if c.d == -1 then
+ return string.format("%g",-c.n)
+ end
+ return string.format("\\frac{%g}{%g}", c.n, c.d)
+end
+
+--Setting Metatable operations.
+frac_mt.__add = M.add
+frac_mt.__sub = M.sub
+frac_mt.__mul = M.mul
+frac_mt.__div = M.div
+frac_mt.__unm = minusFracs
+frac_mt.__pow = powerFracs
+frac_mt.__tostring = M.tostring
+
+return M \ No newline at end of file
diff --git a/macros/luatex/latex/luamaths/luamaths.pdf b/macros/luatex/latex/luamaths/luamaths.pdf
index a9ffe78a82..0b5d310b1d 100644
--- a/macros/luatex/latex/luamaths/luamaths.pdf
+++ b/macros/luatex/latex/luamaths/luamaths.pdf
Binary files differ
diff --git a/macros/luatex/latex/luamaths/luamaths.sty b/macros/luatex/latex/luamaths/luamaths.sty
index c3bc4d51e0..524b36a210 100644
--- a/macros/luatex/latex/luamaths/luamaths.sty
+++ b/macros/luatex/latex/luamaths/luamaths.sty
@@ -1,19 +1,25 @@
-% luaset package
-% version 1.0
-% Authors: Chetan Shirore and Ajit Kumar
+% The luamaths package
+% version 1.1
% Licensed under LaTeX Project Public License v1.3c or later. The complete license text is available at http://www.latex-project.org/lppl.txt.
+%Authors: Chetan Shirore and Ajit Kumar
-\ProvidesPackage{luaset}[1.0]
+\ProvidesPackage{luamaths}[1.1]
\RequirePackage{xkeyval}
\RequirePackage{amsmath}
\RequirePackage{luacode}
\begin{luacode*}
+local complex = require "luamaths-complex"
+local lfrac = require "luamaths-fractions"
+
function mathop(...)
inf = math.huge
return ...
end
function mathround(num, numDecimalPlaces)
+ if num==math.floor(num) then
+ return math.floor(num)
+ end
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
@@ -27,7 +33,7 @@ end
\newcommand\mathCos[1]{\directlua{tex.sprint(math.cos(#1))}}
\newcommand\mathExp[1]{\directlua{tex.sprint(math.exp(#1))}}
\newcommand\mathFloor[1]{\directlua{tex.sprint(math.floor(#1))}}
-\newcommand\mathHuge{\directlua{tex.sprint(math.huge)}}
+\newcommand\mathInf{\directlua{tex.sprint(math.huge)}}
\newcommand\mathLog[1]{\directlua{tex.sprint(math.log(#1))}}
\newcommand\mathMax[1]{\directlua{tex.sprint(math.max(#1))}}
\newcommand\mathMin[1]{\directlua{tex.sprint(math.min(#1))}}
@@ -38,4 +44,12 @@ end
\newcommand\mathTan[1]{\directlua{tex.sprint(math.tan(#1))}}
\newcommand\mathRad[1]{\directlua{tex.sprint(math.rad(#1))}}
\newcommand\mathRound[2]{\directlua{tex.sprint(mathround(#1,#2))}}
+\newcommand\complexRound[2]{%
+\directlua{%
+tex.sprint(complex.tostring(complex.round(#1,#2)))
+}%
+}%
+\newcommand{\imUnit}{\mathrm{i}}
+
+
\endinput
diff --git a/macros/luatex/latex/luamaths/luamaths.tex b/macros/luatex/latex/luamaths/luamaths.tex
index 0c5abbbe94..8e501abf14 100644
--- a/macros/luatex/latex/luamaths/luamaths.tex
+++ b/macros/luatex/latex/luamaths/luamaths.tex
@@ -1,11 +1,12 @@
\documentclass{article}
-\usepackage{listings,color,booktabs,longtable,array,hyperref,multicol}
-\usepackage[ left=1in, right=1in]{geometry}
+\renewcommand{\baselinestretch}{1.2}
+\usepackage{float,listings,color,booktabs,longtable,array,hyperref,luamaths,amsmath,amssymb}
+\usepackage[top=1.1in, bottom=1.1in, left=1.1in, right=1.1in]{geometry}
\hypersetup{colorlinks,urlcolor=blue}
\lstset{frame=none,
language=[LaTeX]{TeX},
aboveskip=3mm,
- belowskip=3mm,
+ belowskip=2mm,
showstringspaces=false,
columns=flexible,
basicstyle={\ttfamily},
@@ -16,11 +17,12 @@
breakatwhitespace=true,
tabsize=1
}
+\usepackage{microtype,graphicx,amsmath,amssymb,float}
\usepackage[backend=bibtex]{biblatex}
\addbibresource{luamaths}
\begin{document}
-\title{The luamaths Package in LaTeX}
-\author{Chetan Shirore and Dr. Ajit Kumar}
+\title{The luamaths package in LaTeX}
+\author{Chetan Shirore\thanks{Email id: mathsbeauty@gmail.com} \space and Ajit Kumar}
\maketitle
\section{Introduction}\label{section:introduction}
The \verb|luamaths| package is developed to perform standard mathematical operations inside LaTeX documents using Lua. It provides an easy way to perform standard mathematical operations. There is no particular environment in the package for performing mathematical operations. The package commands can be used in any environment (including the mathematics environment). It is written in Lua, and tex file is to be compiled with LuaLatex engine. The time required for operations is not an issue while compiling with LuaLaTeX. There is no need to install Lua on the users system as tex distributions (TeXLive or MikTeX) come bundled with LuaLaTeX. It is useful to perform standard operations (addition, subtraction, multiplication, division, powers, roots etc.) in tex file itself. The package supports the nesting of commands for multiple operations. It can be modified or extended by writing custom Lua programs.
@@ -28,6 +30,8 @@ The \verb|luamaths| package is developed to perform standard mathematical operat
The Lua \cite{online.luaorg} programming language is a scripting language that can be embedded across platforms. With\verb|LuaTeX| \cite{online.luatex} and\verb|luacode| \cite{online.luacode} packages, it is possible to use Lua in LaTeX. The TeX \cite{online.tex} or LaTeX has scope for programming \cite{online.texscript}. However, with the weird internals of TeX, there are several limitations, especially for performing calculations on numbers in LaTeX documents. There are packages like \emph{pgf} \cite{online.pgf} and \emph{xparse} \cite{online.xparse} in LaTeX which provides some programming capabilities inside LaTeX documents. However, such packages do not provide the complete programming structure that Lua programming languages provide. The \verb|luacode| \cite{online.luacode} package is used in its development apart from the \verb|luacode| package. There is no need to install Lua on users system as TeX distributions (TeXLive or MikTeX) come bundled with LuaLaTeX. The package can be modified or extended by writing custom Lua programs.
+
+
\section{Installation and License}
The installation of \verb|luamaths| package is similar to plain latex package, where the \texttt{.sty} file is in \LaTeX directory of texmf tree. The package can be included with \verb|\usepackage{luamaths}| command in the preamble of the LaTeX document. The TeX file is to be compiled using the LuaLaTeX engine.
@@ -179,13 +183,13 @@ Table \ref{tbl:opluamaths} lists operations in the \verb|luamaths| package.
\begin{lstlisting}
\mathTan{number}
\end{lstlisting} & Gives the tangent of a real number. Here the number is in radians.\\
-\bottomrule
+\bottomrule \\
\caption{Operations in the luamaths package}
\label{tbl:opluamaths}
\end{longtable}
\end{center}
Numbers can also be entered in scientific notation. For example, the number \(1860000\) can be entered as \(1.86e6\), and the number \(0.000186\) can be entered as \(1.86e-4\).
-\subsection{Illustrations of commands in the luamaths package}
+\subsection*{Illustrations of commands in the luamaths package}
Table \ref{tbl:illluamaths} illustrates operations in the \verb|luamaths| package with examples.
\begin{center}
\begin{longtable}{lc}
@@ -194,132 +198,204 @@ Table \ref{tbl:illluamaths} illustrates operations in the \verb|luamaths| packag
\toprule
\begin{lstlisting}
\mathOp{(3+3)^4-4}
-\end{lstlisting} & \(1292.0\)\\
+\end{lstlisting} & \(\mathOp{(3+3)^4-4}\)\\
\midrule
\begin{lstlisting}
\mathAbs{-6.96}
-\end{lstlisting} & \(6.96\)\\
+\end{lstlisting} & \(\mathAbs{-6.96}\)\\
\midrule
\begin{lstlisting}
\mathFloor{-6.9}
-\end{lstlisting} & \(-7\) \\
+\end{lstlisting} & \(\mathFloor{-6.9}\) \\
\midrule
\begin{lstlisting}
\mathFloor{9.9}
-\end{lstlisting} & \(9\)\\
+\end{lstlisting} & \(\mathFloor{9.9}\)\\
\midrule
\begin{lstlisting}
\mathCeil{-9.9}
-\end{lstlisting} & \(-9\) \\
+\end{lstlisting} & \(\mathCeil{-9.9}\) \\
\midrule
\begin{lstlisting}
\mathCeil{6.3}
-\end{lstlisting} &\(7\)\\
+\end{lstlisting} &\(\mathCeil{6.3}\)\\
\midrule
\begin{lstlisting}
\mathRound{9.678884}{3}
-\end{lstlisting} & \(9.679\)\\
+\end{lstlisting} & \(\mathRound{9.678884}{3}\)\\
\midrule
\begin{lstlisting}
\mathMax{20,30,100}
-\end{lstlisting} &\(100\) \\
+\end{lstlisting} &\(\mathMax{20,30,100}\) \\
\midrule
\begin{lstlisting}
\mathMin{20,30,100}
-\end{lstlisting} &\(20\)\\
+\end{lstlisting} &\(\mathMin{20,30,100}\)\\
\midrule
\begin{lstlisting}
\mathPi
-\end{lstlisting} & \(3.1415926535898\)\\
+\end{lstlisting} & \(\mathPi\)\\
\midrule
\begin{lstlisting}
\mathRound{\mathPi}{6}
-\end{lstlisting} & \(3.141593\)\\
+\end{lstlisting} & \(\mathRound{\mathPi}{6}\)\\
\midrule
\begin{lstlisting}
\mathInf
-\end{lstlisting} & \(Inf\)\\
+\end{lstlisting} & \(\mathInf\)\\
\midrule
\begin{lstlisting}
\mathOp{\mathInf/2}
-\end{lstlisting} &\(Inf\) \\
+\end{lstlisting} &\(\mathOp{\mathInf/2}\) \\
\midrule
\begin{lstlisting}
\mathSqrt{9}
-\end{lstlisting} & \(3.0\)\\
+\end{lstlisting} & \(\mathSqrt{9}\)\\
\midrule
\begin{lstlisting}
\mathLog{2}
-\end{lstlisting} & \(0.69314718055995\)\\
+\end{lstlisting} & \(\mathLog{2}\)\\
\midrule
\begin{lstlisting}
\mathExp{3}
-\end{lstlisting} & \(20.085536923188\) \\
+\end{lstlisting} & \(\mathExp{3}\) \\
\midrule
\begin{lstlisting}
\mathRad{1800}
-\end{lstlisting} & \(31.415926535898\)\\
+\end{lstlisting} & \(\mathRad{1800}\)\\
\midrule
\begin{lstlisting}
\mathSin{0}
-\end{lstlisting} &\(0.0\)\\
+\end{lstlisting} &\(\mathSin{0}\)\\
\midrule
\begin{lstlisting}
\mathCos{0}
-\end{lstlisting} & \(1.0\)\\
+\end{lstlisting} & \(\mathCos{0}\)\\
\midrule
\begin{lstlisting}
\mathTan{0}
-\end{lstlisting} & \(0.0\)\\
+\end{lstlisting} & \(\mathTan{0}\)\\
\midrule
\begin{lstlisting}
\mathAsin{0}
-\end{lstlisting} & \(0.0\)\\
+\end{lstlisting} & \(\mathAsin{0}\)\\
\midrule
\begin{lstlisting}
\mathAcos{0}
-\end{lstlisting} & \(1.5707963267949\)\\
+\end{lstlisting} & \(\mathAcos{0}\)\\
\midrule
\begin{lstlisting}
\mathAtan{0}
-\end{lstlisting} & \(0.0\)\\
+\end{lstlisting} & \(\mathAtan{0}\)\\
\midrule
\begin{lstlisting}
\mathRound{\mathOp{9+\mathSin{4}}}{6}
-\end{lstlisting} & \(8.243198\)\\
-\midrule
+\end{lstlisting} & \(\mathRound{\mathOp{9+\mathSin{4}}}{6}\)\\
+\bottomrule \\
\caption{Illustrations of commands in the luamaths package}
\label{tbl:illluamaths}
\end{longtable}
\end{center}
+The package supports fractions; numerators and denominators must be integers. A fraction can be specified with the Lua function: \verb|lfrac|. This function has the syntax \verb|lfrac(n,d,mode)|: \(n\) is an integer and \(d\) is a non-zero integer. The mode is optional. It can be \verb|fracs| or \verb|nofracs|. The default mode is \verb|fracs|. If fractions are input, the package will display vectors and matrices in fraction mode wherever possible. The package does not attempt to convert floats into fractions. If fractions are expected, then the input should contain fractions. If fractions are input and answers are expected in numbers, the mode can be specified as \verb|nofracs|.
+
+The Lua function \verb|lcomplex| defines the complex numbers. It has the syntax \verb|lcomplex(x,y)|, where \(x\) is a real part, and \(y\) is an imaginary part. \(x\) and \(y\) can also be fractions (numerators and denominators should be integers). The package has a command \verb|\imUnit| which provides typesetting for the imaginary unit. Its default value is \verb|\mathrm{i}|. It can be redefined. For example, one can redefine it as \verb|\renewcommand{\imUnit}{j}}|.
+
+Table \ref{tbl:illluamaths2} illustrates calculations on fractions and complex numbers using the \verb|luamaths| package. The numbers \(x, y, c\) and \(d\) are defined using the following commands.
+\begin{lstlisting}
+\def\x{lfrac(1,2)}
+\def\y{lfrac(-3,4)}
+\def\c{lcomplex(lfrac(3,4),6)}
+\def\d{lcomplex(3,-9)}
+\end{lstlisting}
+
+\subsection*{Some Illustrations}
+\def\x{lfrac(1,2)}
+\def\y{lfrac(-3,4)}
+\def\c{lcomplex(lfrac(3,4),6)}
+\def\d{lcomplex(3,-9)}
+\begin{center}
+\begin{longtable}{lc}
+\toprule
+\multicolumn{1}{c}{\textcolor{blue}{LaTeX input}} &\multicolumn{1}{c}{\textcolor{blue}{Output}} \\
+\toprule
+\begin{lstlisting}
+\(x + y = \mathOp{\x + \y}\)
+\end{lstlisting}
+& \(x + y = \mathOp{\x + \y}\) \\ \hline
+
+\begin{lstlisting}
+\(x - y = \mathOp{\x - \y}\)
+\end{lstlisting}
+& \(x - y = \mathOp{\x - \y}\) \\ \hline
+
+\begin{lstlisting}
+\(xy = \mathOp{\x*\y}\)
+\end{lstlisting}
+& \(xy = \mathOp{\x*\y}\) \\ \hline
+
+\begin{lstlisting}
+\(\frac{x}{y} = \mathOp{\x / \y}\)
+\end{lstlisting}
+& \(\frac{x}{y} = \mathOp{\x / \y}\) \\ \hline
+
+\begin{lstlisting}
+\(c + d = \mathOp{\c + \d}\)
+\end{lstlisting}
+& \(c + d = \mathOp{\c + \d}\) \\ \hline
+
+\begin{lstlisting}
+\(c - d = \mathOp{\c - \d}\)
+\end{lstlisting}
+& \(c - d = \mathOp{\c - \d}\) \\ \hline
+
+\begin{lstlisting}
+\(cd = \mathOp{\c*\d}\)
+\end{lstlisting}
+& \(cd = \mathOp{\c*\d}\) \\ \hline
+
+\begin{lstlisting}
+\(\frac{c}{d} = \mathOp{\c / \d}\)
+\end{lstlisting}
+& \(\frac{c}{d} = \mathOp{\c / \d}\) \\ \hline
+
+\begin{lstlisting}
+\(x + c - y + d = \mathOp{\x + \c - \y + \d}\)
+\end{lstlisting}
+& \(x + c - y + d = \mathOp{\x + \c - \y + \d}\) \\
+
+ \bottomrule \\
+\caption{Calculations on fractions and complex numbers}
+\label{tbl:illluamaths2}
+\end{longtable}
+\end{center}
\printbibliography
\end{document}